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

120 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 the camera from the rig.
  48. */
  49. void detach();
  50. /**
  51. * Returns the attached camera.
  52. */
  53. const ::camera* get_camera() const;
  54. const float3& get_translation() const;
  55. const quaternion_type& get_rotation() const;
  56. const float3& get_forward() const;
  57. const float3& get_right() const;
  58. const float3& get_up() const;
  59. protected:
  60. /**
  61. * Updates the transform of the camera
  62. */
  63. void update_transform(const transform_type& transform);
  64. void update_projection(float fov, float aspect_ratio, float clip_near, float clip_far);
  65. void update_projection(float clip_left, float clip_right, float clip_bottom, float clip_top, float clip_near, float clip_far);
  66. private:
  67. camera* camera;
  68. transform_type transform;
  69. float3 forward;
  70. float3 right;
  71. float3 up;
  72. };
  73. inline const camera* camera_rig::get_camera() const
  74. {
  75. return camera;
  76. }
  77. inline const float3& camera_rig::get_translation() const
  78. {
  79. return transform.translation;
  80. }
  81. inline const typename camera_rig::quaternion_type& camera_rig::get_rotation() const
  82. {
  83. return transform.rotation;
  84. }
  85. inline const float3& camera_rig::get_forward() const
  86. {
  87. return forward;
  88. }
  89. inline const float3& camera_rig::get_right() const
  90. {
  91. return right;
  92. }
  93. inline const float3& camera_rig::get_up() const
  94. {
  95. return up;
  96. }
  97. #endif // ANTKEEPER_CAMERA_RIG_HPP