mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
improved openg gl rotation matrix, added tests
This commit is contained in:
@@ -33,7 +33,7 @@ namespace omath::opengl_engine
|
|||||||
Mat4x4 RotationMatrix(const ViewAngles& angles)
|
Mat4x4 RotationMatrix(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
return MatRotationAxisZ<float, MatStoreType::COLUMN_MAJOR>(angles.roll) *
|
return MatRotationAxisZ<float, MatStoreType::COLUMN_MAJOR>(angles.roll) *
|
||||||
MatRotationAxisY<float, MatStoreType::COLUMN_MAJOR>(angles.yaw) *
|
MatRotationAxisY<float, MatStoreType::COLUMN_MAJOR>(-angles.yaw) *
|
||||||
MatRotationAxisX<float, MatStoreType::COLUMN_MAJOR>(-angles.pitch);
|
MatRotationAxisX<float, MatStoreType::COLUMN_MAJOR>(-angles.pitch);
|
||||||
}
|
}
|
||||||
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
|
|||||||
@@ -27,6 +27,42 @@ TEST(UnitTestIwEngine, UpVector)
|
|||||||
EXPECT_EQ(up, omath::iw_engine::kAbsUp);
|
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)
|
TEST(UnitTestIwEngine, ProjectTargetMovedFromCamera)
|
||||||
{
|
{
|
||||||
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
||||||
|
|||||||
@@ -10,20 +10,12 @@
|
|||||||
TEST(UnitTestOpenGL, ForwardVector)
|
TEST(UnitTestOpenGL, ForwardVector)
|
||||||
{
|
{
|
||||||
const auto forward = omath::opengl_engine::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);
|
EXPECT_EQ(forward, omath::opengl_engine::kAbsForward);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UnitTestOpenGL, RightVector)
|
TEST(UnitTestOpenGL, RightVector)
|
||||||
{
|
{
|
||||||
const auto right = omath::opengl_engine::RightVector({});
|
const auto right = omath::opengl_engine::RightVector({});
|
||||||
|
|
||||||
EXPECT_EQ(right, omath::opengl_engine::kAbsRight);
|
EXPECT_EQ(right, omath::opengl_engine::kAbsRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +25,44 @@ TEST(UnitTestOpenGL, UpVector)
|
|||||||
EXPECT_EQ(up, omath::opengl_engine::kAbsUp);
|
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)
|
TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera)
|
||||||
{
|
{
|
||||||
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
||||||
|
|||||||
Reference in New Issue
Block a user