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  * Copy a bounding box from another bounding box.
15  */
16  BoundingBox(const ::BoundingBox& box) : ::BoundingBox{box.min, box.max} {
17  // Nothing.
18  }
19 
23  BoundingBox(const ::Mesh& mesh) {
24  set(::GetMeshBoundingBox(mesh));
25  }
26 
27  BoundingBox(::Vector3 minMax = ::Vector3{0.0f, 0.0f, 0.0f}) : ::BoundingBox{minMax, minMax} {}
28  BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {}
29 
30  GETTERSETTER(::Vector3, Min, min)
31  GETTERSETTER(::Vector3, Max, max)
32 
33  BoundingBox& operator=(const ::BoundingBox& box) {
34  set(box);
35  return *this;
36  }
37 
41  inline void Draw(::Color color = {255, 255, 255, 255}) const {
42  ::DrawBoundingBox(*this, color);
43  }
44 
48  inline bool CheckCollision(const ::BoundingBox& box2) const {
49  return CheckCollisionBoxes(*this, box2);
50  }
51 
55  inline bool CheckCollision(::Vector3 center, float radius) const {
56  return CheckCollisionBoxSphere(*this, center, radius);
57  }
58 
62  inline bool CheckCollision(const ::Ray& ray) const {
63  return GetRayCollisionBox(ray, *this).hit;
64  }
65 
69  inline RayCollision GetCollision(const ::Ray& ray) const {
70  return GetRayCollisionBox(ray, *this);
71  }
72 
73  private:
74  void set(const ::BoundingBox& box) {
75  min = box.min;
76  max = box.max;
77  }
78  void set(const ::Vector3& _min, const ::Vector3& _max) {
79  min = _min;
80  max = _max;
81  }
82 };
83 } // namespace raylib
84 
86 
87 #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:55
RayCollision GetCollision(const ::Ray &ray) const
Get collision information between ray and bounding box.
Definition: BoundingBox.hpp:69
BoundingBox(const ::Mesh &mesh)
Compute mesh bounding box limits.
Definition: BoundingBox.hpp:23
void Draw(::Color color={255, 255, 255, 255}) const
Draw a bounding box with wires.
Definition: BoundingBox.hpp:41
bool CheckCollision(const ::BoundingBox &box2) const
Detect collision between two boxes.
Definition: BoundingBox.hpp:48
bool CheckCollision(const ::Ray &ray) const
Detect collision between ray and bounding box.
Definition: BoundingBox.hpp:62
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