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

128 lines
2.7 KiB

  1. /*
  2. * Copyright (C) 2020 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_CAMERA_RIG_HPP
  20. #define ANTKEEPER_CAMERA_RIG_HPP
  21. #include "math/quaternion-type.hpp"
  22. #include "math/transform-type.hpp"
  23. #include "utility/fundamental-types.hpp"
  24. class camera;
  25. /**
  26. * Abstract base class for camera rigs which control the movement of cameras.
  27. */
  28. class camera_rig
  29. {
  30. public:
  31. typedef math::quaternion<float> quaternion_type;
  32. typedef math::transform<float> transform_type;
  33. camera_rig();
  34. /**
  35. * Updates the rig.
  36. *
  37. * @param dt Delta time.
  38. */
  39. virtual void update(float dt) = 0;
  40. /**
  41. * Attaches a camera to the rig.
  42. *
  43. * @param camera Camera to attach.
  44. */
  45. void attach(::camera* camera);
  46. /**
  47. * Detaches a camera from the rig.
  48. */
  49. void detach();
  50. /**
  51. * Sets the translation of the camera rig.
  52. */
  53. void set_translation(const float3& translation);
  54. /**
  55. * Sets the rotation of the camera rig.
  56. */
  57. void set_rotation(const quaternion_type& rotation);
  58. /**
  59. * Returns the attached camera.
  60. */
  61. const ::camera* get_camera() const;
  62. /// @copydoc camera_rig::get_camera() const
  63. ::camera* get_camera();
  64. const float3& get_translation() const;
  65. const quaternion_type& get_rotation() const;
  66. const float3& get_forward() const;
  67. const float3& get_right() const;
  68. const float3& get_up() const;
  69. private:
  70. camera* camera;
  71. float3 translation;
  72. quaternion_type rotation;
  73. float3 forward;
  74. float3 right;
  75. float3 up;
  76. };
  77. inline const camera* camera_rig::get_camera() const
  78. {
  79. return camera;
  80. }
  81. inline camera* camera_rig::get_camera()
  82. {
  83. return camera;
  84. }
  85. inline const float3& camera_rig::get_translation() const
  86. {
  87. return translation;
  88. }
  89. inline const typename camera_rig::quaternion_type& camera_rig::get_rotation() const
  90. {
  91. return rotation;
  92. }
  93. inline const float3& camera_rig::get_forward() const
  94. {
  95. return forward;
  96. }
  97. inline const float3& camera_rig::get_right() const
  98. {
  99. return right;
  100. }
  101. inline const float3& camera_rig::get_up() const
  102. {
  103. return up;
  104. }
  105. #endif // ANTKEEPER_CAMERA_RIG_HPP