Guest User

Untitled

a guest
Oct 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #include <stdlib.h>
  3.  
  4. static int shoulder = 0, elbow = 0;
  5.  
  6. void init(void){
  7.     glClearColor (0.0, 0.0, 0.0, 0.0);
  8. }
  9.  
  10. void display(void){
  11.     glClear (GL_COLOR_BUFFER_BIT);
  12.     glPushMatrix();
  13.  
  14.     /* origem posicionada no ombro */
  15.     glTranslatef (-1.0, 0.0, 0.0);
  16.     glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0);
  17.    
  18.     /* origem posicionada no centro do braço */
  19.     glTranslatef (1.0, 0.0, 0.0);
  20.     glPushMatrix();
  21.     glScalef (2.0, 0.4, 1.0);
  22.     glutWireCube (1.0);
  23.     glPopMatrix();
  24.    
  25.     /* origem posicionada no cotovelo */
  26.     glTranslatef (1.0, 0.0, 0.0);
  27.     glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
  28.     glTranslatef (1.0, 0.0, 0.0);
  29.     glPushMatrix();
  30.     glScalef (2.0, 0.4, 1.0);
  31.     glutWireCube (1.0);
  32.     glPopMatrix();
  33.    
  34.     /* origem volta para o sistema de coordenadas original */
  35.     glPopMatrix();
  36.     glutSwapBuffers();
  37. }
  38.  
  39. void reshape (int w, int h){
  40.     glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  41.     glMatrixMode (GL_PROJECTION);
  42.     glLoadIdentity ();
  43.     gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
  44.     glMatrixMode(GL_MODELVIEW);glLoadIdentity();
  45.     glTranslatef (0.0, 0.0, -5.0);
  46. }
  47.  
  48. void keyboard (unsigned char key, int x, int y){
  49.     switch (key) {
  50.         case 's':
  51.             shoulder = (shoulder + 5) % 360;
  52.             glutPostRedisplay();
  53.             break;
  54.         case 'S':
  55.             shoulder = (shoulder - 5) % 360;
  56.             glutPostRedisplay();
  57.             break;
  58.         case 'e':
  59.             elbow = (elbow + 5) % 360;
  60.             glutPostRedisplay();
  61.             break;
  62.         case 'E':
  63.             elbow = (elbow - 5) % 360;
  64.             glutPostRedisplay();
  65.             break;
  66.         case 27:
  67.             exit(0);
  68.             break;
  69.         default:   
  70.             break;
  71.     }
  72. }
  73.  
  74. int main(int argc, char** argv){
  75.     glutInit(&argc, argv);
  76.     glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
  77.     glutInitWindowSize (500, 500);
  78.     glutInitWindowPosition (100, 100);
  79.     glutCreateWindow (argv[0]);
  80.     init ();
  81.     glutDisplayFunc(display);
  82.     glutReshapeFunc(reshape);
  83.     glutKeyboardFunc(keyboard);
  84.     glutMainLoop();
  85.     return 0;
  86. }
Add Comment
Please, Sign In to add comment