複習上週:Transformation.exe
任務一:Transformation.exe 複習移動、旋轉 (一樣去老師的網站載需要的東西)
1.開啟Transformation.exe
試試看旋轉方式一種是自己原地轉,另一種是沿著中心點公轉
任務二:TRT改中心點旋轉
1.把茶壺的中心改到把手的位置
#include <GL/glut.h>
float angle=0; ///旋轉的角度
void motion(int x,int y) /// mouse motion 拖著移動時,會叫motion()
{
angle=x;
glutPostRedisplay();
}
void 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); ///把茶壺的柄放到畫面中心
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05_TRT_05160806");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
#include <GL/glut.h>
float angle=0;
void motion(int x,int y)
{
angle=x;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3); ///放在中間
glTranslatef(0.5,0.15,0); ///把會旋轉的茶壺柄,放到右上角
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);///另一個茶壺
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05_TRT_05160806");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}



沒有留言:
張貼留言