配合上週並延伸學習
(1)到http://jsyeh.org/3dcg10網址下載[data] [win32] glut32.dll 三個檔案
(2)解壓縮[win32] 並把 glut32.dll 檔和 [data]檔複製到window資料夾貼上
(3)點擊Transformation.exe 即可執行
(4)在Transformation.exe中點擊右鍵點選Swap translate/rotate 即可轉換自轉跟公轉的差別
程式碼由下往上優先執行(類似數學結合率)如下示意圖
--------------------------------------------------------------------------------------------------------------------------
一樣配合上訴概念套用於程式碼中並配合上週進度(公轉)
(1)利用程式碼進行這週的初步理解
(2)利用茶壺程式碼理解這週的TRT概念(自轉公轉)
程式碼如下:
#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glRotatef(angle, 0,0,1);///Now:轉動
glTranslatef(0.45,-0.10,0);
glutSolidTeapot(0.3);
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glRotatef(angle, 0,0,1);///Now:轉動
glutSolidTeapot(0.3);
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);///Now:
glutMainLoop();
}
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);///Now:
glutMainLoop();
}






沒有留言:
張貼留言