diff --git a/include/omath/engines/iw_engine/formulas.hpp b/include/omath/engines/iw_engine/formulas.hpp index a604f48..1a27554 100644 --- a/include/omath/engines/iw_engine/formulas.hpp +++ b/include/omath/engines/iw_engine/formulas.hpp @@ -16,6 +16,9 @@ namespace omath::iw_engine [[nodiscard]] Vector3 UpVector(const ViewAngles& angles); + [[nodiscard]] + Mat4x4 RotationMatrix(const ViewAngles& angles); + [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin); diff --git a/include/omath/engines/source_engine/formulas.hpp b/include/omath/engines/source_engine/formulas.hpp index 817ee14..450de1e 100644 --- a/include/omath/engines/source_engine/formulas.hpp +++ b/include/omath/engines/source_engine/formulas.hpp @@ -12,7 +12,6 @@ namespace omath::source_engine [[nodiscard]] Mat4x4 RotationMatrix(const ViewAngles& angles); - [[nodiscard]] Vector3 RightVector(const ViewAngles& angles); @@ -21,9 +20,6 @@ namespace omath::source_engine [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin); - [[nodiscard]] Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); - - } // namespace omath::source diff --git a/include/omath/engines/unity_engine/formulas.hpp b/include/omath/engines/unity_engine/formulas.hpp index 6352cd1..8b36953 100644 --- a/include/omath/engines/unity_engine/formulas.hpp +++ b/include/omath/engines/unity_engine/formulas.hpp @@ -18,6 +18,8 @@ namespace omath::unity_engine [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin); + [[nodiscard]] + Mat4x4 RotationMatrix(const ViewAngles& angles); [[nodiscard]] Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); diff --git a/include/omath/mat.hpp b/include/omath/mat.hpp index 68f867f..1d7b451 100644 --- a/include/omath/mat.hpp +++ b/include/omath/mat.hpp @@ -428,13 +428,6 @@ namespace omath } * MatTranslation(-cameraOrigin); } - template - [[nodiscard]] - Mat<4, 4, Type, St> MatRotation(const ViewAngles& angles) noexcept - { - return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll); - } - template [[nodiscard]] Mat<4, 4, Type, St> MatPerspectiveLeftHanded(const float fieldOfView, const float aspectRatio, const float near, diff --git a/source/engines/iw_engine/formulas.cpp b/source/engines/iw_engine/formulas.cpp index f4fe076..0c293fe 100644 --- a/source/engines/iw_engine/formulas.cpp +++ b/source/engines/iw_engine/formulas.cpp @@ -9,23 +9,27 @@ namespace omath::iw_engine Vector3 ForwardVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsForward); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } Vector3 RightVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsRight); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } Vector3 UpVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsUp); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } + Mat4x4 RotationMatrix(const ViewAngles& angles) + { + return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll); + } Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin) { diff --git a/source/engines/unity_engine/formulas.cpp b/source/engines/unity_engine/formulas.cpp index d3a872f..798920d 100644 --- a/source/engines/unity_engine/formulas.cpp +++ b/source/engines/unity_engine/formulas.cpp @@ -9,19 +9,19 @@ namespace omath::unity_engine { Vector3 ForwardVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsForward); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } Vector3 RightVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsRight); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } Vector3 UpVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsUp); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } @@ -30,6 +30,12 @@ namespace omath::unity_engine return MatCameraView(ForwardVector(angles), -RightVector(angles), UpVector(angles), cam_origin); } + Mat4x4 RotationMatrix(const ViewAngles& angles) + { + return MatRotationAxisZ(angles.roll) * + MatRotationAxisY(angles.yaw) * + MatRotationAxisX(angles.pitch); + } Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, const float far) { diff --git a/tests/engines/unit_test_open_gl.cpp b/tests/engines/unit_test_open_gl.cpp index a107533..66c86c8 100644 --- a/tests/engines/unit_test_open_gl.cpp +++ b/tests/engines/unit_test_open_gl.cpp @@ -16,7 +16,7 @@ TEST(UnitTestOpenGL, ForwardVector) std::print("{}\n", angles.pitch.AsDegrees()); const auto forward2 = omath::opengl_engine::ForwardVector(angles); - std::println("{} {} {}", forward2.x, (int)forward2.y, forward2.z); + std::println("{} {} {}", forward2.x, (int)forward2.y, (int)forward2.z); EXPECT_EQ(forward, omath::opengl_engine::kAbsForward); }