1 #ifndef BLANK_WORLD_WORLDCOLLISION_HPP_
2 #define BLANK_WORLD_WORLDCOLLISION_HPP_
4 #include "BlockType.hpp"
6 #include "../graphics/glm.hpp"
11 struct WorldCollision {
20 : chunk(nullptr), block(-1), depth(0.0f), normal(0.0f) { }
21 WorldCollision(Chunk *c, int b, float d, const glm::vec3 &n)
22 : chunk(c), block(b), depth(d), normal(n) { }
24 /// check if an actual collision
25 operator bool() const noexcept { return chunk; }
27 // following only valid if test true
28 Chunk &GetChunk() noexcept { return *chunk; }
29 const Chunk &GetChunk() const noexcept { return *chunk; }
30 const Block &GetBlock() const noexcept { return GetChunk().BlockAt(block); }
31 const BlockType &GetType() const noexcept { return GetChunk().Type(GetBlock()); }
33 void SetBlock(const Block &b) noexcept { GetChunk().SetBlock(block, b); }
35 bool Blocks() const noexcept { return chunk->Type(block).collide_block; }
37 const ExactLocation::Coarse &ChunkPos() const noexcept { return GetChunk().Position(); }
39 RoughLocation::Fine BlockPos() const noexcept { return Chunk::ToPos(block); }
40 ExactLocation::Fine BlockCoords() const noexcept { return Chunk::ToCoords(block); }
41 glm::mat4 BlockTransform() const noexcept { return GetChunk().ToTransform(BlockPos(), block); }