Agent.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Agent.h
  3. * RVO2-3D Library
  4. *
  5. * Copyright 2008 University of North Carolina at Chapel Hill
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * https://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * Please send all bug reports to <geom@cs.unc.edu>.
  20. *
  21. * The authors may be contacted via:
  22. *
  23. * Jur van den Berg, Stephen J. Guy, Jamie Snape, Ming C. Lin, Dinesh Manocha
  24. * Dept. of Computer Science
  25. * 201 S. Columbia St.
  26. * Frederick P. Brooks, Jr. Computer Science Bldg.
  27. * Chapel Hill, N.C. 27599-3175
  28. * United States of America
  29. *
  30. * <https://gamma.cs.unc.edu/RVO2/>
  31. */
  32. /**
  33. * \file Agent.h
  34. * \brief Contains the Agent class.
  35. */
  36. #ifndef RVO3D_AGENT_H_
  37. #define RVO3D_AGENT_H_
  38. #include <cstddef>
  39. #include <utility>
  40. #include <vector>
  41. #include "Vector3.h"
  42. // Note: Slightly modified to work better in Godot.
  43. // - The agent can be created by anyone.
  44. // - The simulator pointer is removed.
  45. // - The update function is removed.
  46. // - The compute velocity function now need the timeStep.
  47. // - Moved the `Plane` class here.
  48. // - Added a new parameter `ignore_y_` in the `Agent`. This parameter is used to control a godot feature that allows to avoid collisions by moving on the horizontal plane.
  49. namespace RVO {
  50. /**
  51. * \brief Defines a plane.
  52. */
  53. class Plane {
  54. public:
  55. /**
  56. * \brief A point on the plane.
  57. */
  58. Vector3 point;
  59. /**
  60. * \brief The normal to the plane.
  61. */
  62. Vector3 normal;
  63. };
  64. /**
  65. * \brief Defines an agent in the simulation.
  66. */
  67. class Agent {
  68. public:
  69. /**
  70. * \brief Constructs an agent instance.
  71. * \param sim The simulator instance.
  72. */
  73. explicit Agent();
  74. /**
  75. * \brief Computes the neighbors of this agent.
  76. */
  77. void computeNeighbors(class KdTree *kdTree_);
  78. /**
  79. * \brief Computes the new velocity of this agent.
  80. */
  81. void computeNewVelocity(float timeStep);
  82. /**
  83. * \brief Inserts an agent neighbor into the set of neighbors of this agent.
  84. * \param agent A pointer to the agent to be inserted.
  85. * \param rangeSq The squared range around this agent.
  86. */
  87. void insertAgentNeighbor(const Agent *agent, float &rangeSq);
  88. Vector3 newVelocity_;
  89. Vector3 position_;
  90. Vector3 prefVelocity_;
  91. Vector3 velocity_;
  92. size_t id_;
  93. size_t maxNeighbors_;
  94. float maxSpeed_;
  95. float neighborDist_;
  96. float radius_;
  97. float timeHorizon_;
  98. std::vector<std::pair<float, const Agent *> > agentNeighbors_;
  99. std::vector<Plane> orcaPlanes_;
  100. /// This is a godot feature that allows the Agent to avoid collision by mooving
  101. /// on the horizontal plane.
  102. bool ignore_y_;
  103. friend class KdTree;
  104. };
  105. }
  106. #endif /* RVO3D_AGENT_H_ */