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

192 lines
4.4 KiB

7 years ago
  1. /*
  2. * Copyright (C) 2017 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_CONTROLLER_HPP
  20. #define CAMERA_CONTROLLER_HPP
  21. #include <emergent/emergent.hpp>
  22. using namespace Emergent;
  23. class CameraController
  24. {
  25. public:
  26. CameraController();
  27. virtual void update(float dt) = 0;
  28. void setCamera(Camera* camera);
  29. const Camera* getCamera() const;
  30. Camera* getCamera();
  31. protected:
  32. Camera* camera;
  33. };
  34. inline void CameraController::setCamera(Camera* camera)
  35. {
  36. this->camera = camera;
  37. }
  38. inline const Camera* CameraController::getCamera() const
  39. {
  40. return camera;
  41. }
  42. inline Camera* CameraController::getCamera()
  43. {
  44. return camera;
  45. }
  46. class SurfaceCameraController: public CameraController
  47. {
  48. public:
  49. SurfaceCameraController();
  50. virtual ~SurfaceCameraController();
  51. virtual void update(float dt);
  52. /// @param direction Specifies the movement direction and speed scale on the XZ plane
  53. void move(Vector2 direction);
  54. void rotate(float angle);
  55. void zoom(float distance);
  56. void setFocalPoint(const Vector3& point);
  57. void setFocalDistance(float distance);
  58. void setElevation(float angle);
  59. void setAzimuth(float angle);
  60. void setTargetFocalPoint(const Vector3& point);
  61. void setTargetFocalDistance(float distance);
  62. void setTargetElevation(float angle);
  63. void setTargetAzimuth(float angle);
  64. const Vector3& getFocalPoint() const;
  65. float getFocalDistance() const;
  66. float getElevation() const;
  67. float getAzimuth() const;
  68. const Vector3& getTargetFocalPoint() const;
  69. float getTargetFocalDistance() const;
  70. float getTargetElevation() const;
  71. float getTargetAzimuth() const;
  72. const Vector3& getTranslation() const;
  73. const glm::quat& getRotation() const;
  74. const Vector3& getTargetTranslation() const;
  75. const glm::quat& getTargetRotation() const;
  76. private:
  77. Vector3 focalPoint;
  78. float focalDistance;
  79. float elevation;
  80. float azimuth;
  81. Vector3 targetFocalPoint;
  82. float targetFocalDistance;
  83. float targetElevation;
  84. float targetAzimuth;
  85. glm::quat elevationRotation;
  86. glm::quat azimuthRotation;
  87. glm::quat rotation;
  88. glm::quat targetElevationRotation;
  89. glm::quat targetAzimuthRotation;
  90. glm::quat targetRotation;
  91. Vector3 translation;
  92. Vector3 targetTranslation;
  93. };
  94. inline const Vector3& SurfaceCameraController::getFocalPoint() const
  95. {
  96. return focalPoint;
  97. }
  98. inline float SurfaceCameraController::getFocalDistance() const
  99. {
  100. return focalDistance;
  101. }
  102. inline float SurfaceCameraController::getElevation() const
  103. {
  104. return elevation;
  105. }
  106. inline float SurfaceCameraController::getAzimuth() const
  107. {
  108. return azimuth;
  109. }
  110. inline const Vector3& SurfaceCameraController::getTargetFocalPoint() const
  111. {
  112. return targetFocalPoint;
  113. }
  114. inline float SurfaceCameraController::getTargetFocalDistance() const
  115. {
  116. return targetFocalDistance;
  117. }
  118. inline float SurfaceCameraController::getTargetElevation() const
  119. {
  120. return targetElevation;
  121. }
  122. inline float SurfaceCameraController::getTargetAzimuth() const
  123. {
  124. return targetAzimuth;
  125. }
  126. inline const Vector3& SurfaceCameraController::getTranslation() const
  127. {
  128. return translation;
  129. }
  130. inline const glm::quat& SurfaceCameraController::getRotation() const
  131. {
  132. return rotation;
  133. }
  134. inline const Vector3& SurfaceCameraController::getTargetTranslation() const
  135. {
  136. return targetTranslation;
  137. }
  138. inline const glm::quat& SurfaceCameraController::getTargetRotation() const
  139. {
  140. return targetRotation;
  141. }
  142. /**
  143. * Note, when mouseover tunnel, highlight (in red?) the entire path from the end of the tunnel to the entrance of the nest.
  144. */
  145. class TunnelCameraController: public CameraController
  146. {
  147. public:
  148. TunnelCameraController();
  149. virtual ~TunnelCameraController();
  150. virtual void update(float dt);
  151. void rotateCW(float scale);
  152. void rotateCCW(float scale);
  153. // Ascends the tunnel system in the direction of the entrance
  154. void ascend(float scale);
  155. // Descends along the current tunnel
  156. void descend(float scale);
  157. };
  158. #endif