2018年3月30日 星期五

Week05_林楷

(1) 複習: T.R.S

(2)主題: T.R.T轉動

(3)主題: 階層轉動

(4)矩陣

(5)回家作業

跟上周一樣,先到 jsyeh.org/3dcg10 網址裡面下載 1.windows.zip 2.data.zip 3.glut32.dll 三個檔案
並把data與glut32放到windows檔案裡再開啟Transformation.exe檔,觀察程式有沒有執行swap(按右鍵)的差別,可以發現根據移動(Translate)和轉動(Rotate)的順序不一樣,車子轉動的方式也會改變,分別為自轉與公轉(如圖)














再來打開codeblock程式,與前幾周一樣,下載freeglut並import到裡面,接著觀察裏面的式,發現display函式的其中一段
並註解不同的程式以及把glTranslate()與glRotated()順序翻轉,觀察球體的變化,發現會繞著螢幕中心做轉動
再運用上周的茶壺程式先做轉動
#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();
}

然後再display()函式裡加一段程式
glTranslatef(0.45 , -0.10 , 0 ) ;
把茶壺柄移動到中心點,以方便能以柄為中心進行轉。

沒有留言:

張貼留言