1 #ifndef BLANK_SHAPE_HPP_
2 #define BLANK_SHAPE_HPP_
4 #include "geometry.hpp"
15 /// the number of vertices (and normals) this shape has
16 size_t VertexCount() const { return vtx_pos.size(); }
17 /// the number of vertex indices this shape has
18 size_t VertexIndexCount() const { return vtx_idx.size(); }
20 const Model::Normal &VertexNormal(size_t idx) const { return vtx_nrm[idx]; }
21 Model::Normal VertexNormal(
22 size_t idx, const glm::mat4 &transform
24 return Model::Normal(transform * glm::vec4(vtx_nrm[idx], 0.0f));
27 /// fill given buffers with this shape's elements with an
28 /// optional transform and offset
30 Model::Positions &vertex,
31 Model::Normals &normal,
35 Model::Positions &vertex,
36 Model::Normals &normal,
37 Model::Indices &index,
38 const glm::mat4 &transform,
39 Model::Index idx_offset = 0
42 BlockModel::Positions &vertex,
43 BlockModel::Indices &index,
44 const glm::mat4 &transform,
45 BlockModel::Index idx_offset = 0
48 /// the number of vertices this shape's outline has
49 size_t OutlineCount() const { return out_pos.size(); }
50 /// the number of vertex indices this shape's outline has
51 size_t OutlineIndexCount() const { return out_idx.size(); }
53 /// fill given buffers with this shape's outline's elements with
54 /// an optional offset
56 OutlineModel::Positions &vertex,
57 OutlineModel::Indices &index,
58 const OutlineModel::Position &offset = { 0.0f, 0.0f, 0.0f },
59 OutlineModel::Index idx_offset = 0
62 /// Check if given ray would pass though this shape if it were
63 /// transformed with given matrix.
64 /// If true, dist and normal hold the intersection distance and
65 /// normal, otherwise their content is undefined.
66 virtual bool Intersects(
74 void SetShape(const Model::Positions &pos, const Model::Normals &nrm, const Model::Indices &idx) {
79 void SetOutline(const OutlineModel::Positions &pos, const OutlineModel::Indices &idx) {
85 Model::Positions vtx_pos;
86 Model::Normals vtx_nrm;
87 Model::Indices vtx_idx;
89 OutlineModel::Positions out_pos;
90 OutlineModel::Indices out_idx;
101 bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const override;
110 CuboidShape(const AABB &bounds);
112 bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const override;
124 StairShape(const AABB &bounds, const glm::vec2 &clip);
126 bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const override;