http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載
1. data 2. window32 3. glut32dill
解壓縮檔
解壓縮window32到桌面
解壓縮data到window32裡
解壓縮data到window32裡
把glut32dill執行檔放到winow32裡面
然後執行Transformation
改變Rotate
車子會原地旋轉
即使改變Translate一樣是原地旋轉
swap後
先改變Translate
然後Rotate
就會繞著中心點旋轉
課堂作業 1-2 (公轉)
程式由下往上一層一層包
step1:車子縮水
glRotatef();
glTranslatef();
glScalef();
step2:把縮水的車子移到鍋子右邊
glRotatef();
glTranslatef();
glScalef();
step3:旋轉整個鍋子
glRotatef();
glTranslatef();
glScalef();
課堂作業 1-3 (自轉)
step1:車子壓扁
glTranslatef();
glRotatef();
glScalef();
step2:壓扁的車子選轉跳芭蕾
glTranslatef();
glRotatef();
glScalef();
step3:把車子移到右邊(依然在右邊原地跳芭蕾)
glTranslatef();
glRotatef();
glScalef();
課堂作業 2+3
*用滑鼠左右旋轉茶壺

#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix(); //備份Matrix
↑ glRotatef(rotY, 1,0,0); //Y的移動量,讓他對X軸轉
↑ glRotatef(rotX, 0,1,0); //X移動量,讓他對Y軸轉
↑ glColor3f(1,0,0);
↑ glutSolidTeapot(0.3);
glPopMatrix(); //還原Matrix
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);
glutCreateWindow("hello 3D");
glutInitWindowSize(300,300); //改變視窗大小
glutInitWindowPosition(200,0); //視窗左上角的初始位置
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
Q1:甚麼是glpushMatrix(); glpopMatrix();?
A1:glpushMatrix();是備份Matrix;glpopMatrix();是還原Matrix
Q2:甚麼是Buffers?Double?
A2:Double是兩倍記憶體




沒有留言:
張貼留言