Week12天氣晴
1. 至jsyeh.org/3dcg10 下載 data.zip , windows.zip
2.打開 window/Transformation.exe
glTranslatef( 0.9 , 0 , 0 );
glRotatef( angle , 0 , 1 , 0 );
(往右轉的藍色車子)
glRotatef( angle , 0 , 1 , 0 );
glTranslatef( 0.9 , 0 , 0 );
(繞著中間轉彎)
3.對特定軸轉動練習
(1) 120.125.80.50/GL
(2) ctrl-R清空
(3)畫身體 myDrawObject(0)
畫手臂 myDrawObject(1)
(4)可更改程式碼順序
(5)按 angle= 再按空白建 會自動變成動畫\
4.用茶壺來旋轉
程式碼:
#include <GL/glut.h>float angle=0;void display(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1,1,1); glutSolidTeapot(0.3);///白色茶壺當身體 glPushMatrix(); ///右邊的手臂、手肘 glTranslatef(0.2, 0, 0);///(3)掛到右邊 (把整個往右移動) glRotatef( angle, 0, 0, 1);///(2)旋轉 glTranslatef(0.2, 0, 0); ///(1)把旋轉中心,放到世界中心 glColor3f(1,0,0);///紅色的 glutSolidTeapot( 0.2 );///小茶壼 想像它是手臂 glPushMatrix(); glTranslatef(0.2, 0, 0);///(3)掛到右邊 (把整個往右移動) glRotatef( angle, 0, 0, 1);///(2)旋轉 glTranslatef(0.2, 0, 0); ///(1)把旋轉中心,放到世界中心 glColor3f(1,0,0);///紅色的 glutSolidTeapot( 0.2 );///小茶壼 想像它是手肘 glPopMatrix(); glPopMatrix();
glPushMatrix(); ///左邊的手臂、手肘 glTranslatef(-0.2, 0, 0);///(3)掛到左邊 (把整個往左移動) glRotatef( -angle, 0, 0, 1);///(2)旋轉 glTranslatef(-0.2, 0, 0); ///(1)把旋轉中心,放到世界中心 glColor3f(1,0,0);///紅色的 glutSolidTeapot( 0.2 );///小茶壼 想像它是手臂 glPushMatrix(); glTranslatef(-0.2, 0, 0);///(3)掛到左邊 (把整個往左移動) glRotatef( -angle, 0, 0, 1);///(2)旋轉 glTranslatef(-0.2, 0, 0); ///(1)把旋轉中心,放到世界中心 glColor3f(1,0,0);///紅色的 glutSolidTeapot( 0.2 );///小茶壼 想像它是手肘 glPopMatrix(); glPopMatrix();
glutSwapBuffers(); angle+=0.1;}int main(int argc, char**argv){ glutInit( &argc, argv ); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("week12-TRT");
glutIdleFunc(display); glutDisplayFunc(display);
glutMainLoop();} #include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glutSolidTeapot(0.3);///白色茶壺當身體
glPushMatrix();
glTranslatef(0.2,0,0);///掛到右邊,把整個往右移動
glRotatef(angle,0,0,1);
glTranslatef(0.2,0,0);///把手臂的旋轉中心移至中心
glColor3f(1,0,0);
glutSolidTeapot(0.2);///紅色茶壺當手臂
glPopMatrix();
glutSwapBuffers();
angle+=0.1;
}
int main(int argc, char**argv)
{
glutInit( &argc, argv );
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12-TRT");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言