]> git.localhorst.tv Git - blank.git/blob - src/geometry/primitive.hpp
split geometry lib
[blank.git] / src / geometry / primitive.hpp
1 #ifndef BLANK_GEOMETRY_PRIMITIVE_HPP_
2 #define BLANK_GEOMETRY_PRIMITIVE_HPP_
3
4 #include <algorithm>
5 #include <glm/glm.hpp>
6
7
8 namespace blank {
9
10 struct AABB {
11         glm::vec3 min;
12         glm::vec3 max;
13
14         void Adjust() noexcept {
15                 if (max.x < min.x) std::swap(max.x, min.x);
16                 if (max.y < min.y) std::swap(max.y, min.y);
17                 if (max.z < min.z) std::swap(max.z, min.z);
18         }
19
20         glm::vec3 Center() const noexcept {
21                 return min + (max - min) * 0.5f;
22         }
23 };
24
25 struct Ray {
26         glm::vec3 orig;
27         glm::vec3 dir;
28 };
29
30 bool Intersection(
31         const Ray &,
32         const AABB &,
33         const glm::mat4 &M,
34         float *dist = nullptr,
35         glm::vec3 *normal = nullptr) noexcept;
36
37 bool Intersection(
38         const AABB &a_box,
39         const glm::mat4 &a_m,
40         const AABB &b_box,
41         const glm::mat4 &b_m,
42         float &depth,
43         glm::vec3 &normal) noexcept;
44
45 bool CullTest(const AABB &box, const glm::mat4 &MVP) noexcept;
46
47 }
48
49 #endif