MCPcopy Create free account
hub / github.com/BoomingTech/Piccolo / makeViewMatrix

Method makeViewMatrix

engine/source/runtime/core/math/math.cpp:77–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 3

toRotationMatrixMethod · 0.80
setMatrix3x3Method · 0.80
transposeMethod · 0.45

Tested by

no test coverage detected