加上float angle=0
glPushMatrix()
glRotatef(angle,0,0,1)
glPopMatrix()
void motion(int x,int y)
glutMotionFunc(motion)
void display()
{
glClearColor(1.0,0.0,0.9,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
void mouse(int button, int state, int x, int y)
{
oldX=x;
}
void motion(int x,int y)
{
angle+=(x-oldX);
oldX=x;
display();
}
void keyboard(unsigned char key,int x,int y)
{
printf("key: %c x: %d y: %d\n",key,x,y);
}
int main(int argc, char*argv[])
{
glutKeyboardFunc(keyboard)
glutMouseFunc(mouse)
glutMotionFunc(motion)
}
自己旋轉
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glPushMatrix()
glRotatef(angle++,0,0,1)
glutSolidTeapot(0.3)
glPopMatrix()
glutSwapBuffers()
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glClearColor(1.0,1.0,0.9,1.0);
glTranslatef(0.8,0,0);
glRotatef(angle++,0,0,1);
glScalef(0.3,0.3,0.3);
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
旋轉360
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle++,0,0,1);
glTranslatef(0.8,0,0);
glScalef(0.3,0.3,0.3);
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
交換紅色部分
沒有留言:
張貼留言