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

313 lines
5.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 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 TOOL_HPP
  20. #define TOOL_HPP
  21. #include "../ui/tween.hpp"
  22. #include <emergent/emergent.hpp>
  23. using namespace Emergent;
  24. class Ant;
  25. class Colony;
  26. class Navmesh;
  27. class SurfaceCameraController;
  28. /**
  29. * Abstract base class for tools. Tools are the only way for the user to interact with the world.
  30. */
  31. class Tool
  32. {
  33. public:
  34. /**
  35. * Creates an instance of Tool.
  36. */
  37. Tool();
  38. /**
  39. * Destroys an instance of Tool.
  40. */
  41. virtual ~Tool();
  42. /**
  43. * Updates the tool.
  44. *
  45. * @param dt Application timestep.
  46. */
  47. virtual void update(float dt) = 0;
  48. /**
  49. * Activates or deactivates the tool.
  50. */
  51. virtual void setActive(bool active);
  52. /**
  53. * Sets the picking position.
  54. *
  55. * @param pick Picking position
  56. */
  57. void setPick(const Vector3& pick);
  58. /**
  59. * Sets the camera.
  60. *
  61. * @param camera Pointer to the camera.
  62. */
  63. void setCameraController(const SurfaceCameraController* cameraController);
  64. bool isActive() const;
  65. /**
  66. * Returns the model instance.
  67. */
  68. const ModelInstance* getModelInstance() const;
  69. ModelInstance* getModelInstance();
  70. protected:
  71. ModelInstance modelInstance;
  72. bool active;
  73. Vector3 pick;
  74. const SurfaceCameraController* cameraController;
  75. };
  76. inline bool Tool::isActive() const
  77. {
  78. return active;
  79. }
  80. inline void Tool::setPick(const Vector3& pick)
  81. {
  82. this->pick = pick;
  83. }
  84. inline const ModelInstance* Tool::getModelInstance() const
  85. {
  86. return &modelInstance;
  87. }
  88. inline ModelInstance* Tool::getModelInstance()
  89. {
  90. return &modelInstance;
  91. }
  92. /**
  93. * The forceps tool can pick up ants and place them anywhere in the world.
  94. */
  95. class Forceps: public Tool
  96. {
  97. public:
  98. enum class State
  99. {
  100. RELEASED,
  101. RELEASING,
  102. PINCHED,
  103. PINCHING
  104. };
  105. /**
  106. * Creates an instance of Forceps.
  107. *
  108. * @param model Forceps model
  109. */
  110. Forceps(const Model* model);
  111. /**
  112. * Destroys an instance of Forceps.
  113. */
  114. ~Forceps();
  115. /**
  116. * Updates the forceps.
  117. *
  118. * @param dt Application timestep.
  119. */
  120. virtual void update(float dt);
  121. /**
  122. * Pinches the forceps.
  123. */
  124. void pinch();
  125. /**
  126. * Releases the forceps.
  127. */
  128. void release();
  129. /**
  130. * Associates a colony with this forceps.
  131. *
  132. * @param colony Colony with which to associate.
  133. */
  134. void setColony(Colony* colony);
  135. void setNavmesh(Navmesh* navmesh);
  136. /**
  137. * Returns the current state of the forceps.
  138. */
  139. Forceps::State getState() const;
  140. /**
  141. * Returns the suspended ant, if any.
  142. */
  143. Ant* getSuspendedAnt() const;
  144. private:
  145. Forceps::State state;
  146. Pose* pose;
  147. const Animation* pinchAnimation;
  148. const Animation* releaseAnimation;
  149. float animationTime;
  150. float animationTimeStep;
  151. float hoverDistance;
  152. Tweener* tweener;
  153. Tween<float>* descentTween;
  154. Tween<float>* ascentTween;
  155. Vector3 translationBottom;
  156. Vector3 translationTop;
  157. Quaternion rotationTop;
  158. Quaternion rotationBottom;
  159. bool flipRotation;
  160. Colony* colony;
  161. Ant* targetedAnt;
  162. Ant* suspendedAnt;
  163. Navmesh* navmesh;
  164. };
  165. inline Forceps::State Forceps::getState() const
  166. {
  167. return state;
  168. }
  169. inline Ant* Forceps::getSuspendedAnt() const
  170. {
  171. return suspendedAnt;
  172. }
  173. /**
  174. * The lens tool can be used to burn ants.
  175. */
  176. class Lens: public Tool
  177. {
  178. public:
  179. /**
  180. * Creates an instance of Lens.
  181. *
  182. * @param model Lens model
  183. */
  184. Lens(const Model* model);
  185. /**
  186. * Destroys an instance of Lens.
  187. */
  188. ~Lens();
  189. /**
  190. * Updates the lens.
  191. *
  192. * @param dt Application timestep.
  193. */
  194. virtual void update(float dt);
  195. /**
  196. * Activates or deactivates the lens.
  197. */
  198. virtual void setActive(bool active);
  199. void focus();
  200. void unfocus();
  201. /**
  202. * Associates a colony with this lens.
  203. *
  204. * @param colony Colony with which to associate.
  205. */
  206. void setColony(Colony* colony);
  207. void setSunDirection(const Vector3& direction);
  208. /**
  209. * Returns the spotlight.
  210. */
  211. const Spotlight* getSpotlight() const;
  212. Spotlight* getSpotlight();
  213. private:
  214. Spotlight spotlight;
  215. float unfocusedDistance;
  216. float focusedDistance;
  217. bool focused;
  218. Vector3 sunDirection;
  219. Tweener* tweener;
  220. Tween<float>* descentTween;
  221. Tween<float>* ascentTween;
  222. Colony* colony;
  223. };
  224. inline const Spotlight* Lens::getSpotlight() const
  225. {
  226. return &spotlight;
  227. }
  228. inline Spotlight* Lens::getSpotlight()
  229. {
  230. return &spotlight;
  231. }
  232. /**
  233. * The brush tool can paint pheromones on the terrain.
  234. */
  235. class Brush: public Tool
  236. {
  237. public:
  238. Brush(const Model* model);
  239. ~Brush();
  240. virtual void update(float dt);
  241. void press();
  242. void release();
  243. /**
  244. * Associates a colony with this brush.
  245. *
  246. * @param colony Colony with which to associate.
  247. */
  248. void setColony(Colony* colony);
  249. private:
  250. void paint(const Vector2& position, float radius);
  251. Pose* pose;
  252. float hoverDistance;
  253. bool descended;
  254. Vector3 oldPick;
  255. Tweener* tweener;
  256. Tween<float>* descentTween;
  257. Tween<float>* ascentTween;
  258. float tiltAngle;
  259. float targetTiltAngle;
  260. Vector3 tiltAxis;
  261. Vector3 targetTiltAxis;
  262. Colony* colony;
  263. };
  264. #endif // TOOL_HPP