📄 rvosimulator.h
字号:
\param agentID The agent's ID
\param orientation The new orientation of the agent
*/
void setAgentOrientation(int agentID, float orientation);
/*! Retrieving the goal of an agent.
\param agentID The agent's ID
\returns The function returns the ID of the goal of the specified agent. */
int getAgentGoal(int agentID) const;
/*! Sets the goal of an agent.
\param agentID The agent's ID
\param goalID The ID of the new goal of the agent
*/
void setAgentGoal(int agentID, int goalID);
/*! Retrieving the goal radius of an agent.
\param agentID The agent's ID
\returns The function returns the goal radius of the specified agent. */
float getAgentGoalRadius(int agentID) const;
/*! Sets the goal radius of an agent.
\param agentID The agent's ID
\param goalRadius The new goal radius of the agent
*/
void setAgentGoalRadius(int agentID, float goalRadius);
/*! Retrieving the preferred speed of an agent.
\param agentID The agent's ID
\returns The function returns the preferred speed of the specified agent. */
float getAgentPrefSpeed(int agentID) const;
/*! Sets the preferred speed of an agent.
\param agentID The agent's ID
\param prefSpeed The new preferred speed of the agent
*/
void setAgentPrefSpeed(int agentID, float prefSpeed);
/*! Retrieving the maximum speed of an agent.
\param agentID The agent's ID
\returns The function returns the maximum speed of the specified agent. */
float getAgentMaxSpeed(int agentID) const;
/*! Sets the maximum speed of an agent.
\param agentID The agent's ID
\param maxSpeed The new maximum speed of the agent
*/
void setAgentMaxSpeed(int agentID, float maxSpeed);
/*! Retrieving the maximum acceleration of an agent.
\param agentID The agent's ID
\returns The function returns the acceleration of the specified agent. */
float getAgentMaxAccel(int agentID) const;
/*! Sets the maximum acceleration of an agent.
\param agentID The agent's ID
\param maxAccel The new maximum acceleration of the agent
*/
void setAgentMaxAccel(int agentID, float maxAccel);
/*! Retrieving the safety factor of an agent.
\param agentID The agent's ID
\returns The function returns the safety factor of the specified agent. */
float getAgentSafetyFactor(int agentID) const;
/*! Sets the safety factor of an agent.
\param agentID The agent's ID
\param safetyFactor The new safety factor of the agent
*/
void setAgentSafetyFactor(int agentID, float safetyFactor);
// Goal getters
/*! \returns The function returns the number of goals in the simulation. */
int getNumGoals() const;
/*! Retrieving the position of a goal.
\param goalID The goal's ID
\returns The function returns the position of the specified goal. */
const Vector2& getGoalPosition(int goalID) const;
/*! Retrieving the number of roadmap vertices connected to a goal.
\param goalID The goal's ID
\returns The function returns the number of vertices in the roadmap that are neighbors of the specified goal. */
int getGoalNumNeighbors(int goalID) const;
/*! Retrieving the ID of a roadmap vertex connected to a goal.
\param goalID The goal's ID
\param neighborNr The neighbor number
\returns The ID of the vertex in the roadmap that is the neighborNr'th neighbor of the specified goal. */
int getGoalNeighbor(int goalID, int neighborNr) const;
// Obstacle Getter/Setter 's
/*! \returns The function returns the number of obstacles in the simulation. */
int getNumObstacles() const;
/*! Retrieving the first endpoint of an obstacle.
\param obstacleID The obstacle's ID
\returns The function returns the position of the first endpoint of the specified obstacle. */
const Vector2& getObstaclePoint1(int obstacleID) const;
/*! Retrieving the second endpoint of an obstacle.
\param obstacleID The obstacle's ID
\returns The function returns the position of the second endpoint of the specified obstacle. */
const Vector2& getObstaclePoint2(int obstacleID) const;
// Roadmap Getters/Setter 's
/*! \returns The function returns the number of vertices in the roadmap of the simulation. */
int getNumRoadmapVertices() const;
/*! Retrieving the position of a vertex in the roadmap.
\param vertexID The vertex' ID
\returns The function returns the position of the specified roadmap vertex. */
const Vector2& getRoadmapVertexPosition(int vertexID) const;
/*! Retrieving the number of roadmap vertices connected to a vertex in the roadmap.
\param vertexID The vertex' ID
\returns The function returns the number of neighbors of the specified vertex in the roadmap. */
int getRoadmapVertexNumNeighbors(int vertexID) const;
/*! Retrieving the ID of a roadmap vertex connected to a vertex in the roadmap.
\param vertexID The vertex' ID
\param neighborNr The neighbor number
\returns The ID of the vertex in the roadmap that is the neighborNr'th neighbor of the specified roadmap vertex. */
int getRoadmapVertexNeighbor(int vertexID, int neighborNr) const;
private:
/* Private constructor: used to implement Singleton Pattern
*/
RVOSimulator();
/* Singleton pointer to the RVOSimulator
*/
static RVOSimulator* _pinstance;
/* Set of goals in the simulation */
std::vector<RVO::Goal*> _goals;
/* Set of agents in the simulation */
std::vector<RVO::Agent*> _agents;
/* Set of obstacles in the simulation*/
std::vector<RVO::Obstacle*> _obstacles;
/* The roadmap in the simulation */
Roadmap* _roadmap;
/* The datastructure used for efficient neighbor searching */
KDTree* _kdTree;
/* The default agent parameters for newly added agents */
Agent* _defaultAgent;
/* The current time for the simulator */
float _globalTime;
/* Boolean which reports if all agents are at their goal during this time step. */
bool _allAtGoals;
/* The size of the time step in the simulation */
float _timeStep;
/* A flag storing whether the agent defaults have been set */
bool _agentDefaultsHaveBeenSet;
/* A flag storing whether the simulation has been initialized */
bool _simulationHasBeenInitialized;
friend class Agent;
friend class Roadmap;
friend class RoadmapVertex;
friend class SweeplineComparator;
friend class Obstacle;
friend class Goal;
friend class KDTree;
};
} // namespace RVO
#endif
/*! \mainpage RVO Library Documentation
\author Jur van den Berg
The RVO Library provides an easy-to-use implementation of the Reciprocal Velocity Obstacle (RVO)
framework for multi-agent simulation. See http://gamma.cs.unc.edu/RVO/ for papers and demos of the technique.
The library automatically uses parallellism if your machine has multiple processors for computing the motions of the agents.
The library is very easy to use. Please follow the following steps to install and use the library.
- \subpage compiling
- \subpage using
- \subpage params
See the documentation on the RVO::RVOSimulator class for an exhaustive list of public functions of the library.
*/
//-----------------------------------------------------------
/*! \page compiling Compiling the RVO Library
In this section we describe how the RVO library is compiled on various platforms.
\section vs2005 Windows - Visual Studio 2005
Perform the following steps to successfully compile the RVO simulation library.
- Unzip the downloaded file into some directory, here referred to as \$DIR.
- Open the solution \$DIR\\RVOLIB\\RVOLIB.sln into Visual Studio 2005, and select the Release configuration (or alternatively ReleaseST if you do not want to use parallellization).
- Build the solution. This creates a library file rvo.lib (or rvo_st.lib for the single threaded version) in the \$DIR\\lib directory, and copies the header files RVOSimulator.h and vector2.h to the \$DIR\\include directory.
- Use the rvo.lib file, along with the header files RVOSimulator.h and vector2.h in a third party project.
In the section on \ref using "using the RVO simulation library", there is information on how to use the library functionality in your project.
*/
//-----------------------------------------------------------
/*! \page using Using the RVO Library
In this section we describe how the RVO library can be used in your software to simulate agents.
\section rvostructure Structure
A program performing an RVO simulation has the following global structure.
\code
#include "RVOSimulator.h"
int main() {
// Create a simulator instance
RVO::RVOSimulator * sim = RVO::RVOSimulator::Instance();
// Set up the scenario
setupScenario( sim );
// Initialize the simulation
sim->initSimulation();
// Perform (and manipulate) the simulation
do {
updateVisualization( sim );
sim->doStep();
} while ( !sim->getReachedGoal() );
delete sim;
}
\endcode
In order to use the RVO simulator, the user needs to include "RVOSimulator.h".
The first step then is to create an instance of an RVOSimulator.
Then, the process consists of two stages. The first stage is specifying the simulation scenario and its parameters.
In the above example progam, this is done in the method setupScenario, which we will discuss below.
The second stage is the actual performing of the simulation. To finalize the scenario setup and enter
the simulation mode, the simulation has to be initialized by calling RVO::RVOSimulator::initSimulation().
Now, the actual simulation can be performed. In the above example program, simulation steps are taken until
all the agents have reached their goals. Note that it is not allowed to call RVO::RVOSimulator::doStep() before initializing the simulation.
During the simulation, the user may want to retrieve information from the simulation for instance to visualize
the simulation. In the above example program, this is done in the method updateVisualization, which we will discuss below.
It is also possible to manipulate the simulation during the simulation, for instance by changing positions, preferred speeds, goals, etc. of the agents.
\section spec Setting up the Simulation Scenario
A scenario that is to be simulated can be set up as follows. A scenario consists of four types of objects:
goals, agents, obstacles and a roadmap to steer the agents around obstacles.
Each of them can be manually specified. The following example creates a scenario with four agents exchanging positions
around a rectangular obstacle in the middle.
\code
void setupScenario( RVO::RVOSimulator * sim ) {
// Specify global time step of the simulation
sim->setTimeStep( 0.25f );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -