💿🐜 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
3.3 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_ORBIT_CAM_HPP
  20. #define ANTKEEPER_ORBIT_CAM_HPP
  21. #include "camera-rig.hpp"
  22. #include "animation/spring.hpp"
  23. #include <array>
  24. /**
  25. * Rig which orbits around a focal point.
  26. */
  27. class orbit_cam: public camera_rig
  28. {
  29. public:
  30. orbit_cam();
  31. virtual ~orbit_cam();
  32. virtual void update(float dt);
  33. /// @param direction Specifies the movement direction and speed scale on the XZ plane
  34. void move(const float3& translation);
  35. void pan(float angle);
  36. void tilt(float angle);
  37. void zoom(float factor);
  38. void reset_springs();
  39. void set_aspect_ratio(float ratio);
  40. void set_focal_point(const float3& point);
  41. void set_azimuth(float angle);
  42. void set_elevation(float angle);
  43. void set_zoom(float factor);
  44. void set_target_focal_point(const float3& point);
  45. void set_target_azimuth(float angle);
  46. void set_target_elevation(float angle);
  47. void set_target_zoom(float factor);
  48. void set_azimuth_limits(const std::array<float, 2>& limits);
  49. void set_elevation_limits(const std::array<float, 2>& limits);
  50. void set_focal_distance_limits(const std::array<float, 2>& limits);
  51. void set_fov_limits(const std::array<float, 2>& limits);
  52. void set_clip_near_limits(const std::array<float, 2>& limits);
  53. void set_clip_far_limits(const std::array<float, 2>& limits);
  54. const float3& get_focal_point() const;
  55. float get_azimuth() const;
  56. float get_elevation() const;
  57. float get_zoom() const;
  58. const quaternion_type& get_azimuth_rotation() const;
  59. const quaternion_type& get_elevation_rotation() const;
  60. private:
  61. float aspect_ratio;
  62. numeric_spring<float3, float> focal_point_spring;
  63. numeric_spring<float, float> azimuth_spring;
  64. numeric_spring<float, float> elevation_spring;
  65. numeric_spring<float, float> zoom_spring;
  66. std::array<float, 2> azimuth_limits;
  67. std::array<float, 2> elevation_limits;
  68. std::array<float, 2> focal_distance_limits;
  69. std::array<float, 2> fov_limits;
  70. std::array<float, 2> clip_near_limits;
  71. std::array<float, 2> clip_far_limits;
  72. quaternion_type azimuth_rotation;
  73. quaternion_type elevation_rotation;
  74. };
  75. inline const float3& orbit_cam::get_focal_point() const
  76. {
  77. return focal_point_spring.x0;
  78. }
  79. inline float orbit_cam::get_azimuth() const
  80. {
  81. return azimuth_spring.x0;
  82. }
  83. inline float orbit_cam::get_elevation() const
  84. {
  85. return elevation_spring.x0;
  86. }
  87. inline float orbit_cam::get_zoom() const
  88. {
  89. return zoom_spring.x0;
  90. }
  91. inline const typename camera_rig::quaternion_type& orbit_cam::get_azimuth_rotation() const
  92. {
  93. return azimuth_rotation;
  94. }
  95. inline const typename camera_rig::quaternion_type& orbit_cam::get_elevation_rotation() const
  96. {
  97. return elevation_rotation;
  98. }
  99. #endif // ANTKEEPER_ORBIT_CAM_HPP