Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. // controls for navigating ship using arrow keys
  2. void SpecialInput(int key, int x, int y) {
  3. switch (key) {
  4. case GLUT_KEY_UP:
  5. myWorld.shipType[selection]->translate(0, -7);
  6. break;
  7. case GLUT_KEY_LEFT:
  8. //rotate ship given center point of the ship
  9. myWorld.shipType[selection]->rotate(
  10. myWorld.shipType[selection]->center[0],
  11. myWorld.shipType[selection]->center[1], -2);
  12. break;
  13. case GLUT_KEY_RIGHT:
  14. myWorld.shipType[selection]->rotate(
  15. myWorld.shipType[selection]->center[0],
  16. myWorld.shipType[selection]->center[1], 2);
  17. break;
  18. }
  19. glutPostRedisplay();
  20. }
  21.  
  22. void Shape2D::rotate(GLfloat rx, GLfloat ry, GLfloat angle){
  23. glTranslatef(rx, ry, 0);
  24. glRotatef(angle, 0., 0., 1.);
  25. glTranslatef(-rx, -ry, 0);
  26. }
  27.  
  28. switch (key) {
  29. case GLUT_KEY_UP:
  30. myWorld.shipType[selection]->translate(0, -7);
  31. break;
  32. case GLUT_KEY_LEFT:
  33. glPushMatrix();
  34. myWorld.shipType[selection]->rotate(
  35. myWorld.shipType[selection]->center[0],
  36. myWorld.shipType[selection]->center[1], -2);
  37. myWorld.shipType[selection]->draw();
  38. glutPostRedisplay();
  39. glPopMatrix();
  40. break;
  41. case GLUT_KEY_RIGHT:
  42. myWorld.shipType[selection]->rotate(
  43. myWorld.shipType[selection]->center[0],
  44. myWorld.shipType[selection]->center[1], 2);
  45. break;
  46. }
  47. //glutPostRedisplay();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement