打開Transformation.exe
下半視窗右鍵將glTranslatef、glRotatef反轉觀察與原本的變化
1.縮小或壓扁(glScalef)後->移(glTranslatef)到右邊->旋轉(glRotatef)
像在跳芭雷舞,車子自己中間插一根牙籤轉動牙籤以軸心旋轉
切換後
2.縮小或壓扁(glScalef)後->移(glTranslatef)到右邊->旋轉(glRotatef)
像把菜放在旋轉圓桌邊邊轉動桌子
車子像在繞圓環圈圈
作業2-mouse 與旋轉
在Code::Blocks新增GLUT 專案
建立GLUTproject
1.File/New/Project
3. freeglut資料夾解壓縮到桌面,複製freeglut所在位置
4.Please selest GLUT's loctoin: 貼上位置
要用滑鼠旋轉茶壺
老師的示範程式碼如圖
程式碼如下:
#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);
glColor3f(1,0,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("hello3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
回答問題:
1、什麼是glPushMatrix(); glPopMatrix();
2、什麼是Buffers??
作業3-X跟Y旋轉
老師的示範程式碼如圖
程式碼
----------------------------
#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);
glRotatef(rotX, 0,1,0);
glColor3f(1,0,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(300,300);
glutInitWindowPosition(600,0);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
-----------------------------
rotY多設定Y,能上下轉
glutInitWindowSize();設定視窗大小
glutInitWindowPosition(600,0); 設定視窗出現位置
作業外
讓CB視窗更好寫程式
設定讓是工具列等不顯示
View/Perspectives/Code::Blocks minimal
會變這樣
隨時可以View/Perspectives/Code::Blocks default
回家作業
用之前作業的自己畫的圖套上旋轉
push
縮行
pop





















沒有留言:
張貼留言