🌲電腦圖學🌲
2018-03-26 Week05
(1) 複習移動、旋轉(translation)
(2)T-R-T特地轉軸
(3)階層性旋轉
(4)矩陣(整合)
(5回家作業
TODO: 看Transformation.exe
超連結:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載Win32.zip / data.zip / glut32.dll 三個檔案 (詳見圖一)

float angle=0; ///旋轉的角度
void motion(int x,int y) /// mouse motion 拖著移動時,會叫motion()
{
angle=x; ///老師用上周比較差的方法,直接把mouse座標,變轉動角度
glutPostRedisplay(); ///請畫面重置
}
void display() ///畫面要display時呼叫這個函式
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //清洗畫面
glPushMatrix(); ///備份矩陣(乾淨的矩陣)
glRotatef(angle,0,0,1); ///rotate/translate ///scale都會把矩陣改變
glTranslatef(0.45,-0.08,0); ///移動,讓茶壺的柄,放到畫面中心
glutSolidTeapot(0.3); ///TODO: 請試著把茶壺的柄放到畫面中心
glPopMatrix(); ///還原矩陣(乾淨的矩陣)
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05_TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
(2)T-R-T特地轉軸
(3)階層性旋轉
(4)矩陣(整合)
(5回家作業
範例練習
TODO: 看Transformation.exe
超連結:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載Win32.zip / data.zip / glut32.dll 三個檔案 (詳見圖一)

(圖一)
→開啟Transformation.exe. 試著看看反轉時的旋轉方式跟原來的旋轉方式,去做比較
經過比較後發現一個旋轉方式是自己原地轉,另一種方式是沿著中心點公轉。(詳見圖二)
(圖二)出處:老師用圖
glBegin(){ /// 有一台車子
}
glScalef(){ ///有一台縮放的車子
}
glRotatef(){ ///旋轉有一台縮放的車子
}
}
glScalef(){ ///有一台縮放的車子
}
glRotatef(){ ///旋轉有一台縮放的車子
}
(詳見圖三、圖四)
(圖三)出處:老師用圖
(圖四)出處:老師用圖
開始動手撰寫程式
T-R-T特定軸轉
目的:撰寫程式-讓茶壺會轉動就像在握茶壺的手把一樣(詳見圖五)
TODO:把茶壺中心點設在把手
#include <GL/glut.h>float angle=0; ///旋轉的角度
void motion(int x,int y) /// mouse motion 拖著移動時,會叫motion()
{
angle=x; ///老師用上周比較差的方法,直接把mouse座標,變轉動角度
glutPostRedisplay(); ///請畫面重置
}
void display() ///畫面要display時呼叫這個函式
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //清洗畫面
glPushMatrix(); ///備份矩陣(乾淨的矩陣)
glRotatef(angle,0,0,1); ///rotate/translate ///scale都會把矩陣改變
glTranslatef(0.45,-0.08,0); ///移動,讓茶壺的柄,放到畫面中心
glutSolidTeapot(0.3); ///TODO: 請試著把茶壺的柄放到畫面中心
glPopMatrix(); ///還原矩陣(乾淨的矩陣)
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05_TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
(圖六)



沒有留言:
張貼留言