Player.cpp 814 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #define _USE_MATH_DEFINES
  2. #include <cmath>
  3. #include "Player.h"
  4. #include <GL/freeglut.h>
  5. Player* Player::instance = NULL;
  6. Player::Player()
  7. {
  8. }
  9. Player* Player::getInstance()
  10. {
  11. if (instance == nullptr)
  12. instance = new Player();
  13. return instance;
  14. }
  15. void Player::init()
  16. {
  17. instance = new Player();
  18. }
  19. Player::~Player()
  20. {
  21. if (leftWeapon)
  22. delete leftWeapon;
  23. if (rightWeapon)
  24. delete rightWeapon;
  25. }
  26. void Player::setCamera()
  27. {
  28. glRotatef(rotation.x, 1, 0, 0);
  29. glRotatef(rotation.y, 0, 1, 0);
  30. glTranslatef(-position.x, -position.y, -position.z);
  31. }
  32. void Player::setPosition(float angle, float fac, bool height)
  33. {
  34. if (height)
  35. position.y += angle*fac;
  36. else
  37. {
  38. position.x -= (float)cos((rotation.y + angle) / 180 * M_PI) * fac;
  39. position.z -= (float)sin((rotation.y + angle) / 180 * M_PI) * fac;
  40. }
  41. }