看Transformation.exe. 改順序
01.交換 glTranslatef(...) glRotatef(...)
<=>
swap
glRotatef(...) glTranslatef(...)
在右邊自轉 右邊車子繞畫面中心
口訣:左耳貼左肩,從下往上讀
02.(方法2:用別人的程式)
把圖形自轉變成公轉
03.(方法3:自己的程式)
#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion(int x,int y)///mouse motion拖著移動時,呼叫motion()
{
angle=x;///用上週比較差的方式,直接把mouse座標,變成轉動角度
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);///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();
}

04(方法4:用紙來想).





沒有留言:
張貼留言