step01:
選轉方向依照右手定則
0,1,0選轉方向
1,0,0選轉方向
旋轉茶壺程式碼:
#include <GL/glut.h>
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣
glRotated(90,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week04_Rotate");
glutDisplayFunc(display);
glutMainLoop();
}
用滑鼠調整茶壺角度
程式碼:
#include <GL/glut.h>
float angle = 0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣
glRotated(angle,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle = x;
display();///重畫畫面
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week04_Rotate");
glutDisplayFunc(display);
glutMotionFunc(motion);///mouse motion動
glutMainLoop();
}
沒有留言:
張貼留言