| Week 04 |
§旋轉 Rotate§
●01
試試看 glRotatef(角度,x,y,z)
旋轉x,y,z軸
●02
理解旋轉座標(x,y,z)
右手安培定律(?)
●03(根據上面畫的圖)
移動x軸(左右轉) 如圖所示
glRotatef(x, 0,1,0);
●04(根據上面畫的圖)
移動y軸(上下轉) 如圖所示
glRotatef(y, 1,0,0);
◎程式碼
#include <GL/glut.h>
float x=0,y=0; ///現在的重點是滑鼠
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///[新的]清畫面
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glPushMatrix();
glRotatef(y, 1,0,0); ///更改x,y,z軸
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int nowx,int nowy)
{
x=nowx;y=nowy;
display();
}
int main(int argc,char ** argv)
{
glutInit( &argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week04");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}



沒有留言:
張貼留言