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

126 lines
2.4 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. };
  57. /**
  58. * Creates an instance of Ant.
  59. */
  60. Ant(Colony* colony);
  61. void move(const Vector3& velocity);
  62. void turn(float angle);
  63. void update(float dt);
  64. void setState(Ant::State state);
  65. const Colony* getColony() const;
  66. Colony* getColony();
  67. const Transform& getTransform() const;
  68. const ModelInstance* getModelInstance() const;
  69. ModelInstance* getModelInstance();
  70. private:
  71. Vector3 forage(const Vector3& leftReceptor, const Vector3& rightReceptor);
  72. /**
  73. * Calculates the surface normal averaged between the surface normals at each of the ant's grounded feet.
  74. */
  75. Vector3 calculateAverageSurfaceNormal() const;
  76. void updateTransform();
  77. Colony* colony;
  78. Ant::State state;
  79. Transform transform;
  80. ModelInstance modelInstance;
  81. Pose* skeletonPose;
  82. };
  83. inline const Colony* Ant::getColony() const
  84. {
  85. return colony;
  86. }
  87. inline Colony* Ant::getColony()
  88. {
  89. return colony;
  90. }
  91. inline const Transform& Ant::getTransform() const
  92. {
  93. return transform;
  94. }
  95. inline const ModelInstance* Ant::getModelInstance() const
  96. {
  97. return &modelInstance;
  98. }
  99. inline ModelInstance* Ant::getModelInstance()
  100. {
  101. return &modelInstance;
  102. }
  103. #endif // ANT_HPP