1.下載 windows.zip、data.zip、glut32.dll
by http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
開啟範例Transformation.exe
比較 swap translate/rotate
(A){
Translate
Rotate
Scale
}
(A)以外部看其自轉的視角
(B){
Rotate
Translate
Scale
}
(B)以內部看其物體週轉的視角
2.單旋轉茶壺
#include <GL/glut.h>float rotX=0;
void display()
{
glClearColor(1,1,1,1);//背景顏色
glClear(GL_COLOR_BUFFER_BIT);//背景漆上顏色
glPushMatrix();//備份位置
glRotatef(rotX,0,1,0);//將滑鼠移動的x轉換為rotate-x
glColor3f(1,0,0);//紅色
glutSolidTeapot(0.3);//茶壺
glPopMatrix();//取出位置使用
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;//將滑鼠移動的x轉換為rotate-x
display();
}
int main(int argc,char**argv)
{
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("03161042");
glutDisplayFunc(display);
glutMotionFunc(motion);//motion函式
glutMainLoop();
}
Q1:
(1)什麼是 glPushMatrix();?
A:備份量值位置(Matrix-translate、rotate、scale的量值)
(2)什麼是 glPopMatrix();?
A:取出剛剛備份位置的量值使用
Q2:
(1)什麼是Buffers?
A:記憶體
(2)什麼是Double?
A:雙倍
3.雙旋轉茶壺
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(1,1,1,1);//背景顏色
glClear(GL_COLOR_BUFFER_BIT);//背景漆上顏色
glPushMatrix();//備份位置
glRotatef(rotY,1,0,0);//將滑鼠Y的移動量對x軸旋轉
glRotatef(rotX,0,1,0);//將滑鼠X的移動量對y軸旋轉
glColor3f(1,0,0);//紅色
glutSolidTeapot(0.3);//茶壺
glPopMatrix();//取出位置使用
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;//將滑鼠x的移動量轉換為rotate-x
rotY=y;//將滑鼠y的移動量轉換為rotate-y
display();
}
int main(int argc,char**argv)
{
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("03161042");
glutDisplayFunc(display);
glutMotionFunc(motion);//motion函式
glutMainLoop();
}




沒有留言:
張貼留言