(1).主題 : 移動
(2).示範 : glTranslatef(x,y,z)
先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載3個並且解壓縮

把data和glut32.dll丟到windows裡面

開啟Transformation.exe

上課實作(一)
#include <GL/glut.h>void display()
{
glPushMatrix(); ////備份矩陣
glTranslatef( 0.3 , 0.3 , 0 ); ////移動會改變矩陣
glutSolidTeapot( 0.3 ); ////畫實心的茶壺
glPopMatrix(); ////還原矩陣. 才不會再下次有殘值
glutSwapBuffers(); ////最後buffer做交易秀出
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("06160150-W4");
glutDisplayFunc(display);
glutMainLoop();
}

上課實作(二)---圖片可用滑鼠拖曳
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 ); ///滑鼠motion
glutSolidTeapot( 0.3 ); ////畫實心的茶壺
glPopMatrix(); ////還原矩陣. 才不會再下次有殘值
glutSwapBuffers(); ////最後buffer做交易秀出
}
void motion(int nowX,int nowY) ///滑鼠motion
{ ///滑鼠motion
x=nowX; ///滑鼠motion
y=nowY; ///滑鼠motion
display();
} ///滑鼠motion
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("06160150-W4");
glutDisplayFunc(display);
glutMotionFunc(motion); ///滑鼠motion
glutMainLoop();
}

沒有留言:
張貼留言