1. 旋轉、移動
2. mouse 與旋轉
3. 世界旋轉/階層性旋轉
4. 階層性移動
課堂作業 1-1 (先做出來)
(B) rotate/translate/scale
課堂作業 1-2 (搞懂B)
橫著看程式碼
最底下的最靠近物體,從下面開始讀
(B)
translate rotate scale物體先縮放
再做旋轉 (自己是小旋轉盤 自己移動到邊邊)
再做移動 (自己旋轉 所以移動軸是自己)
課堂作業 1-3 (搞懂A)
(A)
rotate translate
scale
物體先縮放
再做移動(自己在大旋轉盤中 移到最邊邊)
再做旋轉 ( 大旋轉盤旋轉 所以移動軸是大旋轉盤的中心點 )
課堂作業 2-1
只有x沿著y軸動
x沿著y軸動 y沿著x軸動
#include <GL/glut.h>
float rotX=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT); //把上面的顏色丟入buffer
glPushMatrix(); //備份Matrix (Matrix裡面有translate, rotate, scale的量值)
glRotatef(rotX, 0,1,0); //X的移動量,讓他對Y軸轉
glRotatef(rotY, 1,0,0); //Y的移動量,讓他對X軸轉
glColor3f(0,1,0);
glutSolidTeapot(0.4);
glPopMatrix(); //還原Matrix (回到剛剛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_DOUBLE|GLUT_DEPTH); //double buffers是兩倍記憶體,一個顯示於螢幕,一個屬於內部的,當內部成是跑完後再做交換(swap),以致於畫面不會閃。
glutCreateWindow("hello3D");
glutInitWindowSize(400,400); ///調整式窗大小
glutInitWindowPosition(300,0); ///調整式窗位置
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}




沒有留言:
張貼留言