]> git.localhorst.tv Git - blank.git/blobdiff - src/world/Chunk.hpp
improved ray/world collision a little
[blank.git] / src / world / Chunk.hpp
index 7eceb980cb62d6c66918ae9b3eb7fa587416c2c3..67794145290ea8adcbaef3dc00618f0122cb93d6 100644 (file)
@@ -35,6 +35,14 @@ public:
        static glm::vec3 Center() noexcept { return glm::vec3(8.0f); }
        static float Radius() noexcept { return 27.71281292110203669632f; /* 16 * √3 */ }
 
+       /// get bounding box relative to given reference chunk
+       AABB RelativeBounds(const ExactLocation::Coarse &ref) const noexcept {
+               AABB bounds;
+               bounds.min = (position - ref) * ExactLocation::Extent();
+               bounds.max = bounds.min + ExactLocation::FExtent();
+               return bounds;
+       }
+
        static constexpr bool InBounds(const ExactLocation::Fine &pos) noexcept {
                return
                        pos.x >= 0.0f && pos.x < fside &&
@@ -136,21 +144,24 @@ public:
        /// get gravity for one unit mass at given point
        glm::vec3 GravityAt(const ExactLocation &) const noexcept;
 
+       /// check if given ray passes this chunk at all
+       /// given reference indicates the chunk offset of the ray in world space
        bool Intersection(
                const Ray &ray,
                const ExactLocation::Coarse &reference,
                float &dist
        ) const noexcept {
-               return blank::Intersection(ray, Bounds(), Transform(reference), &dist);
+               return blank::Intersection(ray, RelativeBounds(reference), dist);
        }
 
        /// check if given ray intersects any block of this chunk
-       /// given reference indicated the chunk offset of the ray in world space
+       /// given reference indicates the chunk offset of the ray in world space
        bool Intersection(
                const Ray &,
                const ExactLocation::Coarse &reference,
                WorldCollision &) noexcept;
 
+       /// get all blocks intersecting given box
        bool Intersection(
                const AABB &box,
                const glm::mat4 &Mbox,