1 #ifndef BLANK_MODEL_GEOMETRY_H_
2 #define BLANK_MODEL_GEOMETRY_H_
11 constexpr float PI = 3.141592653589793238462643383279502884;
12 constexpr float PI_0p25 = PI * 0.25f;
13 constexpr float PI_0p5 = PI * 0.5f;
14 constexpr float PI_1p5 = PI * 1.5f;
15 constexpr float PI_2p0 = PI * 2.0f;
17 constexpr float PI_inv = 1.0f / PI;
18 constexpr float PI_0p5_inv = 1.0f / PI_0p5;
20 constexpr float DEG_RAD_FACTOR = PI / 180.0f;
21 constexpr float RAD_DEG_FACTOR = 180.0f / PI;
23 constexpr float deg2rad(float d) {
24 return d * DEG_RAD_FACTOR;
27 constexpr float rad2deg(float r) {
28 return r * RAD_DEG_FACTOR;
33 inline bool iszero(const T &v) {
34 return dot(v, v) < std::numeric_limits<typename T::value_type>::epsilon();
39 T manhattan_distance(const glm::tvec3<T> &a, const glm::tvec3<T> &b) {
40 glm::tvec3<T> diff(abs(a - b));
41 return diff.x + diff.y + diff.z;
45 T manhattan_radius(const glm::tvec3<T> &v) {
46 glm::tvec3<T> a(abs(v));
47 return std::max(a.x, std::max(a.y, a.z));
55 void Adjust() noexcept {
56 if (max.x < min.x) std::swap(max.x, min.x);
57 if (max.y < min.y) std::swap(max.y, min.y);
58 if (max.z < min.z) std::swap(max.z, min.z);
61 glm::vec3 Center() const noexcept {
62 return min + (max - min) * 0.5f;
75 float *dist = nullptr,
76 glm::vec3 *normal = nullptr) noexcept;
84 glm::vec3 &normal) noexcept;
86 bool CullTest(const AABB &box, const glm::mat4 &MVP) noexcept;