Step01:
1.下載datazip,windows.zip,解壓縮
2.點windows>transformation.exe
Step02:
1.寫入上禮拜茶壺程式
2.學習移動(translate)
寫入
glPushMatrix(); ///備分舊位置
///移動會累積,會改變矩陣
glTranslatef(0.5,0.5,0); ///右上角
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();///還原原位置
3.執行茶壺在右上角出現Step03:
1.新增MyTeapot()函式
2.把剛剛的translate移到MyTeapot()
3.MyTeapot()設參數MyTeapot(float x,float y)
4.改glTranslatef(0.5,0.5,0); --->glTranslatef(x,y,0);讓它讀取參數值
程式如下:
void MyTeapot(float x,float y){
glPushMatrix(); ///備分舊位置
///移動會累積,會改變矩陣
glTranslatef(x,y,0);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();///還原原位置
}
5.修改display(),導入MyTeapot()
void Display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
MyTeapot(0.5,0.5); ///右上角
MyTeapot(-0.5,0.5); ///左上角
MyTeapot(-0.5,-0.5); ///左下角
MyTeapot(0.5,-0.5); ///右下角
glutSwapBuffers();
}
Step04:
1.開新檔,沿用上一步程式
2.設值float mouseX=0,mouseY=0;
3.建立mouse()函式
void mouse(int button,int state,int x,int y)
4.寫入mouseX=x;mouseY=y;
void mouse(int button,int state,int x,int y){
mouseX=x;mouseY=y;
}
5.在Display()加入
沒有留言:
張貼留言