CrystalJohan.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "CrystalJohan.h"
  2. #include <GL/freeglut.h>
  3. #include "World.h"
  4. void CrystalJohan::init()
  5. {
  6. world = new World();
  7. lastFrameTime = 0;
  8. glClearColor(0.7, 0.7, 1.0, 1.0);
  9. glEnable(GL_DEPTH_TEST);
  10. }
  11. void CrystalJohan::draw()
  12. {
  13. glMatrixMode(GL_PROJECTION);
  14. glLoadIdentity();
  15. gluPerspective(70, width / (float)height, 0.1f, 100);
  16. glMatrixMode(GL_MODELVIEW);
  17. glLoadIdentity();
  18. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  19. world->draw();
  20. }
  21. void CrystalJohan::update()
  22. {
  23. float frameTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
  24. float deltaTime = frameTime - lastFrameTime;
  25. lastFrameTime = frameTime;
  26. // if(keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
  27. if (keyboardState.keys[27])
  28. exit(0);
  29. world->player.rotation.y += mouseOffset.x/10.0f;
  30. world->player.rotation.x += mouseOffset.y/10.0f;
  31. if (world->player.rotation.x > 90)
  32. world->player.rotation.x = 90;
  33. if (world->player.rotation.x < -90)
  34. world->player.rotation.x = -90;
  35. mouseOffset = Vec2f(0, 0);
  36. prevKeyboardState = keyboardState;
  37. glutPostRedisplay();
  38. }
  39. KeyboardState::KeyboardState()
  40. {
  41. memset(keys, 0, sizeof(keys));
  42. memset(special, 0, sizeof(special));
  43. }