#include <Gl/glut.h>
void arm()
{
glPushMatrix();
glScalef(1,0.3,0.3);
glutSolidCube(0.5);
glPopMatrix();
}
float angle=0;
float dx=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.2,0,0);
glRotatef(angle,0,0,1);
glTranslatef(0.25,0,0);
glColor3f(1,0,0); arm();
arm();
glPushMatrix();
glTranslatef(0.25,0,0);
glRotatef(angle,0,0,1); }///劃出手手,並讓手手移動
glTranslatef(0.25,0,0);
glColor3f(1,1,0); arm();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.2,0,0);
glRotatef(-angle,0,0,1);
glTranslatef(-0.25,0,0);
glColor3f(1,0,0); arm();
arm();
glPushMatrix();
glTranslatef(-0.25,0,0);
glRotatef(-angle,0,0,1);
glTranslatef(-0.25,0,0);
glColor3f(1,1,0); arm();
glPopMatrix();
glPopMatrix();
angle+=dx;
if(angle>60) dx=-1; }///控制手手移動角度
if(angle<=0) dx=+1;
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize(500,500);
glutInitWindowPosition(750,250);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week09");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}

沒有留言:
張貼留言