diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-14 13:42:10 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-14 13:42:10 +0000 |
commit | 7481957415ecc581b7dfd2453b0e61058e2ac0c6 (patch) | |
tree | 204a23b7a7c3e495ace5209303dc32aa2fbe122f | |
parent | Rename flat_angle to vector_yaw (diff) | |
download | ilt-7481957415ecc581b7dfd2453b0e61058e2ac0c6.tar.bz2 ilt-7481957415ecc581b7dfd2453b0e61058e2ac0c6.tar.xz ilt-7481957415ecc581b7dfd2453b0e61058e2ac0c6.zip |
Add vector pitch
-rw-r--r-- | test/test-maths.cpp | 22 | ||||
-rw-r--r-- | utility/maths.cpp | 6 | ||||
-rw-r--r-- | utility/maths.h | 1 |
3 files changed, 29 insertions, 0 deletions
diff --git a/test/test-maths.cpp b/test/test-maths.cpp index ba1bc7b..6187c46 100644 --- a/test/test-maths.cpp +++ b/test/test-maths.cpp @@ -17,6 +17,28 @@ BOOST_DATA_TEST_CASE(test_vector_yaw, BOOST_CHECK_CLOSE(vector_yaw(v), a, 1.F); } +BOOST_DATA_TEST_CASE(test_vector_pitch, + boost::unit_test::data::make<vecter_to_angle>({ + {north, 0}, + {east, 0}, + {south, 0}, + {west, 0}, + {north + up, quarter_pi}, + {east + up, quarter_pi}, + {south + up, quarter_pi}, + {west + up, quarter_pi}, + {north - up, -quarter_pi}, + {east - up, -quarter_pi}, + {south - up, -quarter_pi}, + {west - up, -quarter_pi}, + {north + west - up, -quarter_pi}, + {north + west + up, quarter_pi}, + }), + v, a) +{ + BOOST_CHECK_CLOSE(vector_pitch(v), a, 1.F); +} + using normalize_angle = std::tuple<float, float>; BOOST_DATA_TEST_CASE(test_angle_normalize, boost::unit_test::data::make<normalize_angle>({ diff --git a/utility/maths.cpp b/utility/maths.cpp index aa44220..fb14a17 100644 --- a/utility/maths.cpp +++ b/utility/maths.cpp @@ -22,6 +22,12 @@ vector_yaw(const glm::vec3 & diff) } float +vector_pitch(const glm::vec3 & diff) +{ + return std::atan(diff.y); +} + +float round_frac(const float & v, const float & frac) { return std::round(v / frac) * frac; diff --git a/utility/maths.h b/utility/maths.h index b8dd342..f2114ef 100644 --- a/utility/maths.h +++ b/utility/maths.h @@ -29,6 +29,7 @@ constexpr auto two_pi {glm::two_pi<float>()}; glm::mat4 flat_orientation(const glm::vec3 & diff); float vector_yaw(const glm::vec3 & diff); +float vector_pitch(const glm::vec3 & diff); float round_frac(const float & v, const float & frac); |