d10070dd

glRotate_skelton-edit

Dec 16th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. //list1322.c
  2. #include<gl/glut.h>
  3. #include <math.h>
  4.  
  5. static
  6. int angle=0;
  7. float tx=0.0;
  8. float ty=0.0;
  9. float tz=0.0;
  10. float sx=1.0;
  11. float sy=1.0;
  12. float sz=1.0;
  13.  
  14. //Call back Function
  15. static void
  16. display()
  17. {
  18.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  19.    
  20.     glMatrixMode (GL_MODELVIEW);
  21.     glLoadIdentity();
  22.     //eye-position, direction, x-y-z up
  23.     gluLookAt(0.0,30.0,100.0,0.0,0.0,0.0,0.0,1.0,0.0);
  24.    
  25.     glPushMatrix();
  26.     glRotatef(angle,1.0,0.0,0.0);
  27.     glRotatef(angle,0.0,1.0,0.0);
  28.     glRotatef(angle,0.0,0.0,1.0);
  29.     glTranslatef(tx,ty,tz);
  30.     //glScalef(sx, sy, sz);
  31.     glEnable(GL_COLOR_MATERIAL);
  32.     glColor3f(0.9,0.5,0.2);
  33.     glutSolidTeapot(25.0);
  34.     glDisable(GL_COLOR_MATERIAL);
  35.     glPopMatrix();
  36.  
  37.     glutSwapBuffers();
  38. }
  39.    
  40. //windows resize function
  41. static void
  42. reshape(int w,int h)
  43. {
  44.     glMatrixMode(GL_PROJECTION);
  45.     glLoadIdentity();
  46.     glViewport(0,0,w,h);
  47.     gluPerspective(40.0,(w/(double)h),1.0,1000.0);
  48. }
  49.  
  50.  
  51. //Call Status:Idle
  52. static void
  53. idle()
  54. {
  55.     angle=(angle+1)%360;
  56.     tx=fmodf(tx+0.01,10);
  57.     ty=fmodf(ty+0.01,10);
  58.     tz=fmodf(tz+0.01,10);
  59.     sx=fmodf(sx+0.01,10);
  60.     sy=fmodf(sy+0.01,10);
  61.     sz=fmodf(sz+0.01,10);
  62.     glutPostRedisplay();
  63. }
  64.  
  65.  
  66.  
  67. int
  68. main(int argc, char* argv[])
  69. {
  70.     //GLUT Initialization
  71.     glutInit(&argc,argv);
  72.  
  73.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  74.     glutInitWindowSize(400,300);
  75.     glutCreateWindow(argv[0]);
  76.  
  77.     //Setting OpenGL
  78.     glClearColor(1.0,1.0,1.0,0.0);
  79.  
  80.     glShadeModel(GL_SMOOTH);
  81.     glCullFace(GL_FRONT);
  82.     glEnable(GL_CULL_FACE);
  83.     glEnable(GL_DEPTH_TEST);
  84.    
  85.     //Callback
  86.     glutDisplayFunc(display);
  87.     glutReshapeFunc(reshape);
  88.     glutIdleFunc(idle);
  89.  
  90.     glutMainLoop();
  91.  
  92.     return 0;
  93. }
  94.  
  95. /*
  96. void drawAry(void)
  97. {
  98.     int i,j;
  99.  
  100.     GLfloat txyz[12][3]=
  101.     {
  102.         //{0.0,0.0,0.0},
  103.         {0.1,0.0,0.0},
  104.         {0.0,0.0,0.0},
  105.         {-0.1,0.0,0.0},
  106.         {0.0,0.0,0.0},
  107.         {0.0,0.1,0.0},
  108.         {0.0,0.0,0.0},
  109.         {0.0,-0.1,0.0},
  110.         {0.0,0.0,0.0},
  111.         {0.0,0.0,0.1},
  112.         {0.0,0.0,0.0},
  113.         {0.0,0.0,-0.1},
  114.         {0.0,0.0,0.0}
  115.     };
  116.  
  117.  
  118.     for(i=0;i<12;i++)
  119.     {
  120.         tx=txyz[i][0];
  121.         ty=txyz[i][1];
  122.         tz=txyz[i][2];
  123.         //printf("%d\n",tx);
  124.         //printf("%d\n",ty);
  125.         //printf("%d\n",tz);
  126.     };
  127.    
  128.     GLfloat sxyz[11][3]=
  129.     {
  130.         {1.0,1.0,1.0},
  131.         {1.1,1.1,1.1},
  132.         {1.2,1.2,1.2},
  133.         {1.3,1.3,1.3},
  134.         {1.4,1.4,1.4},
  135.         {1.5,1.5,1.5},
  136.         {1.4,1.4,1.4},
  137.         {1.3,1.3,1.3},
  138.         {1.2,1.2,1.2},
  139.         {1.1,1.1,1.1},
  140.         {1.0,1.0,1.0},
  141.     };
  142.  
  143.     for(j=0;j<11;j++)
  144.     {
  145.         sx=sxyz[j][0];
  146.         sy=sxyz[j][1];
  147.         sz=sxyz[j][2];
  148.         //printf("%d\n",sx);
  149.         //printf("%d\n",sy);
  150.         //printf("%d\n",sz);
  151.     };
  152. }
  153. */
Advertisement
Add Comment
Please, Sign In to add comment