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-cpp-utils.hpp"
5#include "./RayCollision.hpp"
6
7namespace raylib {
11class BoundingBox : public ::BoundingBox {
12public:
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) { set(::GetMeshBoundingBox(mesh)); }
24
25 BoundingBox(::Vector3 minMax = ::Vector3{0.0f, 0.0f, 0.0f}) : ::BoundingBox{minMax, minMax} {}
26 BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {}
27
28 GETTERSETTER(::Vector3, Min, min)
29 GETTERSETTER(::Vector3, Max, max)
30
31 BoundingBox& operator=(const ::BoundingBox& box) {
32 set(box);
33 return *this;
34 }
35
39 void Draw(::Color color = {255, 255, 255, 255}) const { ::DrawBoundingBox(*this, color); }
40
44 [[nodiscard]] bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }
45
49 [[nodiscard]] bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }
50
54 [[nodiscard]] bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }
55
59 RayCollision GetCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this); }
60protected:
61 void set(const ::BoundingBox& box) {
62 min = box.min;
63 max = box.max;
64 }
65 void set(const ::Vector3& _min, const ::Vector3& _max) {
66 min = _min;
67 max = _max;
68 }
69};
70} // namespace raylib
71
73
74#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:49
RayCollision GetCollision(const ::Ray &ray) const
Get collision information between ray and bounding box.
Definition: BoundingBox.hpp:59
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:39
bool CheckCollision(const ::BoundingBox &box2) const
Detect collision between two boxes.
Definition: BoundingBox.hpp:44
bool CheckCollision(const ::Ray &ray) const
Detect collision between ray and bounding box.
Definition: BoundingBox.hpp:54
Raycast hit information.
Vector3 type.
Definition: Vector3.hpp:20
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8