Browse Source

decouple view direction update from matrix

Kajetan Johannes Hammerle 2 years ago
parent
commit
0e91517a8e
3 changed files with 9 additions and 14 deletions
  1. 4 9
      math/View.cpp
  2. 3 3
      math/View.h
  3. 2 2
      tests/ViewTests.cpp

+ 4 - 9
math/View.cpp

@@ -1,27 +1,22 @@
 #include "math/View.h"
 
-const Matrix& View::update(float lengthAngle, float widthAngle,
-                           const Vector3& pos) {
+void View::updateDirections(float lengthAngle, float widthAngle) {
     back.setAngles(lengthAngle, widthAngle);
     right = back.cross(Vector3(0.0f, 1.0f, 0.0f));
     right.normalize();
     up = right.cross(back);
     up.normalize();
     back = -back;
-
-    view.set(0, Vector4(right[0], right[1], right[2], right.dot(-pos)));
-    view.set(1, Vector4(up[0], up[1], up[2], up.dot(-pos)));
-    view.set(2, Vector4(back[0], back[1], back[2], back.dot(-pos)));
-    view.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
-    return view;
 }
 
-const Matrix& View::update(const Quaternion& q, const Vector3& pos) {
+void View::updateDirections(const Quaternion& q) {
     up = q * Vector3(0.0f, 1.0f, 0.0f);
     back = q * Vector3(-1.0f, 0.0f, 0.0f);
     right = up.cross(back);
     right.normalize();
+}
 
+const Matrix& View::updateMatrix(const Vector3& pos) {
     view.set(0, Vector4(right[0], right[1], right[2], right.dot(-pos)));
     view.set(1, Vector4(up[0], up[1], up[2], up.dot(-pos)));
     view.set(2, Vector4(back[0], back[1], back[2], back.dot(-pos)));

+ 3 - 3
math/View.h

@@ -13,9 +13,9 @@ class View final {
     Vector3 back;
 
 public:
-    const Matrix& update(float lengthAngle, float widthAngle,
-                         const Vector3& pos);
-    const Matrix& update(const Quaternion& q, const Vector3& pos);
+    void updateDirections(float lengthAngle, float widthAngle);
+    void updateDirections(const Quaternion& q);
+    const Matrix& updateMatrix(const Vector3& pos);
 
     Vector3 getUp() const;
     Vector3 getDown() const;

+ 2 - 2
tests/ViewTests.cpp

@@ -17,7 +17,7 @@ static void compareVectors(Test& test, const Vector<N, T>& wanted,
 
 static void testFromAngles(Test& test) {
     View v;
-    v.update(0.0f, 0.0f, Vector3());
+    v.updateDirections(0.0f, 0.0f);
     compareVectors(test, Vector3(0.0f, 1.0f, 0.0f), v.getUp(), "up");
     compareVectors(test, Vector3(0.0f, -1.0f, 0.0f), v.getDown(), "down");
     compareVectors(test, Vector3(0.0f, 0.0f, -1.0f), v.getLeft(), "left");
@@ -28,7 +28,7 @@ static void testFromAngles(Test& test) {
 
 static void testFromQuaternion(Test& test) {
     View v;
-    v.update(Quaternion(), Vector3());
+    v.updateDirections(Quaternion());
     compareVectors(test, Vector3(0.0f, 1.0f, 0.0f), v.getUp(), "up");
     compareVectors(test, Vector3(0.0f, -1.0f, 0.0f), v.getDown(), "down");
     compareVectors(test, Vector3(0.0f, 0.0f, -1.0f), v.getLeft(), "left");