X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FChunk.hpp;fp=src%2Fworld%2FChunk.hpp;h=d0dcf9404219ba063f91fb9b2e5dced933df40e9;hb=7354c74fb8f409336db3a6d70455fbc10232ae64;hp=4938c1b1a7a92f3f34c861e30287ca23491c6686;hpb=c1c0d8c3c10a25002adccf7a977f05a57c4aa3a0;p=blank.git diff --git a/src/world/Chunk.hpp b/src/world/Chunk.hpp index 4938c1b..d0dcf94 100644 --- a/src/world/Chunk.hpp +++ b/src/world/Chunk.hpp @@ -69,7 +69,11 @@ public: (idx / (side * side)) ); } - glm::mat4 ToTransform(const RoughLocation::Fine &pos, int idx) const noexcept; + /// get a chunk-local transform for block at given position and index + /// (position and index are redundant) + glm::mat4 ToTransform(const RoughLocation::Fine &position, int index) const noexcept; + /// same as above, but also apply offset to given reference + glm::mat4 ToTransform(const ExactLocation::Coarse &ref, const RoughLocation::Fine &pos, int idx) const noexcept; ExactLocation::Fine ToSceneCoords(const ExactLocation::Coarse &base, const ExactLocation::Fine &pos) const noexcept { return ExactLocation::Fine((position - base) * ExactLocation::Extent()) + pos; @@ -130,15 +134,17 @@ public: bool Intersection( const Ray &ray, - const glm::mat4 &M, + const ExactLocation::Coarse &reference, float &dist ) const noexcept { - return blank::Intersection(ray, Bounds(), M, &dist); + return blank::Intersection(ray, Bounds(), Transform(reference), &dist); } + /// check if given ray intersects any block of this chunk + /// given reference indicated the chunk offset of the ray in world space bool Intersection( const Ray &, - const glm::mat4 &M, + const ExactLocation::Coarse &reference, WorldCollision &) noexcept; bool Intersection( @@ -155,6 +161,7 @@ public: void Position(const ExactLocation::Coarse &pos) noexcept { position = pos; } const ExactLocation::Coarse &Position() const noexcept { return position; } + glm::mat4 Transform(const ExactLocation::Coarse &offset) const noexcept { return glm::translate((position - offset) * ExactLocation::Extent()); }