1 #ifndef BLANK_WORLD_WORLDCOLLISION_HPP_
2 #define BLANK_WORLD_WORLDCOLLISION_HPP_
4 #include "BlockType.hpp"
12 struct WorldCollision {
21 : chunk(nullptr), block(-1), depth(0.0f), normal(0.0f) { }
22 WorldCollision(Chunk *c, int b, float d, const glm::vec3 &n)
23 : chunk(c), block(b), depth(d), normal(n) { }
25 /// check if an actual collision
26 operator bool() const noexcept { return chunk; }
28 // following only valid if test true
29 Chunk &GetChunk() noexcept { return *chunk; }
30 const Chunk &GetChunk() const noexcept { return *chunk; }
31 const Block &GetBlock() const noexcept { return GetChunk().BlockAt(block); }
32 const BlockType &GetType() const noexcept { return GetChunk().Type(GetBlock()); }
34 void SetBlock(const Block &b) noexcept { GetChunk().SetBlock(block, b); }
36 bool Blocks() const noexcept { return chunk->Type(block).collide_block; }
38 glm::vec3 BlockPos() const noexcept { return Chunk::ToPos(block); }
39 glm::vec3 BlockCoords() const noexcept { return Chunk::ToCoords(block); }
40 glm::mat4 BlockTransform() const noexcept { return GetChunk().ToTransform(BlockPos(), block); }