X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmodel%2FShape.hpp;h=fe58d017510c2cfd1e9da65b265ca52ad1145c8a;hb=e4a1425dccd0ba9b106e415dd02809f4308a85ee;hp=ac4dc8095f159e85e5eb3b7020e32895edaa903d;hpb=3a487f44c26f9bb9d1a1c831406b6497b2b3b425;p=blank.git diff --git a/src/model/Shape.hpp b/src/model/Shape.hpp index ac4dc80..fe58d01 100644 --- a/src/model/Shape.hpp +++ b/src/model/Shape.hpp @@ -1,8 +1,11 @@ #ifndef BLANK_MODEL_SHAPE_HPP_ #define BLANK_MODEL_SHAPE_HPP_ +#include "CollisionBounds.hpp" +#include "../geometry/primitive.hpp" #include "../graphics/BlockMesh.hpp" #include "../graphics/EntityMesh.hpp" +#include "../world/Block.hpp" #include #include @@ -11,16 +14,44 @@ namespace blank { -struct CollisionBounds; class TokenStreamReader; class Shape { +public: + struct Faces { + bool face[Block::FACE_COUNT]; + Faces &operator =(const Faces &other) noexcept { + for (int i = 0; i < Block::FACE_COUNT; ++i) { + face[i] = other.face[i]; + } + return *this; + } + bool operator [](Block::Face f) const noexcept { + return face[f]; + } + }; + + public: Shape(); void Read(TokenStreamReader &); + bool FaceFilled(Block::Face face) const noexcept { + return fill[face]; + } + + std::size_t VertexCount() const noexcept { return vertices.size(); } + std::size_t IndexCount() const noexcept { return indices.size(); } + + const glm::vec3 &VertexNormal(size_t idx) const noexcept { + return vertices[idx].normal; + } + glm::vec3 VertexNormal(size_t idx, const glm::mat4 &M) const noexcept { + return glm::vec3(M * glm::vec4(VertexNormal(idx), 0.0f)); + } + void Fill( EntityMesh::Buffer &, const std::vector &tex_map @@ -37,6 +68,24 @@ public: std::size_t idx_offset = 0 ) const; + size_t OutlineCount() const noexcept; + size_t OutlineIndexCount() const noexcept; + void Outline(PrimitiveMesh::Buffer &out) const; + + bool Intersects( + const Ray &, + const glm::mat4 &, + float &dist, + glm::vec3 &normal + ) const noexcept; + bool Intersects( + const glm::mat4 &M, + const AABB &box, + const glm::mat4 &box_M, + float &depth, + glm::vec3 &normal + ) const noexcept; + private: static float TexR(const std::vector &, std::size_t) noexcept; @@ -50,6 +99,7 @@ private: }; std::vector vertices; std::vector indices; + Faces fill; };