前往教材 jsyeh.org/3dcg10
下載 [source][data][win32][glut32.dll]
做Transformation練習
(A)移動 glTranslatef
旋轉 glRotatef
縮放 glScafef
glBegin();glEnd()
(一個縮小的車子,將一個旋轉中的車子移到右邊)
(B)旋轉 glRotatef
移動 glTranslatef
縮放 glScafef
glBegin();glEnd()
(一個縮小的車子,將一個移動的車子做旋轉)
課堂作業2
旋轉茶壺
加入紅色程式碼,可使茶壺左右旋轉移動。
#include <GL/glut.h>
float rotX=0;
void display()
{
glClearColor(0,0,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rotX,0,1,0);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
rotX = x;
display();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMotionFunc(motion);
//glutMouseFunc(mouse);
glutMainLoop();
}
課堂作業3
再加入藍色程式碼可使茶壺上下左右移動,並放大視窗
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(0,0,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rotX,0,1,0); ///旋轉 角度rotX, 軸(0,1,0) Y軸
glRotatef(rotY,1,0,0); ///旋轉 角度rotY, 軸(1,0,0) X軸
glColor3f(1,1,0);glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
rotX = x;rotY = y;
display();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutInitWindowSize(600,600);
glutInitWindowPosition(700,0);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutMotionFunc(motion);
//glutMouseFunc(mouse);
glutMainLoop();
}
沒有留言:
張貼留言