diff --git a/include/omath/engines/opengl_engine/constants.hpp b/include/omath/engines/opengl_engine/constants.hpp index 66aac7d..3e0a762 100644 --- a/include/omath/engines/opengl_engine/constants.hpp +++ b/include/omath/engines/opengl_engine/constants.hpp @@ -17,9 +17,10 @@ namespace omath::opengl_engine using Mat4x4 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>; using Mat3x3 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>; using Mat1x3 = Mat<1, 3, float, MatStoreType::COLUMN_MAJOR>; - using PitchAngle = Angle; - using YawAngle = Angle; - using RollAngle = Angle; + using PitchAngle = Angle; + using YawAngle = Angle; + using RollAngle = Angle; + using ViewAngles = omath::ViewAngles; } \ No newline at end of file diff --git a/include/omath/engines/unity_engine/constants.hpp b/include/omath/engines/unity_engine/constants.hpp index dae1775..27ec9a3 100644 --- a/include/omath/engines/unity_engine/constants.hpp +++ b/include/omath/engines/unity_engine/constants.hpp @@ -18,7 +18,7 @@ namespace omath::unity_engine using Mat4x4 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>; using Mat3x3 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>; using Mat1x3 = Mat<1, 3, float, MatStoreType::ROW_MAJOR>; - using PitchAngle = Angle; + using PitchAngle = Angle; using YawAngle = Angle; using RollAngle = Angle; diff --git a/source/engines/opengl_engine/formulas.cpp b/source/engines/opengl_engine/formulas.cpp index 3bd7e47..6265225 100644 --- a/source/engines/opengl_engine/formulas.cpp +++ b/source/engines/opengl_engine/formulas.cpp @@ -34,7 +34,7 @@ namespace omath::opengl_engine { return MatRotationAxisZ(angles.roll) * MatRotationAxisY(angles.yaw) * - MatRotationAxisX(angles.pitch); + 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 66c86c8..cab6465 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, (int)forward2.z); + std::println("OpenGL {} {} {}", std::round(forward2.x), std::round(forward2.y), std::round(forward2.z)); EXPECT_EQ(forward, omath::opengl_engine::kAbsForward); } diff --git a/tests/engines/unit_test_source_engine.cpp b/tests/engines/unit_test_source_engine.cpp index 529e69d..c129249 100644 --- a/tests/engines/unit_test_source_engine.cpp +++ b/tests/engines/unit_test_source_engine.cpp @@ -10,11 +10,6 @@ TEST(UnitTestSourceEngine, ForwardVector) { const auto forward = omath::source_engine::ForwardVector({}); - omath::source_engine::ViewAngles angles; - //angles.pitch = omath::source_engine::PitchAngle::FromDegrees(-90); - const auto forward2 = omath::source_engine::ForwardVector(angles); - - //std::println("{} {} {}", forward2.x, forward2.y, forward2.z); EXPECT_EQ(forward, omath::source_engine::kAbsForward); } diff --git a/tests/engines/unit_test_unity_engine.cpp b/tests/engines/unit_test_unity_engine.cpp index 2e0daaa..7fb95a2 100644 --- a/tests/engines/unit_test_unity_engine.cpp +++ b/tests/engines/unit_test_unity_engine.cpp @@ -14,6 +14,42 @@ TEST(UnitTestUnityEngine, ForwardVector) EXPECT_EQ(forward, omath::unity_engine::kAbsForward); } +TEST(UnitTestUnityEngine, ForwardVectorRotationYaw) +{ + omath::unity_engine::ViewAngles angles; + + angles.yaw = omath::unity_engine::YawAngle::FromDegrees(90.f); + + const auto forward = omath::unity_engine::ForwardVector(angles); + EXPECT_NEAR(forward.x, omath::unity_engine::kAbsRight.x, 0.00001f); + EXPECT_NEAR(forward.y, omath::unity_engine::kAbsRight.y, 0.00001f); + EXPECT_NEAR(forward.z, omath::unity_engine::kAbsRight.z, 0.00001f); +} + +TEST(UnitTestUnityEngine, ForwardVectorRotationPitch) +{ + omath::unity_engine::ViewAngles angles; + + angles.pitch = omath::unity_engine::PitchAngle::FromDegrees(-90.f); + + const auto forward = omath::unity_engine::ForwardVector(angles); + EXPECT_NEAR(forward.x, omath::unity_engine::kAbsUp.x, 0.00001f); + EXPECT_NEAR(forward.y, omath::unity_engine::kAbsUp.y, 0.00001f); + EXPECT_NEAR(forward.z, omath::unity_engine::kAbsUp.z, 0.00001f); +} + +TEST(UnitTestUnityEngine, ForwardVectorRotationRoll) +{ + omath::unity_engine::ViewAngles angles; + + angles.roll = omath::unity_engine::RollAngle::FromDegrees(-90.f); + + const auto forward = omath::unity_engine::UpVector(angles); + EXPECT_NEAR(forward.x, omath::unity_engine::kAbsRight.x, 0.00001f); + EXPECT_NEAR(forward.y, omath::unity_engine::kAbsRight.y, 0.00001f); + EXPECT_NEAR(forward.z, omath::unity_engine::kAbsRight.z, 0.00001f); +} + TEST(UnitTestUnityEngine, RightVector) { const auto right = omath::unity_engine::RightVector({});