]> git.localhorst.tv Git - blank.git/blob - src/world/WorldCollision.hpp
glm backwards compatibility
[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 #include "../graphics/glm.hpp"
7
8
9 namespace blank {
10
11 struct WorldCollision {
12
13         Chunk *chunk;
14         int block;
15
16         float depth;
17         glm::vec3 normal;
18
19         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) { }
23
24         /// check if an actual collision
25         operator bool() const noexcept { return chunk; }
26
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()); }
32
33         void SetBlock(const Block &b) noexcept { GetChunk().SetBlock(block, b); }
34
35         bool Blocks() const noexcept { return chunk->Type(block).collide_block; }
36
37         const ExactLocation::Coarse &ChunkPos() const noexcept { return GetChunk().Position(); }
38
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); }
42
43 };
44
45 }
46
47 #endif