(可以參考Week03)
2.解壓縮膽案,並把glut32.dll和data資料夾貼到windows資料夾裡面
3.選擇transformation.exe
Q:觀察移動和旋轉先後順序不同時,會產生什麼情形?
♪由下往上看!!
公轉:
先移動(Transform)再旋轉(Rotate)
(2)再旋轉
繞著移動前(最開始)的中心線旋轉=>公轉
自轉:
先旋轉(Rotate)再移動(Transform)
繞著本身的中心線旋轉=>自轉
♪因為後移動,所以不影響中心線
點擊右鍵可以更改Translatef 和 Rotatef 的順序
𝄞茶壺自轉𝄞
程式碼:
#include <GL/glut.h>
float angle=0;///讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///備份矩陣
glRotatef(angle, 0,0,1); ///轉動
glutSolidTeapot(0.3);
glPopMatrix(); ///還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x; ///改變角度
glutPostRedisplay(); ///重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
float angle=0;///讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///備份矩陣
glRotatef(angle, 0,0,1); ///轉動
glutSolidTeapot(0.3);
glPopMatrix(); ///還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x; ///改變角度
glutPostRedisplay(); ///重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
glutMotionFunc(motion);
glutMainLoop();
}
𝄞茶壺公轉𝄞
程式碼:
#include <GL/glut.h>
float angle=0;///讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣
glRotatef(angle, 0,0,1);///轉動
glTranslatef(0.45,-0.10,0);
glutSolidTeapot(0.3);
glPopMatrix(); ///還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x; ///改變角度
glutPostRedisplay(); ///重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
𝄞茶壺手臂𝄞
#include <GL/glut.h>
float angle=0;///讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣
glColor3f(1,0,0); glutSolidTeapot(0.3); ///中間的紅色茶壺
glPushMatrix(); ///右手臂
glTranslatef(0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1); ///轉動樓下全部
glTranslatef(0.45,-0.1,0); ///把茶壺柄移到中間
glColor3f(0,1,0); glutSolidTeapot(0.3);
glPushMatrix(); ///右手肘
glTranslatef(0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1); ///轉動樓下全部
glTranslatef(0.45,-0.1,0); ///把茶壺柄移到中間
glColor3f(0,1,0); glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix(); ///左手臂
glTranslatef(-0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1); ///轉動樓下全部
glTranslatef(-0.45,-0.1,0); ///把茶壺柄移到中間
glColor3f(0,1,0); glutSolidTeapot(0.3);
glPushMatrix(); ///左手肘
glTranslatef(-0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1); ///轉動樓下全部
glTranslatef(-0.45,-0.1,0); ///把茶壺柄移到中間
glColor3f(0,1,0); glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPopMatrix();///還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///改變角度
glutPostRedisplay();///重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}










沒有留言:
張貼留言