]> git.localhorst.tv Git - blank.git/blobdiff - src/world/WorldCollision.hpp
glm backwards compatibility
[blank.git] / src / world / WorldCollision.hpp
index ebf01c17cd0362bfda3f1ba15f674367b8205bc2..8b0f5a17b89ce72e3ebe76ccf036ec2b29387830 100644 (file)
@@ -3,26 +3,42 @@
 
 #include "BlockType.hpp"
 #include "Chunk.hpp"
-
-#include <glm/glm.hpp>
+#include "../graphics/glm.hpp"
 
 
 namespace blank {
 
 struct WorldCollision {
 
-       const Chunk *chunk;
+       Chunk *chunk;
        int block;
 
        float depth;
        glm::vec3 normal;
 
-       WorldCollision(const Chunk *c, int b, float d, const glm::vec3 &n)
+       WorldCollision()
+       : chunk(nullptr), block(-1), depth(0.0f), normal(0.0f) { }
+       WorldCollision(Chunk *c, int b, float d, const glm::vec3 &n)
        : chunk(c), block(b), depth(d), normal(n) { }
 
+       /// check if an actual collision
+       operator bool() const noexcept { return chunk; }
+
+       // following only valid if test true
+       Chunk &GetChunk() noexcept { return *chunk; }
+       const Chunk &GetChunk() const noexcept { return *chunk; }
+       const Block &GetBlock() const noexcept { return GetChunk().BlockAt(block); }
+       const BlockType &GetType() const noexcept { return GetChunk().Type(GetBlock()); }
+
+       void SetBlock(const Block &b) noexcept { GetChunk().SetBlock(block, b); }
+
        bool Blocks() const noexcept { return chunk->Type(block).collide_block; }
 
-       glm::vec3 BlockCoords() const noexcept { return Chunk::ToCoords(block); }
+       const ExactLocation::Coarse &ChunkPos() const noexcept { return GetChunk().Position(); }
+
+       RoughLocation::Fine BlockPos() const noexcept { return Chunk::ToPos(block); }
+       ExactLocation::Fine BlockCoords() const noexcept { return Chunk::ToCoords(block); }
+       glm::mat4 BlockTransform() const noexcept { return GetChunk().ToTransform(BlockPos(), block); }
 
 };