raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
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#include "./RayCollision.hpp"
7
8namespace raylib {
12class BoundingBox : public ::BoundingBox {
13 public:
14 /*
15 * Copy a bounding box from another bounding box.
16 */
17 BoundingBox(const ::BoundingBox& box) : ::BoundingBox{box.min, box.max} {
18 // Nothing.
19 }
20
24 BoundingBox(const ::Mesh& mesh) {
25 set(::GetMeshBoundingBox(mesh));
26 }
27
28 BoundingBox(::Vector3 minMax = ::Vector3{0.0f, 0.0f, 0.0f}) : ::BoundingBox{minMax, minMax} {}
29 BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {}
30
31 GETTERSETTER(::Vector3, Min, min)
32 GETTERSETTER(::Vector3, Max, max)
33
34 BoundingBox& operator=(const ::BoundingBox& box) {
35 set(box);
36 return *this;
37 }
38
42 void Draw(::Color color = {255, 255, 255, 255}) const {
43 ::DrawBoundingBox(*this, color);
44 }
45
49 bool CheckCollision(const ::BoundingBox& box2) const {
50 return CheckCollisionBoxes(*this, box2);
51 }
52
56 bool CheckCollision(::Vector3 center, float radius) const {
57 return CheckCollisionBoxSphere(*this, center, radius);
58 }
59
63 bool CheckCollision(const ::Ray& ray) const {
64 return GetRayCollisionBox(ray, *this).hit;
65 }
66
70 RayCollision GetCollision(const ::Ray& ray) const {
71 return GetRayCollisionBox(ray, *this);
72 }
73
74 protected:
75 void set(const ::BoundingBox& box) {
76 min = box.min;
77 max = box.max;
78 }
79 void set(const ::Vector3& _min, const ::Vector3& _max) {
80 min = _min;
81 max = _max;
82 }
83};
84} // namespace raylib
85
87
88#endif // RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
Bounding box type.
Definition: BoundingBox.hpp:12
bool CheckCollision(::Vector3 center, float radius) const
Detect collision between box and sphere.
Definition: BoundingBox.hpp:56
RayCollision GetCollision(const ::Ray &ray) const
Get collision information between ray and bounding box.
Definition: BoundingBox.hpp:70
BoundingBox(const ::Mesh &mesh)
Compute mesh bounding box limits.
Definition: BoundingBox.hpp:24
void Draw(::Color color={255, 255, 255, 255}) const
Draw a bounding box with wires.
Definition: BoundingBox.hpp:42
bool CheckCollision(const ::BoundingBox &box2) const
Detect collision between two boxes.
Definition: BoundingBox.hpp:49
bool CheckCollision(const ::Ray &ray) const
Detect collision between ray and bounding box.
Definition: BoundingBox.hpp:63
Raycast hit information.
Vector3 type.
Definition: Vector3.hpp:19