| 75 | } |
| 76 | |
| 77 | Matrix4x4 |
| 78 | Math::makeViewMatrix(const Vector3& position, const Quaternion& orientation, const Matrix4x4* reflect_matrix) |
| 79 | { |
| 80 | Matrix4x4 viewMatrix; |
| 81 | |
| 82 | // View matrix is: |
| 83 | // |
| 84 | // [ Lx Uy Dz Tx ] |
| 85 | // [ Lx Uy Dz Ty ] |
| 86 | // [ Lx Uy Dz Tz ] |
| 87 | // [ 0 0 0 1 ] |
| 88 | // |
| 89 | // Where T = -(Transposed(Rot) * Pos) |
| 90 | |
| 91 | // This is most efficiently done using 3x3 Matrices |
| 92 | Matrix3x3 rot; |
| 93 | orientation.toRotationMatrix(rot); |
| 94 | |
| 95 | // Make the translation relative to new axes |
| 96 | Matrix3x3 rotT = rot.transpose(); |
| 97 | Vector3 trans = -rotT * position; |
| 98 | |
| 99 | // Make final matrix |
| 100 | viewMatrix = Matrix4x4::IDENTITY; |
| 101 | viewMatrix.setMatrix3x3(rotT); // fills upper 3x3 |
| 102 | viewMatrix[0][3] = trans.x; |
| 103 | viewMatrix[1][3] = trans.y; |
| 104 | viewMatrix[2][3] = trans.z; |
| 105 | |
| 106 | // Deal with reflections |
| 107 | if (reflect_matrix) |
| 108 | { |
| 109 | viewMatrix = viewMatrix * (*reflect_matrix); |
| 110 | } |
| 111 | |
| 112 | return viewMatrix; |
| 113 | } |
| 114 | |
| 115 | Matrix4x4 Math::makeLookAtMatrix(const Vector3& eye_position, const Vector3& target_position, const Vector3& up_dir) |
| 116 | { |
nothing calls this directly
no test coverage detected