diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-12-11 20:49:52 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-12-11 20:49:52 +0000 |
commit | 04f42212ba67ec7d8160bf4a19c0b1283aec69bc (patch) | |
tree | df623be62e89a80a9ea75f069b331b625be890a6 | |
parent | Integer camera (diff) | |
download | ilt-04f42212ba67ec7d8160bf4a19c0b1283aec69bc.tar.bz2 ilt-04f42212ba67ec7d8160bf4a19c0b1283aec69bc.tar.xz ilt-04f42212ba67ec7d8160bf4a19c0b1283aec69bc.zip |
Fix clamping to seafloor and add specific test
-rw-r--r-- | gfx/gl/camera.cpp | 6 | ||||
-rw-r--r-- | test/test-render.cpp | 12 |
2 files changed, 15 insertions, 3 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index a0d76ab..ff4c91e 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -41,9 +41,9 @@ Camera::extentsAtDist(const GlobalDistance dist) const const auto clampToSeaFloor = [this, dist](GlobalPosition3D target) -> GlobalPosition4D { target += position; if (target.z < -1500) { - const auto diff = (target - position); - const auto something = (-1500 - position.z) / diff.z; - return {position + diff * something, dist}; + const auto diff = target - position; + const auto limit = -1500 - position.z; + return {position + (limit * diff) / diff.z, (limit * dist) / diff.z}; } return {target, dist}; }; diff --git a/test/test-render.cpp b/test/test-render.cpp index 22da73b..37bacdd 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -82,6 +82,18 @@ BOOST_DATA_TEST_CASE(cam, BOOST_CHECK_CLOSE_VECI(e[3], pos + GlobalPosition4D(dist, dist, dist, dist)); } +BOOST_AUTO_TEST_CASE(camSeaFloor) +{ + const Camera cam {{100, 200, 300}, half_pi, 1.F, 100, 2000}; + + const auto e = cam.extentsAtDist(2000); + + BOOST_CHECK_CLOSE_VECI(e[0], GlobalPosition4D(-1700, 2000, -1500, 1800)); + BOOST_CHECK_CLOSE_VECI(e[1], GlobalPosition4D(-1900, 2200, 2300, 2000)); + BOOST_CHECK_CLOSE_VECI(e[2], GlobalPosition4D(1900, 2000, -1500, 1800)); + BOOST_CHECK_CLOSE_VECI(e[3], GlobalPosition4D(2100, 2200, 2300, 2000)); +} + BOOST_FIXTURE_TEST_SUITE(w, TestRenderOutput); BOOST_AUTO_TEST_CASE(basic) |