2019年3月14日 星期四

Week04-0460453

1.主題:移動

去下載必要三檔案  
網址:

http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

檔案:[data][win32] glut32.dll

解壓縮檔案到windows資料夾裡
打開Transformation檔案

畫一個茶壺

#include <stdio.h>
#include <GL/glut.h>
void display()
{
    glPushMatrix();
        glTranslatef(0.3,0.3,0); ///移動茶壺位置
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);
    
    glutMainLoop();
}

茶壺跟著滑鼠移動

#include <stdio.h>
#include <GL/glut.h>
float x=0,y=0;  ///滑鼠motion
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef((x-150)/150,-(y-150)/150.0,0); ///滑鼠motion
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int nowX,int nowY) ///滑鼠motion
{
    x=nowX; y=nowY;
    display();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);
    glutMotionFunc(motion); ///滑鼠motion

    glutMainLoop();
}



沒有留言:

張貼留言