@@ -10,58 +10,49 @@ namespace omath::source
1010 [[nodiscard]]
1111 inline Vector3 ForwardVector (const ViewAngles& angles)
1212 {
13- const auto vec = RotationMat (angles) * MatColumnFromVector (kAbsForward );
13+ const auto vec = MatRotation (angles) * MatColumnFromVector (kAbsForward );
1414
1515 return {vec.At (0 , 0 ), vec.At (1 , 0 ), vec.At (2 , 0 )};
1616 }
1717
1818 [[nodiscard]]
1919 inline Vector3 RightVector (const ViewAngles& angles)
2020 {
21- const auto vec = RotationMat (angles) * MatColumnFromVector (kAbsRight );
21+ const auto vec = MatRotation (angles) * MatColumnFromVector (kAbsRight );
2222
2323 return {vec.At (0 , 0 ), vec.At (1 , 0 ), vec.At (2 , 0 )};
2424 }
2525
2626 [[nodiscard]]
2727 inline Vector3 UpVector (const ViewAngles& angles)
2828 {
29- const auto vec = RotationMat (angles) * MatColumnFromVector (kAbsUp );
29+ const auto vec = MatRotation (angles) * MatColumnFromVector (kAbsUp );
3030
3131 return {vec.At (0 , 0 ), vec.At (1 , 0 ), vec.At (2 , 0 )};
3232 }
3333
34- [[nodiscard]]
35- constexpr Mat4x4 ViewMatrixFromVecs (const Vector3& forward, const Vector3& right, const Vector3& up,
36- const Vector3& camera_pos)
34+ [[nodiscard]] inline Mat4x4 CalcViewMatrix (const ViewAngles& angles, const Vector3& cam_origin)
3735 {
38- return Mat4x4{
39- {right.x , right.y , right.z , 0 },
40- {-up.x , -up.y , -up.z , 0 },
41- {forward.x , forward.y , forward.z , 0 },
42- {0 , 0 , 0 , 1 },
43- } *
44- MatTranslation<float , MatStoreType::ROW_MAJOR>(-camera_pos);
45- }
46-
47- [[nodiscard]] inline Mat4x4 ViewMatrix (const ViewAngles& angles, const Vector3& cam_origin)
48- {
49- return ViewMatrixFromVecs (ForwardVector (angles), RightVector (angles), UpVector (angles), cam_origin);
36+ return MatCameraView (ForwardVector (angles), RightVector (angles), UpVector (angles), cam_origin);
5037 }
5138
5239
5340 [[nodiscard]]
54- inline Mat4x4 PerspectiveProjectionMatrix (const float fieldOfView, const float aspectRatio, const float near, const float far)
41+ inline Mat4x4 CalcPerspectiveProjectionMatrix (const float fieldOfView, const float aspectRatio, const float near,
42+ const float far)
5543 {
44+ // NOTE: Needed tp make thing draw normal, since source is wierd
45+ // and use tricky projection matrix formula.
5646 constexpr auto kMultiplyFactor = 0 .75f ;
5747
5848 const float fovHalfTan = std::tan (angles::DegreesToRadians (fieldOfView) / 2 .f ) * kMultiplyFactor ;
5949
6050 return {
61- {1 .f / (aspectRatio * fovHalfTan), 0 , 0 , 0 },
62- {0 , 1 .f / (fovHalfTan), 0 , 0 },
63- {0 , 0 , (far + near) / (far - near), -(2 .f * far * near) / (far - near)},
64- {0 , 0 , 1 , 0 },
65- };
51+ {1 .f / (aspectRatio * fovHalfTan), 0 , 0 , 0 },
52+ {0 , 1 .f / (fovHalfTan), 0 , 0 },
53+ {0 , 0 , (far + near) / (far - near), -(2 .f * far * near) / (far - near)},
54+ {0 , 0 , 1 , 0 },
55+
56+ };
6657 }
6758} // namespace omath::source
0 commit comments