]> git.localhorst.tv Git - blank.git/blob - src/geometry.hpp
use light levels for shading of blocks
[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_0p5 = PI * 0.5f;
12 constexpr float PI_1p5 = PI * 1.5f;
13 constexpr float PI_2p0 = PI * 2.0f;
14
15 struct AABB {
16         glm::vec3 min;
17         glm::vec3 max;
18
19         void Adjust() {
20                 if (max.x < min.x) std::swap(max.x, min.x);
21                 if (max.y < min.y) std::swap(max.y, min.y);
22                 if (max.z < min.z) std::swap(max.z, min.z);
23         }
24 };
25
26 struct Ray {
27         glm::vec3 orig;
28         glm::vec3 dir;
29 };
30
31 bool Intersection(
32         const Ray &,
33         const AABB &,
34         const glm::mat4 &M,
35         float *dist = nullptr,
36         glm::vec3 *normal = nullptr);
37
38 bool CullTest(const AABB &box, const glm::mat4 &MVP);
39
40 }
41
42 #endif