View.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "core/math/View.hpp"
  2. void Core::View::updateDirections(float lengthAngle, float widthAngle) {
  3. back.setAngles(lengthAngle, widthAngle);
  4. right = back.cross(Vector3(0.0f, 1.0f, 0.0f));
  5. right.normalize();
  6. up = right.cross(back);
  7. up.normalize();
  8. back = -back;
  9. }
  10. void Core::View::updateDirections(const Quaternion& q) {
  11. up = q * Vector3(0.0f, 1.0f, 0.0f);
  12. back = q * Vector3(-1.0f, 0.0f, 0.0f);
  13. right = up.cross(back);
  14. right.normalize();
  15. }
  16. const Core::Matrix& Core::View::updateMatrix(const Vector3& pos) {
  17. view.set(0, Vector4(right[0], right[1], right[2], right.dot(-pos)));
  18. view.set(1, Vector4(up[0], up[1], up[2], up.dot(-pos)));
  19. view.set(2, Vector4(back[0], back[1], back[2], back.dot(-pos)));
  20. view.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
  21. return view;
  22. }
  23. Core::Vector3 Core::View::getUp() const {
  24. return up;
  25. }
  26. Core::Vector3 Core::View::getDown() const {
  27. return -up;
  28. }
  29. Core::Vector3 Core::View::getLeft() const {
  30. return -right;
  31. }
  32. Core::Vector3 Core::View::getRight() const {
  33. return right;
  34. }
  35. Core::Vector3 Core::View::getFront() const {
  36. return -back;
  37. }
  38. Core::Vector3 Core::View::getBack() const {
  39. return back;
  40. }