2019年4月25日 星期四

幽羊山之土-Week10_旋轉

1.複習

到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 
       --> 下載: windows.zip, data.zip, glut32.dll (week03

程式碼順序,會影響旋轉方式
轉動"移動到右方的車子"

T-R-T 旋轉
移動-轉動-移動






-

2.主題:T-R-T 旋轉

開啟GLUT程式 (week01
 進入transmission zero 網站,下載 freeglut 3.0.0 MinGW Package 
 在 CodeBlocks 開啟GLUTproject
T-R-T 旋轉程式:
#include <GL/glut.h> float angle; void display(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0,0.5,0); //移動位置 glutSolidTeapot(0.3); //茶壺 glPopMatrix(); glPushMatrix(); glTranslatef(0.5,0.625,0);//移動位置 glRotatef(angle,0,0,1); //轉動 glTranslatef(0.6,0,0); //改旋轉中心 glRotatef(-90,0,1,0); //轉90度 glutSolidCone(0.2,0.6,30,30);//直的Cone glPopMatrix(); glutSwapBuffers(); } void motion(int x,int y){ angle=x; display(); } int main(int argc,char**argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH); glutCreateWindow("Week10 T-R-T"); glutDisplayFunc(display); glutMotionFunc(motion); glutMainLoop(); }


沒有留言:

張貼留言