blob: 5f03ab4ded39f3ad82db950412850f958e3d7dd5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#ifndef SHARED_MATH_HH_
#define SHARED_MATH_HH_
#include <compare>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
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
|