improved openg gl rotation matrix, added tests

This commit is contained in:
2025-04-16 19:11:02 +03:00
parent 127bae0b78
commit 0069b8bd96
3 changed files with 75 additions and 9 deletions

View File

@@ -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);

View File

@@ -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);