Player.cpp 819 B

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