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

154 lines
2.9 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 ANT_HPP
  20. #define ANT_HPP
  21. #include <vector>
  22. #include "navmesh.hpp"
  23. #include "agent.hpp"
  24. #include <emergent/emergent.hpp>
  25. using namespace Emergent;
  26. class Colony;
  27. class Gait;
  28. /**
  29. * An individual ant which belongs to a colony.
  30. */
  31. class Ant: public Agent
  32. {
  33. public:
  34. /**
  35. * Named constants corresponding to leg indices.
  36. *
  37. * \_/
  38. * L1 --| |-- R1
  39. * L2 --| |-- R2
  40. * L3 --|_|-- R3
  41. */
  42. enum class LegIndex
  43. {
  44. L1,
  45. L2,
  46. L3,
  47. R1,
  48. R2,
  49. R3
  50. };
  51. enum class State
  52. {
  53. IDLE,
  54. WANDER,
  55. DEAD,
  56. SUSPENDED
  57. };
  58. /**
  59. * Creates an instance of Ant.
  60. */
  61. Ant(Colony* colony);
  62. ~Ant();
  63. void animate();
  64. void suspend(const Vector3& suspensionPoint, const Quaternion& suspensionRotation);
  65. void move(const Vector3& velocity);
  66. void turn(float angle);
  67. void update(float dt);
  68. void setState(Ant::State state);
  69. const Colony* getColony() const;
  70. Colony* getColony();
  71. const Transform& getTransform() const;
  72. const ModelInstance* getModelInstance() const;
  73. ModelInstance* getModelInstance();
  74. // Boid functions
  75. Vector3 seek(const Vector3& target);
  76. Vector3 flee(const Vector3& target);
  77. Vector3 wander();
  78. Vector3 follow();
  79. void applyForce(const Vector3& force);
  80. private:
  81. Vector3 forage(const Vector3& leftReceptor, const Vector3& rightReceptor);
  82. /**
  83. * Calculates the surface normal averaged between the surface normals at each of the ant's grounded feet.
  84. */
  85. Vector3 calculateAverageSurfaceNormal() const;
  86. void updateTransform();
  87. Colony* colony;
  88. Ant::State state;
  89. float animationTime;
  90. Transform transform;
  91. ModelInstance modelInstance;
  92. Pose* pose;
  93. // Boid variables
  94. //Vector3 position;
  95. //Quaternion rotation;
  96. //Vector3 forward;
  97. Vector3 velocity;
  98. Vector3 acceleration;
  99. Vector3 wanderDirection;
  100. float excitement;
  101. Vector3 receptorL;
  102. Vector3 receptorR;
  103. };
  104. inline const Colony* Ant::getColony() const
  105. {
  106. return colony;
  107. }
  108. inline Colony* Ant::getColony()
  109. {
  110. return colony;
  111. }
  112. inline const Transform& Ant::getTransform() const
  113. {
  114. return transform;
  115. }
  116. inline const ModelInstance* Ant::getModelInstance() const
  117. {
  118. return &modelInstance;
  119. }
  120. inline ModelInstance* Ant::getModelInstance()
  121. {
  122. return &modelInstance;
  123. }
  124. #endif // ANT_HPP