Camera.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include "client/math/Camera.h"
  2. #include "client/Utils.h"
  3. Camera::Camera() : oldLengthAngle(0), lengthAngle(0), oldWidthAngle(0), widthAngle(0)
  4. {
  5. }
  6. const Vector& Camera::getFront() const
  7. {
  8. return front;
  9. }
  10. const Vector& Camera::getBack() const
  11. {
  12. return back;
  13. }
  14. const Vector& Camera::getRight() const
  15. {
  16. return right;
  17. }
  18. const Vector& Camera::getLeft() const
  19. {
  20. return left;
  21. }
  22. const Vector& Camera::getUp() const
  23. {
  24. return up;
  25. }
  26. const Vector& Camera::getDown() const
  27. {
  28. return down;
  29. }
  30. const Vector& Camera::getFlatFront() const
  31. {
  32. return flatFront;
  33. }
  34. const Vector& Camera::getFlatBack() const
  35. {
  36. return flatBack;
  37. }
  38. const Vector& Camera::getFlatRight() const
  39. {
  40. return flatRight;
  41. }
  42. const Vector& Camera::getFlatLeft() const
  43. {
  44. return flatLeft;
  45. }
  46. const Vector& Camera::getFlatUp() const
  47. {
  48. return flatUp;
  49. }
  50. const Vector& Camera::getFlatDown() const
  51. {
  52. return flatDown;
  53. }
  54. const Vector& Camera::getPosition() const
  55. {
  56. return interPosition;
  57. }
  58. void Camera::storePosition()
  59. {
  60. oldPosition = position;
  61. oldLengthAngle = lengthAngle;
  62. oldWidthAngle = widthAngle;
  63. }
  64. void Camera::setPosition(const Vector& pos, float length, float width)
  65. {
  66. position = pos;
  67. lengthAngle = length;
  68. widthAngle = width;
  69. }
  70. void Camera::update(float lag)
  71. {
  72. // back
  73. back.setAngles(interpolate(lag, oldLengthAngle, lengthAngle), interpolate(lag, oldWidthAngle, widthAngle));
  74. // front
  75. front.setInverse(back);
  76. // right
  77. right = front;
  78. right.cross(0.0f, 1.0f, 0.0f);
  79. right.normalize();
  80. // left
  81. left.setInverse(right);
  82. // up
  83. up = front;
  84. up.cross(left);
  85. up.normalize();
  86. // down
  87. down.setInverse(up);
  88. // interpolated position
  89. interPosition = oldPosition;
  90. interPosition.addMul(position, lag);
  91. interPosition.addMul(oldPosition, -lag);
  92. // flat back
  93. flatBack = back;
  94. flatBack.setY(0.0f);
  95. flatBack.normalize();
  96. // flat back
  97. flatFront.setInverse(flatBack);
  98. // flat right
  99. flatRight = front;
  100. flatRight.cross(0.0f, 1.0f, 0.0f);
  101. flatRight.normalize();
  102. // flat left
  103. flatLeft.setInverse(flatRight);
  104. // flat up
  105. flatUp.set(0.0f, 1.0f, 0.0f);
  106. // flat down
  107. flatDown.setInverse(flatUp);
  108. }