Player.cpp 542 B

12345678910111213141516171819202122232425262728
  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. if (height)
  18. position.y += angle*fac;
  19. else
  20. {
  21. position.x -= (float)cos((rotation.y + angle) / 180 * M_PI) * fac*speed;
  22. position.z -= (float)sin((rotation.y + angle) / 180 * M_PI) * fac*speed;
  23. }
  24. }