X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FWorldCollision.hpp;h=8b0f5a17b89ce72e3ebe76ccf036ec2b29387830;hb=b3c37033944671429f8db22c3754caef7add1695;hp=eb2e5e2871a334bfe02e1bd0be24a5c48572af98;hpb=32909aa3224ec0ed5656721178eb6ad31cd047df;p=blank.git diff --git a/src/world/WorldCollision.hpp b/src/world/WorldCollision.hpp index eb2e5e2..8b0f5a1 100644 --- a/src/world/WorldCollision.hpp +++ b/src/world/WorldCollision.hpp @@ -1,24 +1,45 @@ #ifndef BLANK_WORLD_WORLDCOLLISION_HPP_ #define BLANK_WORLD_WORLDCOLLISION_HPP_ -#include +#include "BlockType.hpp" +#include "Chunk.hpp" +#include "../graphics/glm.hpp" namespace blank { -class Chunk; - 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; } + + 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); } + }; }