Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/rvo2/rvo2_2d/Agent2d.h
9903 views
1
/*
2
* Agent2d.h
3
* RVO2 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
* http://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 <[email protected]>.
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
* <http://gamma.cs.unc.edu/RVO2/>
31
*/
32
33
#ifndef RVO2D_AGENT_H_
34
#define RVO2D_AGENT_H_
35
36
/**
37
* \file Agent2d.h
38
* \brief Contains the Agent class.
39
*/
40
41
#include "Definitions.h"
42
#include "RVOSimulator2d.h"
43
44
namespace RVO2D {
45
/**
46
* \brief Defines an agent in the simulation.
47
*/
48
class Agent2D {
49
public:
50
/**
51
* \brief Constructs an agent instance.
52
* \param sim The simulator instance.
53
*/
54
explicit Agent2D();
55
56
/**
57
* \brief Computes the neighbors of this agent.
58
*/
59
void computeNeighbors(RVOSimulator2D *sim_);
60
61
/**
62
* \brief Computes the new velocity of this agent.
63
*/
64
void computeNewVelocity(RVOSimulator2D *sim_);
65
66
/**
67
* \brief Inserts an agent neighbor into the set of neighbors of
68
* this agent.
69
* \param agent A pointer to the agent to be inserted.
70
* \param rangeSq The squared range around this agent.
71
*/
72
void insertAgentNeighbor(const Agent2D *agent, float &rangeSq);
73
74
/**
75
* \brief Inserts a static obstacle neighbor into the set of neighbors
76
* of this agent.
77
* \param obstacle The number of the static obstacle to be
78
* inserted.
79
* \param rangeSq The squared range around this agent.
80
*/
81
void insertObstacleNeighbor(const Obstacle2D *obstacle, float rangeSq);
82
83
/**
84
* \brief Updates the two-dimensional position and two-dimensional
85
* velocity of this agent.
86
*/
87
void update(RVOSimulator2D *sim_);
88
89
std::vector<std::pair<float, const Agent2D *> > agentNeighbors_;
90
size_t maxNeighbors_;
91
float maxSpeed_;
92
float neighborDist_;
93
Vector2 newVelocity_;
94
std::vector<std::pair<float, const Obstacle2D *> > obstacleNeighbors_;
95
std::vector<Line> orcaLines_;
96
Vector2 position_;
97
Vector2 prefVelocity_;
98
float radius_;
99
float timeHorizon_;
100
float timeHorizonObst_;
101
Vector2 velocity_;
102
float height_ = 0.0;
103
float elevation_ = 0.0;
104
uint32_t avoidance_layers_ = 1;
105
uint32_t avoidance_mask_ = 1;
106
float avoidance_priority_ = 1.0;
107
108
size_t id_;
109
110
friend class KdTree2D;
111
friend class RVOSimulator2D;
112
};
113
114
/**
115
* \relates Agent
116
* \brief Solves a one-dimensional linear program on a specified line
117
* subject to linear constraints defined by lines and a circular
118
* constraint.
119
* \param lines Lines defining the linear constraints.
120
* \param lineNo The specified line constraint.
121
* \param radius The radius of the circular constraint.
122
* \param optVelocity The optimization velocity.
123
* \param directionOpt True if the direction should be optimized.
124
* \param result A reference to the result of the linear program.
125
* \return True if successful.
126
*/
127
bool linearProgram1(const std::vector<Line> &lines, size_t lineNo,
128
float radius, const Vector2 &optVelocity,
129
bool directionOpt, Vector2 &result);
130
131
/**
132
* \relates Agent
133
* \brief Solves a two-dimensional linear program subject to linear
134
* constraints defined by lines and a circular constraint.
135
* \param lines Lines defining the linear constraints.
136
* \param radius The radius of the circular constraint.
137
* \param optVelocity The optimization velocity.
138
* \param directionOpt True if the direction should be optimized.
139
* \param result A reference to the result of the linear program.
140
* \return The number of the line it fails on, and the number of lines if successful.
141
*/
142
size_t linearProgram2(const std::vector<Line> &lines, float radius,
143
const Vector2 &optVelocity, bool directionOpt,
144
Vector2 &result);
145
146
/**
147
* \relates Agent
148
* \brief Solves a two-dimensional linear program subject to linear
149
* constraints defined by lines and a circular constraint.
150
* \param lines Lines defining the linear constraints.
151
* \param numObstLines Count of obstacle lines.
152
* \param beginLine The line on which the 2-d linear program failed.
153
* \param radius The radius of the circular constraint.
154
* \param result A reference to the result of the linear program.
155
*/
156
void linearProgram3(const std::vector<Line> &lines, size_t numObstLines, size_t beginLine,
157
float radius, Vector2 &result);
158
}
159
160
#endif /* RVO2D_AGENT_H_ */
161
162