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.hh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/shared/math.hh (limited to 'src/shared/math.hh') diff --git a/src/shared/math.hh b/src/shared/math.hh new file mode 100644 index 0000000..5f03ab4 --- /dev/null +++ b/src/shared/math.hh @@ -0,0 +1,53 @@ +#ifndef SHARED_MATH_HH_ +#define SHARED_MATH_HH_ + +#include + +#include +#include +#include + +namespace shared { +namespace math { + +// 2D coordinates. +struct coords { + std::int32_t x; + std::int32_t z; + coords operator+(const coords& c) const noexcept { + auto ret = *this; + ret.x += c.x; + ret.z += c.z; + return ret; + } + coords operator-(const coords& c) const noexcept { + auto ret = *this; + ret.x -= c.x; + ret.z -= c.z; + return ret; + } + auto operator<=>(const coords& c) const noexcept = default; +}; + +struct angles { + float pitch; + float yaw; + angles operator+(const angles& a) const noexcept { + auto ret = *this; + ret.pitch += a.pitch; + ret.yaw += a.yaw; + return ret; + } +}; + +// Returns a vector pointing in the direction of pitch + yaw. +glm::vec3 angle_to_dir(const angles& ang) noexcept; + +bool is_inside_draw(const shared::math::coords& a, + const shared::math::coords& b, + const std::int32_t draw_distance) noexcept; + +} // namespace math +} // namespace shared + +#endif -- cgit v1.2.3