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

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