2017年3月23日 星期四

Lars'的圖學 week05

歡迎到Lars~ 本篇標籤為 04160143_陳泓鈞(Lars)_ week05



HW一 主題範例
去老師的網站下載data.zip ,window.zip ,glut.dll,解壓縮後把資料放在一起點擊transform.exe開啟檔案。




HW二  做出會移動的茶壺


程式碼:

#include <GL/glut.h>

float mouseX,mouseY;

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    glTranslatef(mouseX,mouseY,0);
    glutSolidTeapot(0.3);

    glPopMatrix();
    glutSwapBuffers();
}

void motion(int x,int y)
{
    mouseX=(x-150)/150.0;
    mouseY=-(y-150)/150.0;
    glutPostRedisplay();
}

int main(int argc,char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("04160143");
    glutDisplayFunc(display);
    //glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}



HW三  將茶壺變形


程式碼:

#include <GL/glut.h>

float mouseX,mouseY;

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();

    glScalef(mouseX,mouseY,0);
    glutSolidTeapot(0.3);

    glPopMatrix();
    glutSwapBuffers();
}

void motion(int x,int y)
{
    mouseX=(x-150)/150.0;
    mouseY=-(y-150)/150.0;
    glutPostRedisplay();
}

int main(int argc,char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("04160143");
    glutDisplayFunc(display);
    //glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}



HW四  翻轉吧~茶壺



程式碼

#include <GL/glut.h>

float mouseX,mouseY,rotX=0;

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    glRotatef(rotX,0,0,1);
    glutSolidTeapot(0.3);

    glPopMatrix();
    glutSwapBuffers();
}

void motion(int x,int y)
{
    mouseX=(x-150)/150.0;
    mouseY=-(y-150)/150.0;
    rotX=x;
    glutPostRedisplay();
}

int main(int argc,char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("04160143");
    glutDisplayFunc(display);
    //glutMouseFunc(mouse);
    glutMotionFunc(motion);


    glutMainLoop();
}




沒有留言:

張貼留言