Player.cpp 545 B

1234567891011121314151617181920212223242526272829
  1. #define _USE_MATH_DEFINES
  2. #include <cmath>
  3. #include "Player.h"
  4. #include <GL/freeglut.h>
  5. Player::Player()
  6. {
  7. speed = 10;
  8. }
  9. void Player::setCamera()
  10. {
  11. glRotatef(rotation.x, 1, 0, 0);
  12. glRotatef(rotation.y, 0, 1, 0);
  13. glTranslatef(-position.x, -position.y, -position.z);
  14. }
  15. void Player::setPosition(float angle, float fac, bool height)
  16. {
  17. fac *= speed;
  18. if (height)
  19. position.y += angle*fac;
  20. else
  21. {
  22. position.x -= (float)cos((rotation.y + angle) / 180 * M_PI) * fac;
  23. position.z -= (float)sin((rotation.y + angle) / 180 * M_PI) * fac;
  24. }
  25. }