Camera.cpp 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "client/math/Camera.h"
  2. #include "client/Utils.h"
  3. Camera::Camera(const Ray& ray) : ray(ray) {
  4. }
  5. const Vector& Camera::getBack() const {
  6. return back;
  7. }
  8. const Vector& Camera::getRight() const {
  9. return right;
  10. }
  11. const Vector& Camera::getUp() const {
  12. return up;
  13. }
  14. const Vector& Camera::getFlatBack() const {
  15. return flatBack;
  16. }
  17. const Vector& Camera::getFlatRight() const {
  18. return flatRight;
  19. }
  20. const Vector& Camera::getFlatUp() const {
  21. return flatUp;
  22. }
  23. const Vector& Camera::getPosition() const {
  24. return position;
  25. }
  26. void Camera::update(float lag) {
  27. back = ray.getDirection(lag);
  28. right.setInverse(back).cross(0.0f, 1.0f, 0.0f).normalize();
  29. up.set(back).cross(right).normalize();
  30. flatBack.set(back).setY(0.0f).normalize();
  31. flatRight.setInverse(back).cross(0.0f, 1.0f, 0.0f).normalize();
  32. flatUp.set(0.0f, 1.0f, 0.0f);
  33. position = ray.getPosition(lag);
  34. }