顯示具有 01160456_謝之麟 標籤的文章。 顯示所有文章
顯示具有 01160456_謝之麟 標籤的文章。 顯示所有文章

2014年5月29日 星期四

01160456_謝之麟, HW014, Week14




#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <stdio.h>
//IplImage *img1, *img2, *img3, *img4;
//GLuint id1, id2, id3, id4;
IplImage * img[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
GLuint id[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
float angle1=0, angle2=0, angle3=0, angle4=0, angle5=0, angle6=0, angle7=0, angle8=0;
void myPrepareTexture(int i)//用參數來配, 找對應正確的變數
{//技巧3: 可以把重覆的東西, 用函式來簡化
cvCvtColor(img[i], img[i], CV_BGR2RGB);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &id[i]);
glBindTexture(GL_TEXTURE_2D, id[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img[i]->width, img[i]->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img[i]->imageData);
}
void myTexture()
{
img[0]=cvLoadImage("orange.png");
img[1]=cvLoadImage("yellow.png");
img[2]=cvLoadImage("blue.png");
for(int i=0;i<3;i++){//技巧2: 可以把重覆的東西, 用迴圈來簡化
myPrepareTexture(i);
}
}
void myPolygon(int num){//技巧3: 可以把重覆的東西, 用函式來簡化
glPushMatrix();
glScalef(0.3, 0.8, 0.8);
glBindTexture(GL_TEXTURE_2D, id[num]);
glBegin(GL_POLYGON);
glTexCoord2f(0, 0);   glVertex3f( -0.5,  0.5, 0);
glTexCoord2f(1, 0);   glVertex3f(  0.5,  0.5, 0);
glTexCoord2f(1, 1);   glVertex3f(  0.5, -0.5, 0);
glTexCoord2f(0, 1);   glVertex3f( -0.5, -0.5, 0);
glEnd();
glPopMatrix();
}
void myBody(){
myPolygon(0);
}
void myLeg(){
glPushMatrix();
glScalef(0.5, 0.5, 0.5);
myPolygon(1);
glPopMatrix();
}
void myHand(){
glPushMatrix();// 今天的技巧2: 可以利用 scale把後面的東西都變小
//T R S: Translate, Rotate, Scale, 要放在 glPushMatrix()/glPopMatrix()
glScalef(0.5, 0.5, 0.5);
myPolygon(2);
glPopMatrix();
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glScalef(0.5, 0.5, 0.5);//今天的技巧1: 可以利用 scale把後面的東西都變小
myBody();
glPushMatrix();//今天的技巧3: 大的在外面
glTranslatef(0.2,0,0);//右手
glRotatef(angle1, 0,0,1);
glTranslatef(0, -0.2, 0);
myHand();
glPushMatrix();//今天的技巧3: 小的在裡面
glTranslatef(0,-0.2,0);//小右手
glRotatef(angle2, 0,0,1);
glTranslatef(0, -0.2, 0);
myHand();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.2,0,0);//左手
glRotatef(-angle3, 0,0,1);
glTranslatef(0, -0.2, 0);
myHand();
glPushMatrix();//今天的技巧3: 小的在裡面
glTranslatef(0,-0.2,0);//小右手
glRotatef(-angle4, 0,0,1);
glTranslatef(0, -0.2, 0);
myHand();
glPopMatrix(); 
glPopMatrix();
glPushMatrix();
glTranslatef(0.1,-0.3,0);//右腿
glRotatef(angle5, 0,0,1);
glTranslatef(0, -0.2, 0);
myLeg();
//請把小腿及腳掌做出來
glPushMatrix();
glTranslatef(0,-0.2,0);//右腿
glRotatef(angle6, 0,0,1);
glTranslatef(0, -0.2, 0);
myLeg(); 
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.1,-0.3,0);//左腿
glRotatef(-angle7, 0,0,1);
glTranslatef(0, -0.2, 0);
myLeg();
//請把小腿及腳掌做出來
glPushMatrix();
glTranslatef(0,-0.2,0);//右腿
glRotatef(-angle8, 0,0,1);
glTranslatef(0, -0.2, 0);
myLeg(); 
glPopMatrix(); 
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}

void timer(int t);
FILE * fout= NULL, *fin=NULL;

void keyboard(unsigned char key, int x, int y)
{
if(key=='1') angle1+=3;
if(key=='2') angle1-=3;
if(key=='3') angle2+=3;
if(key=='4') angle2-=3;
if(key=='5') angle3+=3;
if(key=='6') angle3-=3;
if(key=='7') angle4+=3;
if(key=='8') angle4-=3;
if(key=='q') angle5+=3;
if(key=='w') angle5-=3;
if(key=='e') angle6+=3;
if(key=='r') angle6-=3;
if(key=='t') angle7+=3;
if(key=='y') angle7-=3;
if(key=='u') angle8+=3;
if(key=='i') angle8-=3;
if(key=='c'){
if(fout==NULL) fout=fopen("my_output_file_for_animation.txt","w+");
fprintf(fout,"%f %f %f %f %f %f %f %f \n",angle1,angle2,angle3,angle4,angle5,angle6,angle7,angle8);
 }
 if(key=='v'){
if(fin==NULL) fin=fopen("my_output_file_for_animation.txt","r");
fscanf(fin, "%f %f %f %f %f %f %f %f \n",&angle1,&angle2,&angle3,&angle4,&angle5,&angle6,&angle7,&angle8);
printf("%f %f %f %f %f %f %f %f \n",angle1,angle2,angle3,angle4,angle5,angle6,angle7,angle8);
 }
 if(key=='b'){
if(fin==NULL) fin=fopen("my_output_file_for_animation.txt","r");
glutTimerFunc(1000,timer,0);
 }

glutPostRedisplay();

}

void timer(int t)
{
glutTimerFunc(1000, timer, 0);
fscanf(fin,"%f %f %f %f %f %f %f %f\n",&angle1,&angle2,&angle3,&angle4,&angle5,&angle6,&angle7,&angle8);
printf("%f %f %f %f %f %f %f %f\n",angle1,angle2,angle3,angle4,angle8);
glutPostRedisplay();

}

int main()
{
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("week14");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
myTexture();//不要忘了加哦!
glutMainLoop();
}

2014年5月15日 星期四

01160456_謝之麟, HW013, Week13

#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <stdio.h>
//IplImage *img1, *img2, *img3, *img4;
//GLuint id1, id2, id3, id4;
IplImage * img[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
GLuint id[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
float angleX=0;
void myPrepareTexture(int i)//用參數來配, 找對應正確的變數
{//技巧3: 可以把重覆的東西, 用函式來簡化
 cvCvtColor(img[i], img[i], CV_BGR2RGB);
 glEnable(GL_TEXTURE_2D);
 glGenTextures(1, &id[i]);
 glBindTexture(GL_TEXTURE_2D, id[i]);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img[i]->width, img[i]->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img[i]->imageData);
}
void myTexture()
{
 img[0]=cvLoadImage("imgbody.png");
 img[1]=cvLoadImage("imgHand1.png");
 img[2]=cvLoadImage("imgLeg1.png");
 for(int i=0;i<3;i++){//技巧2: 可以把重覆的東西, 用迴圈來簡化
  myPrepareTexture(i);
 }
}
void myPolygon(int num){//技巧3: 可以把重覆的東西, 用函式來簡化
 glPushMatrix();
  glScalef(0.3, 0.8, 0.8);
  glBindTexture(GL_TEXTURE_2D, id[num]);
  glBegin(GL_POLYGON);
   glTexCoord2f(0, 0);   glVertex3f( -0.5,  0.5, 0);
   glTexCoord2f(1, 0);   glVertex3f(  0.5,  0.5, 0);
   glTexCoord2f(1, 1);   glVertex3f(  0.5, -0.5, 0);
   glTexCoord2f(0, 1);   glVertex3f( -0.5, -0.5, 0);
  glEnd();
 glPopMatrix();
}
void myBody(){
 myPolygon(0);
}
void myLeg(){
     glPushMatrix();
     glScalef(0.5,0.5,0.5);
 myPolygon(1);
 glPopMatrix();
}
void myHand(){
     glPushMatrix();
     glScalef(0.5,0.5,0.5);
 myPolygon(2);
 glPopMatrix();
}
void display()
{
 glEnable(GL_DEPTH_TEST);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPushMatrix();
 glScalef(0.5,0.5,0.5);
  myBody();
  glPushMatrix();
   glTranslatef(0.2,0,0);//右手
   glRotatef(angleX, 0,0,1);
   glTranslatef(0, -0.4, 0);
   myHand();
 
   glPushMatrix();
   glTranslatef(0,-0.2,0);
   glRotatef(angleX,0,0,1);
   glTranslatef(0,-0.2,0);
   myHand();
   glPopMatrix();
 
  glPopMatrix();
  glPushMatrix();
   glTranslatef(-0.2,0,0);//左手
   glRotatef(-angleX, 0,0,1);
   glTranslatef(0, -0.4, 0);
   myHand();
  glPopMatrix();
  glPushMatrix();
   glTranslatef(-0.2,-0.3,0);//左腿
   glRotatef(-angleX, 0,0,1);
   glTranslatef(0, -0.4, 0);
   myLeg();
  glPopMatrix();
 glPopMatrix();
 glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
 if(key=='a') angleX+=3;
 if(key=='b') angleX-=3;
 glutPostRedisplay();

}
int main()
{
 glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
 glutCreateWindow("week12");
 glutDisplayFunc(display);
 glutKeyboardFunc(keyboard);
 myTexture();//不要忘了加哦!
 glutMainLoop();
}


#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <stdio.h>
//IplImage *img1, *img2, *img3, *img4;
//GLuint id1, id2, id3, id4;
IplImage * img[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
GLuint id[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
float angleA=0,angleX=0,angleY=0,angleZ=0;
void myPrepareTexture(int i)//用參數來配, 找對應正確的變數
{//技巧3: 可以把重覆的東西, 用函式來簡化
 cvCvtColor(img[i], img[i], CV_BGR2RGB);
 glEnable(GL_TEXTURE_2D);
 glGenTextures(1, &id[i]);
 glBindTexture(GL_TEXTURE_2D, id[i]);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img[i]->width, img[i]->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img[i]->imageData);
}
void myTexture()
{
 img[0]=cvLoadImage("imgbody.png");
 img[1]=cvLoadImage("imgHand1.png");
 img[2]=cvLoadImage("imgLeg1.png");
 for(int i=0;i<3;i++){//技巧2: 可以把重覆的東西, 用迴圈來簡化
 myPrepareTexture(i);
 }
}
void myPolygon(int num){//技巧3: 可以把重覆的東西, 用函式來簡化
 glPushMatrix();
 glScalef(0.3, 0.8, 0.8);
 glBindTexture(GL_TEXTURE_2D, id[num]);
 glBegin(GL_POLYGON);
  glTexCoord2f(0, 0);   glVertex3f( -0.5,  0.5, 0);
  glTexCoord2f(1, 0);   glVertex3f(  0.5,  0.5, 0);  
  glTexCoord2f(1, 1);   glVertex3f(  0.5, -0.5, 0);  
  glTexCoord2f(0, 1);   glVertex3f( -0.5, -0.5, 0);  
 glEnd();
 glPopMatrix();
}
void myBody(){
 myPolygon(0);
}
void myLeg(){
 myPolygon(1);
}
void myHand(){
 myPolygon(2);
}
void display()
{
 glEnable(GL_DEPTH_TEST);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPushMatrix();
 glScalef(0.5,0.5,0.5);
 myBody();
 glPushMatrix();
  glTranslatef(0.2,0,0);//右手
  glRotatef(angleA, 0,0,1);
  glTranslatef(0, -0.4, 0);
  myHand();
  glPushMatrix();
   glTranslatef(0,-0.25,0);//small右手
   glRotatef(angleZ, 0,0,1);
   glTranslatef(0, -0.4, 0);
   myHand();
  glPopMatrix();
 glPopMatrix();

 glPushMatrix();
  glTranslatef(-0.2,0,0);//左手
  glRotatef(-angleA, 0,0,1);
  glTranslatef(0, -0.4, 0);
  myHand();
  glPushMatrix();
   glTranslatef(0,-0.25,0);//small左手
   glRotatef(angleZ, 0,0,-1);
   glTranslatef(0, -0.4, 0);
   myHand();
  glPopMatrix();
 glPopMatrix();

 glPushMatrix();
  glTranslatef(-0.2,-0.3,0);//左腿
  glRotatef(-angleX, 0,0,1);
  glTranslatef(0, -0.4, 0);
  myLeg();
  glPushMatrix();
   glTranslatef(0,-0.3,0);//小左腿
   glRotatef(-angleY, 0,0,1);
   glTranslatef(0, -0.4, 0);
   myLeg();
  glPopMatrix();
 glPopMatrix();

 glPushMatrix();
  glTranslatef(0.2,-0.3,0);//右腿
  glRotatef(-angleX, 0,0,-1);
  glTranslatef(0, -0.4, 0);
  myLeg();
  glPushMatrix();
   glTranslatef(0,-0.3,0);//小右腿
   glRotatef(-angleY, 0,0,-1);
   glTranslatef(0, -0.4, 0);
   myLeg();
  glPopMatrix();
 glPopMatrix();


 glPopMatrix();
 glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
 if(key=='1') angleA+=3;
 if(key=='3') angleA-=3;
 if(key=='a') angleX+=3;
 if(key=='d') angleX-=3;
 if(key=='w') angleY+=3;
 if(key=='s') angleY-=3;
 if(key=='q') angleZ+=3;
 if(key=='e') angleZ-=3;
 glutPostRedisplay();
}
int main()
{
 glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
 glutCreateWindow("week12");
 glutDisplayFunc(display);
 glutKeyboardFunc(keyboard);
 myTexture();//不要忘了加哦!
 glutMainLoop();
}



2014年5月8日 星期四

01160456_謝之麟, HW012, Week12



#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
IplImage *img1,*img2, *img3, *img4;
GLuint id1,id2,id3,id4;
float angleX=0;

void mtTexture()
{
 img1=cvLoadImage("body.jpg");
 img2=cvLoadImage("hand1.jpg");
 img3=cvLoadImage("leg1.jpg");

 cvCvtColor(img1, img1, CV_BGR2RGB);
 cvCvtColor(img2, img2, CV_BGR2RGB);
 cvCvtColor(img3, img3, CV_BGR2RGB);
 glEnable(GL_TEXTURE_2D);
 glGenTextures(1, &id1);
 glGenTextures(1, &id2);
 glGenTextures(1, &id3);

 glBindTexture(GL_TEXTURE_2D, id1);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img1->width, img1->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img1->imageData);

 glBindTexture(GL_TEXTURE_2D, id2);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img2->width, img2->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img2->imageData);

 glBindTexture(GL_TEXTURE_2D, id3);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img3->width, img3->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img3->imageData);

}
void display()
{
 glEnable(GL_DEPTH_TEST);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPushMatrix();
 glRotatef(angleX, 0,1,0);
 glutSolidTeapot(0.3);
 glPopMatrix();
 glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
 if(key=='a') angleX+=3;
 if(key=='b') angleX-=3;
 glutPostRedisplay();

}
void myLight()
{
 const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
 glEnable(GL_LIGHT0);
 glEnable(GL_NORMALIZE);
 glEnable(GL_COLOR_MATERIAL);
 glEnable(GL_LIGHTING);
 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
int main()
{
 glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
 glutCreateWindow("week12");
 glutDisplayFunc(display);
 glutKeyboardFunc(keyboard);
 myLight();
 glutMainLoop();
}

2014年5月1日 星期四

01160456_謝之麟, HW011, Week11

#include <GL/glut.h>
float angleX=0;
void display()
{
 glEnable(GL_DEPTH_TEST);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPushMatrix();
  glRotatef(angleX, 0,1,0);
  glutSolidTeapot(0.3);

  glPushMatrix();
  glTranslatef(0.4,0,0);
  glutSolidSphere(0.2,30,30);
  glPopMatrix();

 glPushMatrix();
  glTranslatef(-0.4,0,0);
  glutSolidSphere(0.2,30,30);
  glPopMatrix();

   glPushMatrix();
  glTranslatef(0,0.4,0);
  glutSolidSphere(0.2,30,30);
  glPopMatrix();

 glPopMatrix();
 glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
     if(key=='a') angleX+=3;
     if(key=='b') angleX-=3;
     glutPostRedisplay();
     
}
void myLight()
{
 const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
 glEnable(GL_LIGHT0);
 glEnable(GL_NORMALIZE);
 glEnable(GL_COLOR_MATERIAL);
 glEnable(GL_LIGHTING);
 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
int main()
{
 glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
 glutCreateWindow("week11");
 glutDisplayFunc(display);
 glutKeyboardFunc(keyboard);
 myLight();
 glutMainLoop();
}
--------------------------------------------------------------------------------------------------------

#include <GL/glut.h>
float angleX=0,angle1=0;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angleX ,0,1,0);
glutWireTeapot(0.3);
glPushMatrix();
glTranslatef(0.4,0,0);
glutSolidSphere(0.2,30,30);
glPushMatrix();
glRotatef(angle1 ,0,0,1);
glTranslatef(0.3,0,0);
glScalef(2,0.5,0.5);
glutSolidCube(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.4,0,0);
glutSolidSphere(0.2,30,30);
glPushMatrix();
glRotatef(angle1 ,0,0,-1);
glTranslatef(-0.3,0,0);
glScalef(2,0.5,0.5);
glutSolidCube(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(0,0.4,0);
glutSolidSphere(0.2,30,30);
glPopMatrix();
glPushMatrix();//右腳 
glTranslatef(0.2,-0.25,0);
glRotatef(angle1,0,0,1);
glTranslatef(0,-0.45/2,0);
glPushMatrix();
glScalef(0.2,0.45,0.12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//右小腿 
glTranslatef(0,-0.18,0);
glRotatef(angle1,0,0,1);
glTranslatef(0,-0.45/2,0);
glScalef(0.2,0.45,0.12);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPushMatrix();//左腿 
glTranslatef(-0.2,-0.25,0);
glRotatef(angle1,0,0,1);
glTranslatef(0,-0.45/2,0);
glPushMatrix();
glScalef(0.2,0.45,0.12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();//左小腿 
glTranslatef(0,-0.18,0);
glRotatef(angle1,0,0,1);
glTranslatef(0,-0.45/2,0);
glScalef(0.2,0.45,0.12);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers(); 
}
void keyboard (unsigned char key , int x,int y)
{
 if(key=='a') angleX+=3;
 if(key=='b') angleX-=3;
 if(key=='1') angle1+=3;
 if(key=='2') angle1-=3; 
 glutPostRedisplay(); 
}
void myLight()
{
 const GLfloat light_position[] ={2.0f,5.0f,-5.0f,0.0f};
 glEnable(GL_LIGHT0);
 glEnable(GL_NORMALIZE);
 glEnable(GL_COLOR_MATERIAL);
 glEnable(GL_LIGHTING);
 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  
}
int main()
{
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
 glutCreateWindow("week11");
 glutDisplayFunc(display);
 glutKeyboardFunc(keyboard);
 myLight();
 glutMainLoop();
}