2019年3月14日 星期四

week04_showshowshow的筆記

1.主題:移動
2.示範:glTranslatef(x,y,z);

(1)下載windows資料夾  - 開啟Transformation.exe
在Screen-space view滑鼠按右鍵可更換模型




















(2)開啟CodeBlocks - 開啟新project - 撰寫一個茶壺模型


利用glTranslatef移動模型

(3)利用函式撰寫出可用滑鼠移動模型

#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.0,-(y-150)/150.0,0);///移動
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣 才不會有殘影
    glutSwapBuffers();
}
void motion(int nowX,int nowY)
{
    x=nowX; y=nowY;
    display();///滑鼠motion馬上更新
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);
    glutMotionFunc(motion);///滑鼠motion
    glutMainLoop();
}




沒有留言:

張貼留言