Antkeeper  0.0.1
sphere-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_SPHERE_COLLIDER_HPP
21 #define ANTKEEPER_PHYSICS_SPHERE_COLLIDER_HPP
22 
25 
26 namespace physics {
27 
32 {
33 public:
36 
37  [[nodiscard]] inline constexpr collider_type type() const noexcept override
38  {
39  return collider_type::sphere;
40  }
41 
47  inline constexpr explicit sphere_collider(const sphere_type& sphere) noexcept:
48  m_sphere{sphere}
49  {}
50 
58  inline constexpr sphere_collider(const math::fvec3& center, float radius) noexcept:
59  m_sphere{center, radius}
60  {}
61  inline constexpr explicit sphere_collider(float radius) noexcept:
62  m_sphere{{}, radius}
63  {}
64  constexpr sphere_collider() noexcept = default;
66 
72  inline constexpr void set_sphere(const sphere_type& sphere) noexcept
73  {
74  m_sphere = sphere;
75  }
76 
82  inline constexpr void set_center(const math::fvec3& center) noexcept
83  {
84  m_sphere.center = center;
85  }
86 
92  inline constexpr void set_radius(float radius) noexcept
93  {
94  m_sphere.radius = radius;
95  }
96 
98  [[nodiscard]] inline constexpr const sphere_type& get_sphere() const noexcept
99  {
100  return m_sphere;
101  }
102 
104  [[nodiscard]] inline constexpr const math::fvec3& get_center() const noexcept
105  {
106  return m_sphere.center;
107  }
108 
110  [[nodiscard]] inline constexpr float get_radius() const noexcept
111  {
112  return m_sphere.radius;
113  }
114 
115 private:
116  sphere_type m_sphere{};
117 };
118 
119 } // namespace physics
120 
121 #endif // ANTKEEPER_PHYSICS_SPHERE_COLLIDER_HPP
Abstract base class for collision objects.
Definition: collider.hpp:34
Sphere collision object.
constexpr collider_type type() const noexcept override
Returns the collider type.
constexpr sphere_collider() noexcept=default
Constructs a sphere collider.
constexpr sphere_collider(float radius) noexcept
Constructs a sphere collider.
constexpr const math::fvec3 & get_center() const noexcept
Returns the center of the sphere, in object space.
constexpr const sphere_type & get_sphere() const noexcept
Returns the sphere shape.
geom::sphere< float > sphere_type
Sphere type.
constexpr void set_center(const math::fvec3 &center) noexcept
Sets the center of the sphere.
constexpr sphere_collider(const math::fvec3 &center, float radius) noexcept
Constructs a sphere collider.
constexpr float get_radius() const noexcept
Returns the radius of the sphere.
constexpr sphere_collider(const sphere_type &sphere) noexcept
Constructs a sphere collider from a sphere.
constexpr void set_sphere(const sphere_type &sphere) noexcept
Sets the collider's sphere.
constexpr void set_radius(float radius) noexcept
Sets the radius of the sphere.
Physics.
Definition: constants.hpp:23
collider_type
Collider types.
@ sphere
Sphere collider.
n-dimensional sphere.
Definition: hypersphere.hpp:37
vector_type center
Hypersphere center.
Definition: hypersphere.hpp:42
T radius
Hypersphere radius.
Definition: hypersphere.hpp:45
n-dimensional vector.
Definition: vector.hpp:44