]> git.localhorst.tv Git - blank.git/blobdiff - src/model/Shape.hpp
glm backwards compatibility
[blank.git] / src / model / Shape.hpp
index 21602707b593132e6f9871beedcc98b0d6d83fab..80dc4a33ba6d28803f9de4b603e1cf83b2b00b9f 100644 (file)
@@ -1,26 +1,57 @@
 #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 "../graphics/glm.hpp"
+#include "../world/Block.hpp"
 
 #include <memory>
 #include <vector>
-#include <glm/glm.hpp>
 
 
 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<float> &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<float> &, std::size_t) noexcept;
 
@@ -45,11 +94,12 @@ private:
        struct Vertex {
                glm::vec3 position;
                glm::vec3 normal;
-               glm::vec3 tex_st;
+               glm::vec2 tex_st;
                std::size_t tex_id;
        };
        std::vector<Vertex> vertices;
        std::vector<std::size_t> indices;
+       Faces fill;
 
 };