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