diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-11-16 00:07:48 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-11-16 00:07:48 +0000 |
commit | b7fadd730a78671a0eaf55c36df24c04661ef2c3 (patch) | |
tree | a9d5bce62b3c6e42008d7e0f637665aa97b73764 /lib | |
parent | Don't write null value for pointers (diff) | |
download | ilt-b7fadd730a78671a0eaf55c36df24c04661ef2c3.tar.bz2 ilt-b7fadd730a78671a0eaf55c36df24c04661ef2c3.tar.xz ilt-b7fadd730a78671a0eaf55c36df24c04661ef2c3.zip |
Swap y,z axis
This was a pain... but all the coords make much more sense now and a lot of mystery negation has disappeared.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/maths.cpp | 18 | ||||
-rw-r--r-- | lib/maths.h | 18 |
2 files changed, 19 insertions, 17 deletions
diff --git a/lib/maths.cpp b/lib/maths.cpp index 0298363..e894d02 100644 --- a/lib/maths.cpp +++ b/lib/maths.cpp @@ -9,7 +9,7 @@ glm::mat4 flat_orientation(const glm::vec3 & diff) { static const auto oneeighty {glm::rotate(pi, up)}; - const auto flatdiff {glm::normalize(glm::vec3 {diff.x, 0, diff.z})}; + const auto flatdiff {glm::normalize(!!diff)}; auto e {glm::orientation(flatdiff, north)}; // Handle if diff is exactly opposite to north return (std::isnan(e[0][0])) ? oneeighty : e; @@ -42,16 +42,16 @@ rotate_flat(float a) return rotation<glm::mat2>(a, {0, 0}, {0, 1}, {1, 1}, {1, 0}); } -// Create a roll transformation matrix +// Create a yaw transformation matrix glm::mat4 -rotate_roll(float a) +rotate_yaw(float a) { - return rotation<glm::mat4>(a, {0, 0}, {0, 1}, {1, 1}, {1, 0}); + return rotation<glm::mat4>(a, {0, 0}, {1, 0}, {1, 1}, {0, 1}); } -// Create a yaw transformation matrix +// Create a roll transformation matrix glm::mat4 -rotate_yaw(float a) +rotate_roll(float a) { return rotation<glm::mat4>(a, {0, 0}, {2, 0}, {2, 2}, {0, 2}); } @@ -63,7 +63,7 @@ rotate_pitch(float a) return rotation<glm::mat4>(a, {1, 1}, {1, 2}, {2, 2}, {2, 1}); } -// Create a bomcined yaw, pitch, roll transformation matrix +// Create a combined yaw, pitch, roll transformation matrix glm::mat4 rotate_ypr(glm::vec3 a) { @@ -73,13 +73,13 @@ rotate_ypr(glm::vec3 a) float vector_yaw(const glm::vec3 & diff) { - return std::atan2(diff.x, diff.z); + return std::atan2(diff.x, diff.y); } float vector_pitch(const glm::vec3 & diff) { - return std::atan(diff.y); + return std::atan(diff.z); } float diff --git a/lib/maths.h b/lib/maths.h index c02123a..285c69a 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -18,11 +18,13 @@ struct Arc : public std::pair<float, float> { } }; -constexpr const glm::vec3 up {0, 1, 0}; -constexpr const glm::vec3 north {0, 0, 1}; -constexpr const glm::vec3 south {0, 0, -1}; -constexpr const glm::vec3 east {-1, 0, 0}; -constexpr const glm::vec3 west {1, 0, 0}; +constexpr const glm::vec3 origin {0, 0, 0}; +constexpr const glm::vec3 up {0, 0, 1}; +constexpr const glm::vec3 down {0, 0, -1}; +constexpr const glm::vec3 north {0, 1, 0}; +constexpr const glm::vec3 south {0, -1, 0}; +constexpr const glm::vec3 east {1, 0, 0}; +constexpr const glm::vec3 west {-1, 0, 0}; constexpr auto half_pi {glm::half_pi<float>()}; constexpr auto quarter_pi {half_pi / 2}; constexpr auto pi {glm::pi<float>()}; @@ -73,13 +75,13 @@ rdiv(Ta a, Tb b) constexpr inline glm::vec2 operator!(const glm::vec3 & v) { - return {v.x, v.z}; + return {v.x, v.y}; } constexpr inline glm::vec3 -operator^(const glm::vec2 & v, float y) +operator^(const glm::vec2 & v, float z) { - return {v.x, y, v.y}; + return {v.x, v.y, z}; } constexpr inline glm::vec3 |