教材做swap交換
進入教材網址 jsyeh.org/3dcg10
下載檔案 data windows glut32
A) 以車子為中心點移動
縮放 gl Scalef - 旋轉 gl Rotatef - 移動 gl Translatef

B) 右鍵Swap translate/rotate
以鍋子為中心點來坐旋轉
縮放 gl Scalef - 移動 gl Translatef - 旋轉 gl Rotatef
作業2 Mouse轉動
#include <GL/Glut.h>
float rotX=0, rotY=0;void display()
{
glClearColor(0.5, 0.8, 0.8, 1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();///備份Matrix
glRotated(rotX,0,1,0);///對X軸移動
glRotated(rotY,0,1,0);///對Y軸移動
glColor3f(1, 1, 0.5);
glutSolidTeapot(0.3);
glPopMatrix();///還原Maxtrix,回到Push的位置
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x, rotY=y;
display();///glutPostRedisplay();
}
int main(int argc,char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH|GLUT_DEPTH);///double buffers兩倍記憶體
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
float rotX=0, rotY=0;
void display()
{
glClearColor(0.5, 0.8, 0.8, 1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotated(rotX, 1, 0, 0);///旋轉 角度rotY, 軸(1,0,0)X軸
glRotated(rotY, 0, 1, 0);///旋轉 角度rotX, 軸(1,0,0)X軸
glColor3f(1, 1, 0.5);
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_DEPTH|GLUT_DEPTH);
glutInitWindowSize(600,600);
glutInitWindowPosition(700,0);
glutCreateWindow("hello3D");
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
Q1: 什麼是Push Pop?
Push是放進,Pop是拿出
Push是放進,Pop是拿出
Q2: 什麼是 Matrix?
Matrix是矩陣






沒有留言:
張貼留言