]> git.localhorst.tv Git - blank.git/blob - src/geometry.hpp
df75f22bf66720d31c6b4d4e0c08b83cb7fb312d
[blank.git] / src / geometry.hpp
1 #ifndef BLANK_GEOMETRY_H_
2 #define BLANK_GEOMETRY_H_
3
4 #include <algorithm>
5 #include <glm/glm.hpp>
6
7
8 namespace blank {
9
10 constexpr float PI = 3.141592653589793238462643383279502884;
11 constexpr float PI_0p25 = PI * 0.25f;
12 constexpr float PI_0p5 = PI * 0.5f;
13 constexpr float PI_1p5 = PI * 1.5f;
14 constexpr float PI_2p0 = PI * 2.0f;
15
16 struct AABB {
17         glm::vec3 min;
18         glm::vec3 max;
19
20         void Adjust() noexcept {
21                 if (max.x < min.x) std::swap(max.x, min.x);
22                 if (max.y < min.y) std::swap(max.y, min.y);
23                 if (max.z < min.z) std::swap(max.z, min.z);
24         }
25 };
26
27 struct Ray {
28         glm::vec3 orig;
29         glm::vec3 dir;
30 };
31
32 bool Intersection(
33         const Ray &,
34         const AABB &,
35         const glm::mat4 &M,
36         float *dist = nullptr,
37         glm::vec3 *normal = nullptr) noexcept;
38
39 bool CullTest(const AABB &box, const glm::mat4 &MVP) noexcept;
40
41 }
42
43 #endif