Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // glutTimerFunc() example
- void timerFcn(int value)
- {
- // rotation variables
- if (headrotate) theRobot.head.rotation += 2.;
- // movement variables
- if (walkfwd) theRobot.movedZ += .01;
- else
- if (walkback) theRobot.movedZ -= .01;
- // render + repeat
- glutPostRedisplay();
- glutTimerFunc(10, timerFcn, 1);
- // reset movement
- // r = 0;
- // walkfwd = false; walkback = false;
- }
- void reshape(int w, int h)
- {
- glViewport(0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(65, (GLfloat) w/(GLfloat) h, 1., 20.);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef (0.0, 0.0, -5.0);
- }
- void keyboard(unsigned char key, int x, int y)
- {
- switch (key) {
- case 27:
- exit(0);
- break;
- // wireframe
- case '1': w = !w; break;
- // translation //
- case 'w': theRobot.movedZ += .1; break;
- case 's': theRobot.movedZ -= .1; break;
- // rotation //
- // head
- case 'h': headrotate = !headrotate; break;
- // all
- case 'a': r = 5; break;
- case 'd': r = -5; break;
- // stop
- case 'r':
- theRobot = buildRobot();
- walkfwd = false; walkback = false;
- headrotate = false;
- break;
- default: break;
- }
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowSize (1024, 768);
- glutInitWindowPosition(100, 0);
- glutCreateWindow("Assignment 2 - Liam Jenkin 6517080");
- init();
- glutReshapeFunc(reshape);
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
- glutTimerFunc(10,timerFcn, 0);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement