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

215 lines
4.6 KiB

  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 AGENT_HPP
  20. #define AGENT_HPP
  21. #include "navmesh.hpp"
  22. #include <vector>
  23. #include <emergent/emergent.hpp>
  24. using namespace Emergent;
  25. class Obstacle;
  26. /*************88
  27. Ant is an agent.
  28. Ant combines steering behaviors with different weights.
  29. I.E.
  30. seek pheromones * 0.5
  31. separation * 0.1
  32. alignment * 0.1
  33. cohesion * 0.1
  34. followWall * 0.2
  35. */
  36. /**
  37. * An agent which navigates on a navmesh.
  38. */
  39. class Agent
  40. {
  41. public:
  42. Agent();
  43. /**
  44. * Adds a force to the agent's acceleration vector.
  45. *
  46. * @param force Acceleration force
  47. */
  48. //void applyForce(const Vector3& force);
  49. /**
  50. * Calculates velocity based on current acceleration vector, then resets acceleration to zero.
  51. */
  52. //void updateVelocity();
  53. /**
  54. * Calculates steering force for the wander behavior.
  55. */
  56. //Vector3 wander(float dt);
  57. /**
  58. * Calculates steering force for the seek behavior.
  59. */
  60. //Vector3 seek(const Vector3& target) const;
  61. /**
  62. * Calculates steering force for the flee behavior.
  63. */
  64. //Vector3 flee(const Vector3& target) const;
  65. //Vector3 containment(const Vector3& probe) const;
  66. //Vector3 separation(const std::list<Agent*>& neighbors) const;
  67. //Vector3 forage(const Vector3& leftProbe, const Vector3& rightProbe);
  68. /*
  69. void setMaxSpeed(float speed);
  70. void setVelocity(const Vector3& velocity);
  71. void setMaxAcceleration(float acceleration);
  72. void setMass(float mass);
  73. void setWanderCircleDistance(float distance);
  74. void setWanderCircleRadius(float radius);
  75. void setWanderRate(float angle);
  76. void setSeparationRadius(float radius);
  77. */
  78. /**
  79. * Sets the position of the agent on a navmesh.
  80. *
  81. * @param triangle Navmesh triangle on which the agent resides
  82. * @param position Barycentric position on the specified triangle
  83. */
  84. void setPosition(Navmesh::Triangle* triangle, const Vector3& position);
  85. /**
  86. * Sets the orientation of the agent. This effectively updates the agent's vector basis and rotation quaternion.
  87. *
  88. * @param forward Normalized forward vector
  89. * @param up Normalized up vector
  90. */
  91. void setOrientation(const Vector3& newForward, const Vector3& newUp);
  92. /*
  93. Vector3 followWall();
  94. // or
  95. Vector3 followEdge();
  96. Vector3 avoidObstacle(const Obstacle* obstacle);
  97. Vector3 alignment(const std::vector<const Agent*>* neighbors);
  98. Vector3 cohesion(const std::vector<const Agent*>* neighbors);
  99. */
  100. const Navmesh::Triangle* getNavmeshTriangle() const;
  101. Navmesh::Triangle* getNavmeshTriangle();
  102. const Vector3& getBarycentricPosition() const;
  103. const Vector3& getPosition() const;
  104. const Vector3& getForward() const;
  105. const Vector3& getUp() const;
  106. const Vector3& getRight() const;
  107. const Quaternion& getRotation() const;
  108. //const Vector3& getVelocity() const;
  109. private:
  110. Navmesh::Triangle* navmeshTriangle;
  111. Vector3 barycentricPosition;
  112. Vector3 position;
  113. Vector3 forward;
  114. Vector3 up;
  115. Vector3 right;
  116. Quaternion rotation;
  117. /*
  118. // Limits
  119. float maxSpeed;
  120. float maxAcceleration;
  121. // Steering forces
  122. float mass;
  123. Vector3 acceleration;
  124. Vector3 velocity;
  125. // Wander variables
  126. float wanderCircleDistance;
  127. float wanderCircleRadius;
  128. float wanderRate;
  129. Vector3 wanderDirection;
  130. float separationRadius;
  131. float separationRadiusSquared;
  132. */
  133. };
  134. inline const Navmesh::Triangle* Agent::getNavmeshTriangle() const
  135. {
  136. return navmeshTriangle;
  137. }
  138. inline Navmesh::Triangle* Agent::getNavmeshTriangle()
  139. {
  140. return navmeshTriangle;
  141. }
  142. inline const Vector3& Agent::getBarycentricPosition() const
  143. {
  144. return barycentricPosition;
  145. }
  146. inline const Vector3& Agent::getPosition() const
  147. {
  148. return position;
  149. }
  150. inline const Vector3& Agent::getForward() const
  151. {
  152. return forward;
  153. }
  154. inline const Vector3& Agent::getUp() const
  155. {
  156. return up;
  157. }
  158. inline const Vector3& Agent::getRight() const
  159. {
  160. return right;
  161. }
  162. inline const Quaternion& Agent::getRotation() const
  163. {
  164. return rotation;
  165. }
  166. /*
  167. inline const Vector3& Agent::getVelocity() const
  168. {
  169. return velocity;
  170. }
  171. */
  172. #endif // AGENT_HPP