diff options
Diffstat (limited to 'test/test-maths.cpp')
-rw-r--r-- | test/test-maths.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/test-maths.cpp b/test/test-maths.cpp index edc3e60..86cb7b8 100644 --- a/test/test-maths.cpp +++ b/test/test-maths.cpp @@ -9,6 +9,7 @@ #include <type_traits> #include <game/network/link.h> +#include <gfx/gl/camera.h> #include <glm/glm.hpp> #include <maths.h> #include <tuple> @@ -250,3 +251,38 @@ BOOST_DATA_TEST_CASE(curve1, } } } + +BOOST_AUTO_TEST_CASE(camera_clicks) +{ + Camera camera {{0, 0, 0}, ::half_pi, 1.25F, .1F, 10000.F}; + constexpr float centre {0.5F}, right {0.9F}, left {0.1F}, top {1.F}, bottom {0.F}; + camera.forward = ::north; + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, centre}), ::north); + BOOST_CHECK_CLOSE_VEC(camera.unProject({left, centre}), glm::normalize(::north + ::west)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({right, centre}), glm::normalize(::north + ::east)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, top}), glm::normalize(::north + ::up)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, bottom}), glm::normalize(::north + ::down)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({left, top}), glm::normalize(::north + ::west + ::up)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({right, top}), glm::normalize(::north + ::east + ::up)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({left, bottom}), glm::normalize(::north + ::west + ::down)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({right, bottom}), glm::normalize(::north + ::east + ::down)); + + camera.forward = ::east; + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, centre}), ::east); + BOOST_CHECK_CLOSE_VEC(camera.unProject({left, centre}), glm::normalize(::north + ::east)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({right, centre}), glm::normalize(::south + ::east)); + + camera.forward = glm::normalize(::north + ::down); + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, centre}), glm::normalize(::north + ::down)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, top}), glm::normalize(::north)); + + camera.forward = glm::normalize(::north + ::west + ::down); + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, centre}), glm::normalize(::north + ::west + ::down)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, top}), glm::normalize(::north + ::west + ::up * 0.2F)); + + camera.forward = glm::normalize(::north + ::west); + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, centre}), glm::normalize(::north + ::west)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({centre, top}), glm::normalize(::north + ::west + ::up * 1.2F)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({right, centre}), glm::normalize(::north)); + BOOST_CHECK_CLOSE_VEC(camera.unProject({left, centre}), glm::normalize(::west)); +} |