💿🐜 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.

81 lines
2.2 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_COLLIDER_HPP
  20. #define ANTKEEPER_PHYSICS_COLLIDER_HPP
  21. #include <engine/physics/kinematics/collider-type.hpp>
  22. #include <engine/physics/kinematics/collider-material.hpp>
  23. #include <cstdint>
  24. #include <memory>
  25. namespace physics {
  26. /**
  27. * Abstract base class for collision objects.
  28. */
  29. class collider
  30. {
  31. public:
  32. /**
  33. * Returns the collider type.
  34. */
  35. [[nodiscard]] virtual constexpr collider_type type() const noexcept = 0;
  36. /**
  37. * Sets the layer mask of the collider.
  38. *
  39. * @param mask 32-bit layer mask in which each set bit represents a layer with which the collider can interact.
  40. */
  41. inline constexpr void set_layer_mask(std::uint32_t mask) noexcept
  42. {
  43. m_layer_mask = mask;
  44. }
  45. /**
  46. * Sets the collider material.
  47. */
  48. inline void set_material(std::shared_ptr<collider_material> material) noexcept
  49. {
  50. m_material = material;
  51. }
  52. /// Returns the layer mask of the collider.
  53. [[nodiscard]] inline constexpr std::uint32_t get_layer_mask() const noexcept
  54. {
  55. return m_layer_mask;
  56. }
  57. /// Returns the collider material.
  58. [[nodiscard]] inline constexpr const std::shared_ptr<collider_material>& get_material() const noexcept
  59. {
  60. return m_material;
  61. }
  62. private:
  63. /// Layer mask, in which each bit represents a layer with which the rigid body can interact.
  64. std::uint32_t m_layer_mask{1};
  65. /// Collider material.
  66. std::shared_ptr<collider_material> m_material;
  67. };
  68. } // namespace physics
  69. #endif // ANTKEEPER_PHYSICS_COLLIDER_HPP