diff --git a/source/engines/opengl_engine/formulas.cpp b/source/engines/opengl_engine/formulas.cpp index 6265225..f3e5b5c 100644 --- a/source/engines/opengl_engine/formulas.cpp +++ b/source/engines/opengl_engine/formulas.cpp @@ -33,7 +33,7 @@ namespace omath::opengl_engine Mat4x4 RotationMatrix(const ViewAngles& angles) { return MatRotationAxisZ(angles.roll) * - MatRotationAxisY(angles.yaw) * + MatRotationAxisY(-angles.yaw) * MatRotationAxisX(-angles.pitch); } Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, diff --git a/tests/engines/unit_test_iw_engine.cpp b/tests/engines/unit_test_iw_engine.cpp index 679af03..86b7d0b 100644 --- a/tests/engines/unit_test_iw_engine.cpp +++ b/tests/engines/unit_test_iw_engine.cpp @@ -27,6 +27,42 @@ TEST(UnitTestIwEngine, UpVector) EXPECT_EQ(up, omath::iw_engine::kAbsUp); } +TEST(UnitTestIwEngine, ForwardVectorRotationYaw) +{ + omath::iw_engine::ViewAngles angles; + + angles.yaw = omath::iw_engine::YawAngle::FromDegrees(-90.f); + + const auto forward = omath::iw_engine::ForwardVector(angles); + EXPECT_NEAR(forward.x, omath::iw_engine::kAbsRight.x, 0.00001f); + EXPECT_NEAR(forward.y, omath::iw_engine::kAbsRight.y, 0.00001f); + EXPECT_NEAR(forward.z, omath::iw_engine::kAbsRight.z, 0.00001f); +} + +TEST(UnitTestIwEngine, ForwardVectorRotationPitch) +{ + omath::iw_engine::ViewAngles angles; + + angles.pitch = omath::iw_engine::PitchAngle::FromDegrees(-89.f); + + const auto forward = omath::iw_engine::ForwardVector(angles); + EXPECT_NEAR(forward.x, omath::iw_engine::kAbsUp.x, 0.02f); + EXPECT_NEAR(forward.y, omath::iw_engine::kAbsUp.y, 0.01f); + EXPECT_NEAR(forward.z, omath::iw_engine::kAbsUp.z, 0.01f); +} + +TEST(UnitTestIwEngine, ForwardVectorRotationRoll) +{ + omath::iw_engine::ViewAngles angles; + + angles.roll = omath::iw_engine::RollAngle::FromDegrees(90.f); + + const auto forward = omath::iw_engine::UpVector(angles); + EXPECT_NEAR(forward.x, omath::iw_engine::kAbsRight.x, 0.00001f); + EXPECT_NEAR(forward.y, omath::iw_engine::kAbsRight.y, 0.00001f); + EXPECT_NEAR(forward.z, omath::iw_engine::kAbsRight.z, 0.00001f); +} + TEST(UnitTestIwEngine, ProjectTargetMovedFromCamera) { constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f); diff --git a/tests/engines/unit_test_open_gl.cpp b/tests/engines/unit_test_open_gl.cpp index cab6465..170b306 100644 --- a/tests/engines/unit_test_open_gl.cpp +++ b/tests/engines/unit_test_open_gl.cpp @@ -10,20 +10,12 @@ TEST(UnitTestOpenGL, ForwardVector) { const auto forward = omath::opengl_engine::ForwardVector({}); - omath::opengl_engine::ViewAngles angles = {}; - angles.pitch = omath::opengl_engine::PitchAngle::FromDegrees(90); - - std::print("{}\n", angles.pitch.AsDegrees()); - const auto forward2 = omath::opengl_engine::ForwardVector(angles); - - std::println("OpenGL {} {} {}", std::round(forward2.x), std::round(forward2.y), std::round(forward2.z)); EXPECT_EQ(forward, omath::opengl_engine::kAbsForward); } TEST(UnitTestOpenGL, RightVector) { const auto right = omath::opengl_engine::RightVector({}); - EXPECT_EQ(right, omath::opengl_engine::kAbsRight); } @@ -33,6 +25,44 @@ TEST(UnitTestOpenGL, UpVector) EXPECT_EQ(up, omath::opengl_engine::kAbsUp); } +TEST(UnitTestOpenGL, ForwardVectorRotationYaw) +{ + omath::opengl_engine::ViewAngles angles; + + angles.yaw = omath::opengl_engine::YawAngle::FromDegrees(90.f); + + const auto forward = omath::opengl_engine::ForwardVector(angles); + EXPECT_NEAR(forward.x, omath::opengl_engine::kAbsRight.x, 0.00001f); + EXPECT_NEAR(forward.y, omath::opengl_engine::kAbsRight.y, 0.00001f); + EXPECT_NEAR(forward.z, omath::opengl_engine::kAbsRight.z, 0.00001f); +} + + + +TEST(UnitTestOpenGL, ForwardVectorRotationPitch) +{ + omath::opengl_engine::ViewAngles angles; + + angles.pitch = omath::opengl_engine::PitchAngle::FromDegrees(-90.f); + + const auto forward = omath::opengl_engine::ForwardVector(angles); + EXPECT_NEAR(forward.x, omath::opengl_engine::kAbsUp.x, 0.00001f); + EXPECT_NEAR(forward.y, omath::opengl_engine::kAbsUp.y, 0.00001f); + EXPECT_NEAR(forward.z, omath::opengl_engine::kAbsUp.z, 0.00001f); +} + +TEST(UnitTestOpenGL, ForwardVectorRotationRoll) +{ + omath::opengl_engine::ViewAngles angles; + + angles.roll = omath::opengl_engine::RollAngle::FromDegrees(-90.f); + + const auto forward = omath::opengl_engine::UpVector(angles); + EXPECT_NEAR(forward.x, omath::opengl_engine::kAbsRight.x, 0.00001f); + EXPECT_NEAR(forward.y, omath::opengl_engine::kAbsRight.y, 0.00001f); + EXPECT_NEAR(forward.z, omath::opengl_engine::kAbsRight.z, 0.00001f); +} + TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera) { constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);