added unit tests

This commit is contained in:
2025-04-16 18:35:50 +03:00
parent 3f6ea010dc
commit bed204a663
6 changed files with 43 additions and 11 deletions

View File

@@ -17,9 +17,10 @@ namespace omath::opengl_engine
using Mat4x4 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>; using Mat4x4 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>;
using Mat3x3 = 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 Mat1x3 = Mat<1, 3, float, MatStoreType::COLUMN_MAJOR>;
using PitchAngle = Angle<float, 0.f, 180.f, AngleFlags::Clamped>; using PitchAngle = Angle<float, -90.f, 90.f, AngleFlags::Clamped>;
using YawAngle = Angle<float, 0.f, 360.f, AngleFlags::Normalized>; using YawAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
using RollAngle = Angle<float, 0.f, 360.f, AngleFlags::Normalized>; using RollAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
using ViewAngles = omath::ViewAngles<PitchAngle, YawAngle, RollAngle>; using ViewAngles = omath::ViewAngles<PitchAngle, YawAngle, RollAngle>;
} }

View File

@@ -18,7 +18,7 @@ namespace omath::unity_engine
using Mat4x4 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>; using Mat4x4 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>;
using Mat3x3 = 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 Mat1x3 = Mat<1, 3, float, MatStoreType::ROW_MAJOR>;
using PitchAngle = Angle<float, -89.f, 89.f, AngleFlags::Clamped>; using PitchAngle = Angle<float, -90.f, 90.f, AngleFlags::Clamped>;
using YawAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>; using YawAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
using RollAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>; using RollAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;

View File

@@ -34,7 +34,7 @@ namespace omath::opengl_engine
{ {
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,
const float far) const float far)

View File

@@ -16,7 +16,7 @@ TEST(UnitTestOpenGL, ForwardVector)
std::print("{}\n", angles.pitch.AsDegrees()); std::print("{}\n", angles.pitch.AsDegrees());
const auto forward2 = omath::opengl_engine::ForwardVector(angles); 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); EXPECT_EQ(forward, omath::opengl_engine::kAbsForward);
} }

View File

@@ -10,11 +10,6 @@
TEST(UnitTestSourceEngine, ForwardVector) TEST(UnitTestSourceEngine, ForwardVector)
{ {
const auto forward = omath::source_engine::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); EXPECT_EQ(forward, omath::source_engine::kAbsForward);
} }

View File

@@ -14,6 +14,42 @@ TEST(UnitTestUnityEngine, ForwardVector)
EXPECT_EQ(forward, omath::unity_engine::kAbsForward); 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) TEST(UnitTestUnityEngine, RightVector)
{ {
const auto right = omath::unity_engine::RightVector({}); const auto right = omath::unity_engine::RightVector({});