From 1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Wed, 12 Feb 2025 18:05:18 +1100 Subject: initial commit --- src/shared/math.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/shared/math.cc (limited to 'src/shared/math.cc') diff --git a/src/shared/math.cc b/src/shared/math.cc new file mode 100644 index 0000000..80eba81 --- /dev/null +++ b/src/shared/math.cc @@ -0,0 +1,23 @@ +#include "shared/math.hh" + +namespace shared { +namespace math { + +glm::vec3 angle_to_dir(const angles& ang) noexcept { + const float x = std::cos(ang.pitch) * std::cos(ang.yaw); + const float y = std::sin(ang.pitch); + const float z = std::cos(ang.pitch) * std::sin(ang.yaw); + return {x, y, z}; +} + +bool is_inside_draw(const coords& a, const coords& b, + const std::int32_t draw_distance) noexcept { + const auto x2 = (a.x - b.x) * (a.x - b.x); + const auto z2 = (a.z - b.z) * (a.z - b.z); + const auto dd2 = draw_distance * draw_distance; + + return (x2 < dd2 - z2) && (z2 < dd2 - x2); +} + +} // namespace math +} // namespace shared -- cgit v1.2.3