1 #ifndef BLANK_MODEL_SHAPE_HPP_
2 #define BLANK_MODEL_SHAPE_HPP_
4 #include "BlockModel.hpp"
5 #include "EntityModel.hpp"
6 #include "OutlineModel.hpp"
19 /// the number of vertices (and normals) this shape has
20 size_t VertexCount() const noexcept { return vtx_pos.size(); }
21 /// the number of vertex indices this shape has
22 size_t VertexIndexCount() const noexcept { return vtx_idx.size(); }
24 const EntityModel::Normal &VertexNormal(size_t idx) const noexcept { return vtx_nrm[idx]; }
25 EntityModel::Normal VertexNormal(
26 size_t idx, const glm::mat4 &transform
28 return EntityModel::Normal(transform * glm::vec4(vtx_nrm[idx], 0.0f));
31 /// fill given buffers with this shape's elements with an
32 /// optional transform and offset
34 EntityModel::Positions &vertex,
35 EntityModel::Normals &normal,
36 EntityModel::Indices &index
39 EntityModel::Positions &vertex,
40 EntityModel::Normals &normal,
41 EntityModel::Indices &index,
42 const glm::mat4 &transform,
43 EntityModel::Index idx_offset = 0
46 BlockModel::Positions &vertex,
47 BlockModel::Indices &index,
48 const glm::mat4 &transform,
49 BlockModel::Index idx_offset = 0
52 /// the number of vertices this shape's outline has
53 size_t OutlineCount() const { return out_pos.size(); }
54 /// the number of vertex indices this shape's outline has
55 size_t OutlineIndexCount() const { return out_idx.size(); }
57 /// fill given buffers with this shape's outline's elements with
58 /// an optional offset
60 OutlineModel::Positions &vertex,
61 OutlineModel::Indices &index,
62 const OutlineModel::Position &offset = { 0.0f, 0.0f, 0.0f },
63 OutlineModel::Index idx_offset = 0
66 /// Check if given ray would pass though this shape if it were
67 /// transformed with given matrix.
68 /// If true, dist and normal hold the intersection distance and
69 /// normal, otherwise their content is undefined.
70 virtual bool Intersects(
77 /// Check for intersection with given OBB.
78 /// The OBB is defined by box and box_M, M is applied to the shape.
79 virtual bool Intersects(
82 const glm::mat4 &box_M,
88 void SetShape(const EntityModel::Positions &pos, const EntityModel::Normals &nrm, const EntityModel::Indices &idx) {
93 void SetOutline(const OutlineModel::Positions &pos, const OutlineModel::Indices &idx) {
99 EntityModel::Positions vtx_pos;
100 EntityModel::Normals vtx_nrm;
101 EntityModel::Indices vtx_idx;
103 OutlineModel::Positions out_pos;
104 OutlineModel::Indices out_idx;