]> git.localhorst.tv Git - blank.git/blob - src/model/CollisionBounds.hpp
e43b0d82e66e69ae624cbfbfbbba9e540ea8f770
[blank.git] / src / model / CollisionBounds.hpp
1 #ifndef BLANK_MODEL_COLLISIONBOUNDS_HPP_
2 #define BLANK_MODEL_COLLISIONBOUNDS_HPP_
3
4 #include "../graphics/PrimitiveMesh.hpp"
5
6 #include <glm/glm.hpp>
7
8
9 namespace blank {
10
11 class AABB;
12 class Ray;
13
14 struct CollisionBounds {
15
16         /// the number of vertices this shape's outline has
17         std::size_t OutlineCount() const { return out_pos.size(); }
18         /// the number of vertex indices this shape's outline has
19         std::size_t OutlineIndexCount() const { return out_idx.size(); }
20
21         /// fill given buffers with these bounds' outline's elements
22         void Outline(PrimitiveMesh::Buffer &out) const;
23
24         /// Check if given ray would pass though this shape if it were
25         /// transformed with given matrix.
26         /// If true, dist and normal hold the intersection distance and
27         /// normal, otherwise their content is undefined.
28         virtual bool Intersects(
29                 const Ray &,
30                 const glm::mat4 &,
31                 float &dist,
32                 glm::vec3 &normal
33         ) const noexcept = 0;
34
35         /// Check for intersection with given OBB.
36         /// The OBB is defined by box and box_M, M is applied to the shape.
37         virtual bool Intersects(
38                 const glm::mat4 &M,
39                 const AABB &box,
40                 const glm::mat4 &box_M,
41                 float &depth,
42                 glm::vec3 &normal
43         ) const noexcept = 0;
44
45 protected:
46         void SetOutline(
47                 const PrimitiveMesh::Positions &pos,
48                 const PrimitiveMesh::Indices &idx);
49
50 private:
51         PrimitiveMesh::Positions out_pos;
52         PrimitiveMesh::Indices out_idx;
53
54 };
55
56 }
57
58 #endif