raylib-cpp
C++ object-oriented wrapper library for raylib.
BoundingBox.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
26 #define RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
27 
28 #include "./raylib.hpp"
29 #include "./raylib-cpp-utils.hpp"
30 
31 namespace raylib {
35 class BoundingBox : public ::BoundingBox {
36  public:
37  BoundingBox(const ::BoundingBox& box) {
38  set(box);
39  }
40 
44  BoundingBox(const ::Mesh& mesh) {
45  set(::MeshBoundingBox(mesh));
46  }
47 
48  BoundingBox(::Vector3 Min, ::Vector3 Max) {
49  min = Min;
50  max = Max;
51  }
52 
53  GETTERSETTER(::Vector3, Min, min)
54  GETTERSETTER(::Vector3, Max, max)
55 
56  BoundingBox& operator=(const ::BoundingBox& box) {
57  set(box);
58  return *this;
59  }
60 
64  inline BoundingBox& Draw(::Color color = {255, 255, 255, 255}) {
65  DrawBoundingBox(*this, color);
66  return *this;
67  }
68 
72  inline bool CheckCollision(const ::BoundingBox& box2) const {
73  return CheckCollisionBoxes(*this, box2);
74  }
75 
79  inline bool CheckCollision(::Vector3 center, float radius) const {
80  return CheckCollisionBoxSphere(*this, center, radius);
81  }
82 
86  inline bool CheckCollision(const ::Ray& ray) const {
87  return CheckCollisionRayBox(ray, *this);
88  }
89 
90  protected:
91  inline void set(const ::BoundingBox& box) {
92  min = box.min;
93  max = box.max;
94  }
95 };
96 } // namespace raylib
97 
98 #endif // RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::BoundingBox::BoundingBox
BoundingBox(const ::Mesh &mesh)
Compute mesh bounding box limits.
Definition: BoundingBox.hpp:44
raylib::BoundingBox::Draw
BoundingBox & Draw(::Color color={255, 255, 255, 255})
Draw a bounding box with wires.
Definition: BoundingBox.hpp:64
raylib::Vector3
Definition: Vector3.hpp:37
raylib::BoundingBox::set
void set(const ::BoundingBox &box)
Definition: BoundingBox.hpp:91
raylib::BoundingBox::CheckCollision
bool CheckCollision(::Vector3 center, float radius) const
Detect collision between box and sphere.
Definition: BoundingBox.hpp:79
raylib::BoundingBox::CheckCollision
bool CheckCollision(const ::BoundingBox &box2) const
Detect collision between two boxes.
Definition: BoundingBox.hpp:72
raylib::Color
Definition: Color.hpp:35
raylib::BoundingBox::BoundingBox
BoundingBox(::Vector3 Min, ::Vector3 Max)
Definition: BoundingBox.hpp:48
raylib::BoundingBox
Bounding box type.
Definition: BoundingBox.hpp:35
raylib::BoundingBox::CheckCollision
bool CheckCollision(const ::Ray &ray) const
Detect collision between ray and bounding box.
Definition: BoundingBox.hpp:86
raylib::BoundingBox::BoundingBox
BoundingBox(const ::BoundingBox &box)
Definition: BoundingBox.hpp:37