raylib-cpp
C++ object-oriented wrapper library for raylib.
BoundingBox.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
2 #define RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
3 
4 #include "./raylib.hpp"
5 #include "./raylib-cpp-utils.hpp"
6 
7 namespace raylib {
11 class BoundingBox : public ::BoundingBox {
12  public:
13  /*
14  * Set the bounding box to default: min (0, 0, 0) and max (0, 0, 0).
15  */
16  BoundingBox() : ::BoundingBox{::Vector3{0, 0, 0}, ::Vector3{ 0, 0, 0 }} {
17  // Nothing.
18  }
19 
20  /*
21  * Copy a bounding box from another bounding box.
22  */
23  BoundingBox(const ::BoundingBox& box) : ::BoundingBox{box.min, box.max} {
24  // Nothing.
25  }
26 
30  BoundingBox(const ::Mesh& mesh) {
31  set(::GetMeshBoundingBox(mesh));
32  }
33 
34  BoundingBox(::Vector3 minMax) : ::BoundingBox{minMax, minMax} {}
35  BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {}
36 
37  GETTERSETTER(::Vector3, Min, min)
38  GETTERSETTER(::Vector3, Max, max)
39 
40  BoundingBox& operator=(const ::BoundingBox& box) {
41  set(box);
42  return *this;
43  }
44 
48  inline BoundingBox& Draw(::Color color = {255, 255, 255, 255}) {
49  DrawBoundingBox(*this, color);
50  return *this;
51  }
52 
56  inline bool CheckCollision(const ::BoundingBox& box2) const {
57  return CheckCollisionBoxes(*this, box2);
58  }
59 
63  inline bool CheckCollision(::Vector3 center, float radius) const {
64  return CheckCollisionBoxSphere(*this, center, radius);
65  }
66 
70  inline bool CheckCollision(const ::Ray& ray) const {
71  return GetRayCollisionBox(ray, *this).hit;
72  }
73 
77  inline RayCollision GetCollision(const ::Ray& ray) const {
78  return GetRayCollisionBox(ray, *this);
79  }
80 
81  private:
82  void set(const ::BoundingBox& box) {
83  min = box.min;
84  max = box.max;
85  }
86  void set(const ::Vector3& _min, const ::Vector3& _max) {
87  min = _min;
88  max = _max;
89  }
90 };
91 } // namespace raylib
93 
94 #endif // RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
Bounding box type.
Definition: BoundingBox.hpp:11
bool CheckCollision(::Vector3 center, float radius) const
Detect collision between box and sphere.
Definition: BoundingBox.hpp:63
RayCollision GetCollision(const ::Ray &ray) const
Get collision information between ray and bounding box.
Definition: BoundingBox.hpp:77
BoundingBox(const ::Mesh &mesh)
Compute mesh bounding box limits.
Definition: BoundingBox.hpp:30
BoundingBox & Draw(::Color color={255, 255, 255, 255})
Draw a bounding box with wires.
Definition: BoundingBox.hpp:48
bool CheckCollision(const ::BoundingBox &box2) const
Detect collision between two boxes.
Definition: BoundingBox.hpp:56
bool CheckCollision(const ::Ray &ray) const
Detect collision between ray and bounding box.
Definition: BoundingBox.hpp:70
Color type, RGBA (32bit)
Definition: Color.hpp:14
Raycast hit information.
Vector3 type.
Definition: Vector3.hpp:16
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8