]> git.localhorst.tv Git - blank.git/blobdiff - src/geometry/primitive.hpp
faster ray/box test for AABBs
[blank.git] / src / geometry / primitive.hpp
index da4c37f1e03296d254d55f051d5e199f94132a9c..72da84749140ca6f2d6b2c71a069c3fd9c031199 100644 (file)
@@ -31,13 +31,29 @@ struct AABB {
 
 std::ostream &operator <<(std::ostream &, const AABB &);
 
+// TODO: this should really use setters/getters for dir and inv_dir so
+//       manipulating code doesn't "forget" to call Update()
 struct Ray {
        glm::vec3 orig;
        glm::vec3 dir;
+
+       glm::vec3 inv_dir;
+
+       void Update() noexcept {
+               inv_dir = 1.0f / dir;
+       }
 };
 
 std::ostream &operator <<(std::ostream &, const Ray &);
 
+/// axis aligned boolean ray/box intersection test
+/// if true, dist constains distance from ray's origin to intersection point
+bool Intersection(
+       const Ray &,
+       const AABB &,
+       float &dist) noexcept;
+
+/// detailed oriented ray/box intersection test
 bool Intersection(
        const Ray &,
        const AABB &,