Advertisement
Guest User

Untitled

a guest
Oct 27th, 2010
3,339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. // glutTimerFunc() example
  2.  
  3. void timerFcn(int value)
  4. {
  5.  
  6. // rotation variables
  7.         if (headrotate) theRobot.head.rotation += 2.;
  8.  
  9. // movement variables
  10.  
  11.         if (walkfwd) theRobot.movedZ += .01;
  12.         else
  13.         if (walkback) theRobot.movedZ -= .01;
  14.  
  15. // render + repeat
  16.         glutPostRedisplay();
  17.         glutTimerFunc(10, timerFcn, 1);
  18.  
  19.     // reset movement
  20. //      r = 0;
  21. //      walkfwd = false; walkback = false;
  22.  
  23. }
  24.  
  25. void reshape(int w, int h)
  26. {
  27.    glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  28.    glMatrixMode(GL_PROJECTION);
  29.    glLoadIdentity();
  30.  
  31.    gluPerspective(65, (GLfloat) w/(GLfloat) h, 1., 20.);
  32.  
  33.    glMatrixMode(GL_MODELVIEW);
  34.    glLoadIdentity();
  35.  
  36.    glTranslatef (0.0, 0.0, -5.0);
  37. }
  38.  
  39.  
  40. void keyboard(unsigned char key, int x, int y)
  41. {
  42.    switch (key) {
  43.       case 27:
  44.          exit(0);
  45.          break;
  46.  
  47. // wireframe
  48.          case '1': w = !w; break;
  49.  
  50. // translation //
  51.          case 'w': theRobot.movedZ += .1; break;
  52.          case 's': theRobot.movedZ -= .1; break;
  53.  
  54. // rotation //
  55. // head
  56.          case 'h': headrotate = !headrotate; break;
  57. // all
  58.          case 'a': r = 5; break;
  59.          case 'd': r = -5; break;
  60. // stop
  61.          case 'r':
  62.  
  63.              theRobot = buildRobot();
  64.              walkfwd = false; walkback = false;
  65.              headrotate = false;
  66.              break;
  67.  
  68.      default: break;
  69.    }
  70. }
  71.  
  72. int main(int argc, char** argv)
  73. {
  74.    glutInit(&argc, argv);
  75.    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  76.    glutInitWindowSize (1024, 768);
  77.    glutInitWindowPosition(100, 0);
  78.    glutCreateWindow("Assignment 2 - Liam Jenkin 6517080");
  79.  
  80.    init();
  81.  
  82.    glutReshapeFunc(reshape);
  83.    glutDisplayFunc(display);
  84.    glutKeyboardFunc(keyboard);
  85.    glutTimerFunc(10,timerFcn, 0);
  86.  
  87.    glutMainLoop();
  88.  
  89.  
  90.    return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement