View.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "math/View.h"
  2. void 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 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 Matrix& 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. Vector3 View::getUp() const {
  24. return up;
  25. }
  26. Vector3 View::getDown() const {
  27. return -up;
  28. }
  29. Vector3 View::getLeft() const {
  30. return -right;
  31. }
  32. Vector3 View::getRight() const {
  33. return right;
  34. }
  35. Vector3 View::getFront() const {
  36. return -back;
  37. }
  38. Vector3 View::getBack() const {
  39. return back;
  40. }