float angleX =0,angleA=0;
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') angleA+=5;
if(key=='2') angleA-=5;
glutPostRedisplay();//請電腦重新畫一次畫面
}
void myLight()
{
const GLfloat light_position[] = { 2.0f, 5.0f, -1.0f, 0.0f };
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();//頭
//glRotatef(angleX, 0,1,0);
glColor3f(0.5,1,2);
glTranslatef(0, 0.2, 0);
glutSolidSphere(0.25, 20, 20);
glPopMatrix();
glPushMatrix();//身體
//glRotatef(angleX, 0,1,0);
glutSolidTeapot(0.29);
glutWireTeapot(0.3);
glPopMatrix();
glPushMatrix();// 右大腿
glRotatef(angleA, 1,0,0);
glTranslatef(-0.1, -0.4, 0);
glScalef(1, 3, 1);
glutSolidCube(0.15);
glPopMatrix();
glPushMatrix();//右小腿
glRotatef(angleA, 1,0,0);
glTranslatef(-0.1, -0.6, 0);
glScalef(1.2, 2, 1.4);
glutSolidCube(0.15);
glPopMatrix();
glPushMatrix();// 左大腿
glRotatef(angleA, -1,0,0);
glTranslatef(0.1, -0.4, 0);
glScalef(1, 3, 1);
glutSolidCube(0.15);
glPopMatrix();
glPushMatrix();//左小腿
glRotatef(angleA, -1,0,0);
glTranslatef(0.1, -0.6, 0);
glScalef(1.2, 2, 1.4);
glutSolidCube(0.15);
glPopMatrix();
glPushMatrix();//左肩
//glRotatef(angleX, 0,1,0);
glColor3f(1, 1, 1);
glTranslatef(-0.4, 0, 0);
glutSolidSphere(0.15, 20, 20);
glPushMatrix();//左手臂
glRotatef(angleA, 0, 1, 1);
glColor3f(0.5,1,2);
glScalef(1, 2, 1);
glTranslatef(0.02, -0.1, 0);
glutSolidCube(0.15);
glPopMatrix();
glPopMatrix();
glPushMatrix();//右肩
//glRotatef(angleX, 0, 1, 0);
glColor3f(1, 1, 1);
glTranslatef(0.4, 0, 0);
glutSolidSphere(0.15, 20, 20);
glPushMatrix();//右手臂
glRotatef(angleA, 0, 1, 1);
glColor3f(0.5,1,2);
glScalef(1, 2, 1);
glTranslatef(0.02, -0.1, 0);
glutSolidCube(0.15);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
myLight();
glutMainLoop();
}
水藍色真的很美。
沒有留言:
張貼留言