Antkeeper  0.0.1
plane-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_PLANE_COLLIDER_HPP
21 #define ANTKEEPER_PHYSICS_PLANE_COLLIDER_HPP
22 
25 
26 namespace physics {
27 
31 class plane_collider: public collider
32 {
33 public:
36 
37  [[nodiscard]] inline constexpr collider_type type() const noexcept override
38  {
39  return collider_type::plane;
40  }
41 
47  inline constexpr explicit plane_collider(const plane_type& plane) noexcept:
48  m_plane{plane}
49  {}
50 
58  inline constexpr plane_collider(const math::fvec3& normal, float constant) noexcept:
59  m_plane{normal, constant}
60  {}
61  inline constexpr explicit plane_collider(const math::fvec3& normal) noexcept:
62  m_plane{normal, 0.0f}
63  {}
64  constexpr plane_collider() noexcept = default;
66 
73  inline constexpr plane_collider(const math::fvec3& normal, const math::fvec3& offset) noexcept:
74  m_plane(normal, offset)
75  {}
76 
82  inline constexpr void set_plane(const plane_type& plane) noexcept
83  {
84  m_plane = plane;
85  }
86 
92  inline constexpr void set_normal(const math::fvec3& normal) noexcept
93  {
94  m_plane.normal = normal;
95  }
96 
102  inline constexpr void set_constant(float constant) noexcept
103  {
104  m_plane.constant = constant;
105  }
106 
108  [[nodiscard]] inline constexpr const plane_type& get_plane() const noexcept
109  {
110  return m_plane;
111  }
112 
114  [[nodiscard]] inline constexpr const math::fvec3& get_normal() const noexcept
115  {
116  return m_plane.normal;
117  }
118 
120  [[nodiscard]] inline constexpr float get_constant() const noexcept
121  {
122  return m_plane.constant;
123  }
124 
125 private:
126  plane_type m_plane{};
127 };
128 
129 } // namespace physics
130 
131 #endif // ANTKEEPER_PHYSICS_PLANE_COLLIDER_HPP
Abstract base class for collision objects.
Definition: collider.hpp:34
Plane collision object.
constexpr plane_collider(const plane_type &plane) noexcept
Constructs a plane collider from a plane.
constexpr plane_collider(const math::fvec3 &normal, float constant) noexcept
Constructs a plane collider from a normal and constant.
constexpr collider_type type() const noexcept override
Returns the collider type.
constexpr void set_plane(const plane_type &plane) noexcept
Sets the collider's plane.
constexpr const math::fvec3 & get_normal() const noexcept
Returns the plane normal, in object space.
constexpr plane_collider(const math::fvec3 &normal) noexcept
Constructs a plane collider from a normal and constant.
constexpr plane_collider() noexcept=default
Constructs a plane collider from a normal and constant.
constexpr void set_constant(float constant) noexcept
Sets the plane constant.
constexpr float get_constant() const noexcept
Returns the plane constant.
constexpr const plane_type & get_plane() const noexcept
Returns the plane shape.
geom::plane< float > plane_type
Plane type.
constexpr void set_normal(const math::fvec3 &normal) noexcept
Sets the plane normal.
Mathematical functions and data types.
Definition: angles.hpp:26
T offset(T longitude)
Calculates the UTC offset at a given longitude.
Definition: utc.hpp:38
Physics.
Definition: constants.hpp:23
collider_type
Collider types.
@ plane
Plane collider.
n-dimensional plane.
Definition: hyperplane.hpp:36
T constant
Hyperplane constant.
Definition: hyperplane.hpp:44
vector_type normal
Hyperplane normal.
Definition: hyperplane.hpp:41
n-dimensional vector.
Definition: vector.hpp:44