mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
Fixes incorrect NDC calculation and updates formulas
Corrects the NDC calculation in `world_to_screen` to improve accuracy. Replaces custom perspective projection matrix calculation with `omath::mat_perspective_right_handed` for correctness and consistency. Updates test cases and provides debugging information by printing view and projection matrices. Addresses an issue in the feature/ndc_invalid_calc_fix branch.
This commit is contained in:
@@ -87,9 +87,9 @@ TEST(unit_test_unity_engine, Project)
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
const auto proj = cam.world_to_screen({5.f, 3, 10.f});
|
||||
const auto proj = cam.world_to_screen({10.f, 3, 10.f});
|
||||
|
||||
EXPECT_NEAR(proj->x, 951.769f, 0.001f);
|
||||
EXPECT_NEAR(proj->x, 1263.538, 0.001f);
|
||||
EXPECT_NEAR(proj->y, 547.061f, 0.001f);
|
||||
}
|
||||
|
||||
@@ -233,4 +233,19 @@ TEST(unit_test_unity_engine, loook_at_random_z_axis)
|
||||
failed_points++;
|
||||
}
|
||||
EXPECT_LE(failed_points, 100);
|
||||
}
|
||||
|
||||
TEST(unit_test_unity_engine, to_camera_coordiante_syste)
|
||||
{
|
||||
omath::Vector3<float> point = {10, 3, 10};
|
||||
auto result = omath::unity_engine::calc_view_matrix({}, {}) * omath::mat_column_from_vector(point);
|
||||
auto perspective = omath::unity_engine::calc_perspective_projection_matrix(60, 1280 / 720.f, 0.3, 1000);
|
||||
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
std::println("View matrix: \n{}", cam.get_view_matrix());
|
||||
std::println("Projection: \n{}", cam.get_projection_matrix());
|
||||
std::print("NDC: projection {} -> {}", point, cam.world_to_screen(point).value());
|
||||
}
|
||||
Reference in New Issue
Block a user