]> git.localhorst.tv Git - blank.git/blob - src/world/WorldCollision.hpp
65cba9de58f5140b664dc2fbbd7e80fed8717957
[blank.git] / src / world / WorldCollision.hpp
1 #ifndef BLANK_WORLD_WORLDCOLLISION_HPP_
2 #define BLANK_WORLD_WORLDCOLLISION_HPP_
3
4 #include "BlockType.hpp"
5 #include "Chunk.hpp"
6
7 #include <glm/glm.hpp>
8
9
10 namespace blank {
11
12 struct WorldCollision {
13
14         Chunk *chunk;
15         int block;
16
17         float depth;
18         glm::vec3 normal;
19
20         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) { }
24
25         /// check if an actual collision
26         operator bool() const noexcept { return chunk; }
27
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()); }
33
34         void SetBlock(const Block &b) noexcept { GetChunk().SetBlock(block, b); }
35
36         bool Blocks() const noexcept { return chunk->Type(block).collide_block; }
37
38         const ExactLocation::Coarse &ChunkPos() const noexcept { return GetChunk().Position(); }
39
40         RoughLocation::Fine BlockPos() const noexcept { return Chunk::ToPos(block); }
41         ExactLocation::Fine BlockCoords() const noexcept { return Chunk::ToCoords(block); }
42         glm::mat4 BlockTransform() const noexcept { return GetChunk().ToTransform(BlockPos(), block); }
43
44 };
45
46 }
47
48 #endif