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

274 lines
5.5 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
  1. /*
  2. * Copyright (C) 2017-2019 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 CAMERA_RIG_HPP
  20. #define CAMERA_RIG_HPP
  21. #include <emergent/emergent.hpp>
  22. using namespace Emergent;
  23. /**
  24. * Abstract base class for camera rigs which control the movement of cameras.
  25. */
  26. class CameraRig
  27. {
  28. public:
  29. CameraRig();
  30. /**
  31. * Updates the rig.
  32. */
  33. virtual void update(float dt) = 0;
  34. /**
  35. * Attaches a camera to the rig.
  36. *
  37. * @param camera Camera to attach.
  38. */
  39. void attachCamera(Camera* camera);
  40. /**
  41. * Detaches a camera from the rig.
  42. */
  43. void detachCamera();
  44. /**
  45. * Sets the translation of the camera rig.
  46. */
  47. void setTranslation(const Vector3& translation);
  48. /**
  49. * Sets the rotation of the camera rig.
  50. */
  51. void setRotation(const Quaternion& rotation);
  52. /**
  53. * Returns the attached camera.
  54. */
  55. const Camera* getCamera() const;
  56. /// @copydoc CameraRig::getCamera() const
  57. Camera* getCamera();
  58. const Vector3& getTranslation() const;
  59. const Quaternion& getRotation() const;
  60. const Vector3& getForward() const;
  61. const Vector3& getRight() const;
  62. const Vector3& getUp() const;
  63. private:
  64. Camera* camera;
  65. Vector3 translation;
  66. Quaternion rotation;
  67. Vector3 forward;
  68. Vector3 right;
  69. Vector3 up;
  70. };
  71. inline const Camera* CameraRig::getCamera() const
  72. {
  73. return camera;
  74. }
  75. inline Camera* CameraRig::getCamera()
  76. {
  77. return camera;
  78. }
  79. inline const Vector3& CameraRig::getTranslation() const
  80. {
  81. return translation;
  82. }
  83. inline const Quaternion& CameraRig::getRotation() const
  84. {
  85. return rotation;
  86. }
  87. inline const Vector3& CameraRig::getForward() const
  88. {
  89. return forward;
  90. }
  91. inline const Vector3& CameraRig::getRight() const
  92. {
  93. return right;
  94. }
  95. inline const Vector3& CameraRig::getUp() const
  96. {
  97. return up;
  98. }
  99. /**
  100. * Rig which can freely move around the scene.
  101. */
  102. class FreeCam: public CameraRig
  103. {
  104. public:
  105. FreeCam();
  106. virtual ~FreeCam();
  107. /**
  108. * Moves the camera.
  109. *
  110. * @param velocity Specifies the movement velocity on the local forward-right plane.
  111. */
  112. void move(const Vector2& velocity);
  113. /**
  114. * Rotates the camera.
  115. *
  116. * @param pan Specifies the angle (in radians) to rotate around the global Y-axis.
  117. * @param tilt Specifies the angle (in radians) to rotate around the local X-axis.
  118. */
  119. void rotate(float pan, float tilt);
  120. virtual void update(float dt);
  121. private:
  122. Quaternion pitchRotation;
  123. Quaternion yawRotation;
  124. float pitch;
  125. float yaw;
  126. };
  127. /**
  128. * Rig which orbits around a focal point.
  129. */
  130. class OrbitCam: public CameraRig
  131. {
  132. public:
  133. OrbitCam();
  134. virtual ~OrbitCam();
  135. virtual void update(float dt);
  136. /// @param direction Specifies the movement direction and speed scale on the XZ plane
  137. void move(Vector2 direction);
  138. void rotate(float angle);
  139. void zoom(float distance);
  140. void setFocalPoint(const Vector3& point);
  141. void setFocalDistance(float distance);
  142. void setElevation(float angle);
  143. void setAzimuth(float angle);
  144. void setTargetFocalPoint(const Vector3& point);
  145. void setTargetFocalDistance(float distance);
  146. void setTargetElevation(float angle);
  147. void setTargetAzimuth(float angle);
  148. const Vector3& getFocalPoint() const;
  149. float getFocalDistance() const;
  150. float getElevation() const;
  151. float getAzimuth() const;
  152. const Vector3& getTargetFocalPoint() const;
  153. float getTargetFocalDistance() const;
  154. float getTargetElevation() const;
  155. float getTargetAzimuth() const;
  156. const Vector3& getTargetTranslation() const;
  157. const Quaternion& getTargetRotation() const;
  158. private:
  159. Vector3 focalPoint;
  160. float focalDistance;
  161. float elevation;
  162. float azimuth;
  163. Vector3 targetFocalPoint;
  164. float targetFocalDistance;
  165. float targetElevation;
  166. float targetAzimuth;
  167. Quaternion elevationRotation;
  168. Quaternion azimuthRotation;
  169. Quaternion targetElevationRotation;
  170. Quaternion targetAzimuthRotation;
  171. Quaternion targetRotation;
  172. Vector3 targetTranslation;
  173. };
  174. inline const Vector3& OrbitCam::getFocalPoint() const
  175. {
  176. return focalPoint;
  177. }
  178. inline float OrbitCam::getFocalDistance() const
  179. {
  180. return focalDistance;
  181. }
  182. inline float OrbitCam::getElevation() const
  183. {
  184. return elevation;
  185. }
  186. inline float OrbitCam::getAzimuth() const
  187. {
  188. return azimuth;
  189. }
  190. inline const Vector3& OrbitCam::getTargetFocalPoint() const
  191. {
  192. return targetFocalPoint;
  193. }
  194. inline float OrbitCam::getTargetFocalDistance() const
  195. {
  196. return targetFocalDistance;
  197. }
  198. inline float OrbitCam::getTargetElevation() const
  199. {
  200. return targetElevation;
  201. }
  202. inline float OrbitCam::getTargetAzimuth() const
  203. {
  204. return targetAzimuth;
  205. }
  206. inline const Vector3& OrbitCam::getTargetTranslation() const
  207. {
  208. return targetTranslation;
  209. }
  210. inline const Quaternion& OrbitCam::getTargetRotation() const
  211. {
  212. return targetRotation;
  213. }
  214. /**
  215. * Rig which aligns a camera with a light. Used for rendering shadow maps.
  216. */
  217. class ShadowCam
  218. {
  219. public:
  220. ShadowCam();
  221. virtual ~ShadowCam();
  222. void setLight(const PunctualLight* light);
  223. void update(float dt);
  224. private:
  225. const PunctualLight* light;
  226. };
  227. #endif // CAMERA_RIG_HPP