Antkeeper  0.0.1
box-collider.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_PHYSICS_BOX_COLLIDER_HPP
21 #define ANTKEEPER_PHYSICS_BOX_COLLIDER_HPP
22 
25 
26 namespace physics {
27 
31 class box_collider: public collider
32 {
33 public:
36 
37  [[nodiscard]] inline constexpr collider_type type() const noexcept override
38  {
39  return collider_type::box;
40  }
41 
47  inline constexpr explicit box_collider(const box_type& box) noexcept:
48  m_box{box}
49  {}
50 
58  inline constexpr box_collider(const math::fvec3& min, const math::fvec3& max) noexcept:
59  m_box{min, max}
60  {}
61  constexpr box_collider() noexcept = default;
63 
69  inline constexpr void set_box(const box_type& box) noexcept
70  {
71  m_box = box;
72  }
73 
79  inline constexpr void set_min(const math::fvec3& min) noexcept
80  {
81  m_box.min = min;
82  }
83 
89  inline constexpr void set_max(const math::fvec3& max) noexcept
90  {
91  m_box.max = max;
92  }
93 
95  [[nodiscard]] inline constexpr const box_type& get_box() const noexcept
96  {
97  return m_box;
98  }
99 
101  [[nodiscard]] inline constexpr const math::fvec3& get_min() const noexcept
102  {
103  return m_box.min;
104  }
105 
107  [[nodiscard]] inline constexpr const math::fvec3& get_max() const noexcept
108  {
109  return m_box.max;
110  }
111 
112 private:
113  box_type m_box{};
114 };
115 
116 } // namespace physics
117 
118 #endif // ANTKEEPER_PHYSICS_BOX_COLLIDER_HPP
Box collision object.
constexpr void set_box(const box_type &box) noexcept
Sets the collider's box.
constexpr const box_type & get_box() const noexcept
Returns the box shape.
constexpr box_collider(const box_type &box) noexcept
Constructs a box collider from a box.
geom::box< float > box_type
Box type.
constexpr const math::fvec3 & get_max() const noexcept
Returns the maximum extent of the box, in object space.
constexpr void set_max(const math::fvec3 &max) noexcept
Sets the maximum extent of the box.
constexpr const math::fvec3 & get_min() const noexcept
Returns the minimum extent of the box, in object space.
constexpr box_collider() noexcept=default
Constructs a box collider.
constexpr void set_min(const math::fvec3 &min) noexcept
Sets the minimum extent of the box.
constexpr box_collider(const math::fvec3 &min, const math::fvec3 &max) noexcept
Constructs a box collider.
constexpr collider_type type() const noexcept override
Returns the collider type.
Abstract base class for collision objects.
Definition: collider.hpp:34
Physics.
Definition: constants.hpp:23
collider_type
Collider types.
@ box
Box collider.
n-dimensional axis-aligned rectangle.
vector_type min
Minimum extent of the hyperrectangle.
vector_type max
Maximum extent of the hyperrectangle.
n-dimensional vector.
Definition: vector.hpp:44