💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.8 KiB

  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. #ifndef ANTKEEPER_PHYSICS_BOX_COLLIDER_HPP
  20. #define ANTKEEPER_PHYSICS_BOX_COLLIDER_HPP
  21. #include <engine/physics/kinematics/collider.hpp>
  22. #include <engine/geom/primitives/box.hpp>
  23. namespace physics {
  24. /**
  25. * Box collision object.
  26. */
  27. class box_collider: public collider
  28. {
  29. public:
  30. /// Box type.
  31. using box_type = geom::box<float>;
  32. [[nodiscard]] inline constexpr collider_type type() const noexcept override
  33. {
  34. return collider_type::box;
  35. }
  36. /**
  37. * Constructs a box collider from a box.
  38. *
  39. * @param box Box shape.
  40. */
  41. inline constexpr explicit box_collider(const box_type& box) noexcept:
  42. m_box{box}
  43. {}
  44. /**
  45. * Constructs a box collider.
  46. *
  47. * @param min Minimum extent of the box, in object space.
  48. * @param max Maximum extent of the box, in object space.
  49. */
  50. /// @{
  51. inline constexpr box_collider(const math::fvec3& min, const math::fvec3& max) noexcept:
  52. m_box{min, max}
  53. {}
  54. constexpr box_collider() noexcept = default;
  55. /// @}
  56. /**
  57. * Sets the collider's box.
  58. *
  59. * @param box Box shape.
  60. */
  61. inline constexpr void set_box(const box_type& box) noexcept
  62. {
  63. m_box = box;
  64. }
  65. /**
  66. * Sets the minimum extent of the box.
  67. *
  68. * @param min Minimum extent of the box, in object space.
  69. */
  70. inline constexpr void set_min(const math::fvec3& min) noexcept
  71. {
  72. m_box.min = min;
  73. }
  74. /**
  75. * Sets the maximum extent of the box.
  76. *
  77. * @param max Maximum extent of the box, in object space.
  78. */
  79. inline constexpr void set_max(const math::fvec3& max) noexcept
  80. {
  81. m_box.max = max;
  82. }
  83. /// Returns the box shape.
  84. [[nodiscard]] inline constexpr const box_type& get_box() const noexcept
  85. {
  86. return m_box;
  87. }
  88. /// Returns the minimum extent of the box, in object space.
  89. [[nodiscard]] inline constexpr const math::fvec3& get_min() const noexcept
  90. {
  91. return m_box.min;
  92. }
  93. /// Returns the maximum extent of the box, in object space.
  94. [[nodiscard]] inline constexpr const math::fvec3& get_max() const noexcept
  95. {
  96. return m_box.max;
  97. }
  98. private:
  99. box_type m_box{};
  100. };
  101. } // namespace physics
  102. #endif // ANTKEEPER_PHYSICS_BOX_COLLIDER_HPP