📄 rvosimulator.h
字号:
// Specify default parameters for agents that are subsequently added
sim->setAgentDefaults( 250, 15.0f, 10, 2.0f, 3.0f, 1.0f, 2.0f, 7.5f, 1.0f );
// Add agents (and simulataneously their goals), specifying their start position and goal ID
sim->addAgent( RVO::Vector2(-50.0f, -50.0f), sim->addGoal( RVO::Vector2(50.0f, 50.0f) ) );
sim->addAgent( RVO::Vector2(50.0f, -50.0f), sim->addGoal( RVO::Vector2(-50.0f, 50.0f) ) );
sim->addAgent( RVO::Vector2(50.0f, 50.0f), sim->addGoal( RVO::Vector2(-50.0f, -50.0f) ) );
sim->addAgent( RVO::Vector2(-50.0f, 50.0f), sim->addGoal( RVO::Vector2(50.0f, -50.0f) ) );
// Add (line segment) obstacles, specifying both endpoints of the line segments
sim->addObstacle( RVO::Vector2(-7.0f, -20.0f), RVO::Vector2(-7.0f, 20.0f) );
sim->addObstacle( RVO::Vector2(-7.0f, 20.0f), RVO::Vector2(7.0f, 20.0f) );
sim->addObstacle( RVO::Vector2(7.0f, 20.0f), RVO::Vector2(7.0f, -20.0f) );
sim->addObstacle( RVO::Vector2(7.0f, -20.0f), RVO::Vector2(-7.0f, -20.0f) );
// Add roadmap vertices, specifying their position
sim->addRoadmapVertex( RVO::Vector2(-10.0f, -23.0f) );
sim->addRoadmapVertex( RVO::Vector2(-10.0f, 23.0f) );
sim->addRoadmapVertex( RVO::Vector2(10.0f, 23.0f) );
sim->addRoadmapVertex( RVO::Vector2(10.0f, -23.0f) );
// Do not automatically create edges between mutually visible roadmap vertices
sim->setRoadmapAutomatic( false );
// Manually specify edges between vertices, specifying the ID's of the vertices the edges connect
sim->addRoadmapEdge( 0, 1 );
sim->addRoadmapEdge( 1, 2 );
sim->addRoadmapEdge( 2, 3 );
sim->addRoadmapEdge( 3, 0 );
}
\endcode
See the documentation on RVO::RVOSimulator for a full overview of the functionality to specify scenarios.
\section ret Retrieving Information from the Simulation
During the simulation, the user can extract information from the simulation for instance for visualization purposes.
In the example program above, this is done in the updateVisualization method. Here we give an example that simply writes
the positions and orientations of each agent in each time step to the standard output.
\code
void updateVisualization( RVO::RVOSimulator * sim ) {
// Output the current global time
std::cout << sim->getGlobalTime() << " ";
// Output the position and orientation for all the agents
for (int i = 0; i < sim->getNumAgents(); ++i) {
std::cout << sim->getAgentPosition( i ) << " " << sim->getAgentOrientation( i ) << " ";
}
std::cout << std::endl;
}
\endcode
Using similar functions as the ones used in this example, the user can access information about other parameters of the agents, as well as the global parameters, the obstacles and the roadmap.
See the documentation of the class RVO::RVOSimulator for an exhaustive list of public functions for retrieving simulation information.
\section manip Manipulating the Simulation
During the simulation, the user can manipulate the simulation, for instance by changing the global parameters, or changing the parameters of the agents (causing abrupt different behavior).
It is also possible to give the agents a new position, which make them jump through the scene. See the documentation of the class RVO::RVOSimulator for an exhaustive list of public functions for manipulating the simulation.
It is not allowed to add goals, agents, obstacles or roadmap vertices to the simulation, after the simulation has been initialized by calling RVO::RVOSimulator::initSimulation(). Also, it is impossible to change the position of the goals, obstacles or the roadmap vertices.
*/
//-----------------------------------------------------------
/*! \page params Parameter Description
In this section, we give an overview of all parameters of all objects in the simulation.
\section global Global Parameters
\htmlonly
<table border="0" cellpadding="3" width="100%">
<tr>
<td valign="top" width="150"><strong>Parameter</strong></td>
<td valign="top" width="150"><strong>Type (unit)</strong></td>
<td valign="top"><strong>Meaning</strong></td>
</tr>
<tr>
<td valign="top">timeStep</td>
<td valign="top">float (time)</td>
<td valign="top">The time step of the simulation.</td>
</tr>
</table>
\endhtmlonly
\section goal Goal Parameters
\htmlonly
<table border="0" cellpadding="3" width="100%">
<tr>
<td valign="top" width="150"><strong>Parameter</strong></td>
<td valign="top" width="150"><strong>Type (unit)</strong></td>
<td valign="top"><strong>Meaning</strong></td>
</tr>
<tr>
<td valign="top" width="150">position</td>
<td valign="top" width="150">Vector2 (distance, distance)</td>
<td valign="top">The position of the goal.</td>
</tr>
</table>
\endhtmlonly
\section agent Agent Parameters
\htmlonly
<table border="0" cellpadding="3" width="100%">
<tr>
<td valign="top" width="150"><strong>Parameter</strong></td>
<td valign="top" width="150"><strong>Type (unit)</strong></td>
<td valign="top"><strong>Meaning</strong></td>
</tr>
<tr>
<td valign="top" width="150">position</td>
<td valign="top" width="150">Vector2 (distance, distance)</td>
<td valign="top">The (current) position of the agent.</td>
</tr>
<tr>
<td valign="top">goalID</td>
<td valign="top">int</td>
<td valign="top">The ID of the goal of the agent.</td>
</tr>
<tr>
<td valign="top">velSampleCount</td>
<td valign="top">int</td>
<td valign="top">The number of candidate velocities the
agent samples in each time step of the simulation. The higher the number,
the more accurate the simulation. The running time of the simulation
increases linearly with this number.</td>
</tr>
<tr>
<td valign="top">neighborDist</td>
<td valign="top">float (distance)</td>
<td valign="top">The distance within which other agents
and obstacles are taken into account in selecting a
velocity. The larger this number, the larger the running
time of the simulation. If the number is too low, the
simulation will not be safe.</td>
</tr>
<tr>
<td valign="top">maxNeighbors</td>
<td valign="top">int</td>
<td valign="top">
The maximum number of neighboring agents and obstacles that are taken into account
in selecting a velocity. The larger this number, the larger the running time of
the simulation. If the number is too low, the simulation will not be safe.</td>
</tr>
<tr>
<td valign="top">radius</td>
<td valign="top">float (distance)</td>
<td valign="top">The radius of the agent.</td>
</tr>
<tr>
<td valign="top">goalRadius</td>
<td valign="top">float (distance)</td>
<td valign="top">The radius of the goal region around the goal position of the agent. An agent is defined to have reached its goal when it is within a distance goalRadius from its goal position.</td>
</tr>
<tr>
<td valign="top">prefSpeed</td>
<td valign="top">float (distance/time)</td>
<td valign="top">The preferred speed of the agent.</td>
</tr>
<tr>
<td valign="top">maxSpeed</td>
<td valign="top">float (distance/time)</td>
<td valign="top">The maximum speed of the agent.</td>
</tr>
<tr>
<td valign="top">safetyFactor</td>
<td valign="top">float (distance)</td>
<td valign="top">The weight that is given to the "time to collision" when penalizing a candidate
velocity for the agent (vs. the distance to the preferred velocity). The higher this value, the "safer"
or the "shyer" the agent is. The lower this value, the more "aggressive" and "reckless" the agent is. Its unit is distance.</td>
</tr>
<tr>
<td valign="top">maxAccel</td>
<td valign="top">float (distance/time<sup>2</sup>)</td>
<td valign="top">The maximum acceleration of the agent.</td>
</tr>
<tr>
<td valign="top" width="150">velocity</td>
<td valign="top" width="150">Vector2 (distance/time, distance/time)</td>
<td valign="top">The (current) velocity of the agent.</td>
</tr>
<tr>
<td valign="top">orientation</td>
<td valign="top">float (radians)</td>
<td valign="top">The (current) orientation of the agent.</td>
</tr>
<tr>
<td valign="top">class</td>
<td valign="top">int</td>
<td valign="top">The class of the agent. The class can be used by a visualizer to distinguish among different classes of agents. Its value does not have any effect on the simulation.</td>
</tr>
</table>
\endhtmlonly
\section obst Obstacle Parameters
\htmlonly
<table border="0" cellpadding="3" width="100%">
<tr>
<td valign="top" width="150"><strong>Parameter</strong></td>
<td valign="top" width="150"><strong>Type (unit)</strong></td>
<td valign="top"><strong>Meaning</strong></td>
</tr>
<tr>
<td valign="top" width="150">point1</td>
<td valign="top" width="150">Vector2 (distance, distance)</td>
<td valign="top">The first endpoint of the line segment obstacle.</td>
</tr>
<tr>
<td valign="top" width="150">point2</td>
<td valign="top" width="150">Vector2 (distance, distance)</td>
<td valign="top">The second endpoint of the line segment obstacle.</td>
</tr>
</table>
\endhtmlonly
\section roadmap Roadmap Parameters
\htmlonly
<table border="0" cellpadding="3" width="100%">
<tr>
<td valign="top" width="150"><strong>Parameter</strong></td>
<td valign="top" width="150"><strong>Type (unit)</strong></td>
<td valign="top"><strong>Meaning</strong></td>
</tr>
<tr>
<td valign="top">automatic</td>
<td valign="top">bool</td>
<td valign="top">Indicates whether the mutually visible vertices of the roadmap should automatically be connected upon initializing the simulation.</td>
</tr>
</table>
\endhtmlonly
\section vertex Roadmap Vertex Parameters
\htmlonly
<table border="0" cellpadding="3" width="100%">
<tr>
<td valign="top" width="150"><strong>Parameter</strong></td>
<td valign="top" width="150"><strong>Type (unit)</strong></td>
<td valign="top"><strong>Meaning</strong></td>
</tr>
<tr>
<td valign="top" width="150">position</td>
<td valign="top" width="150">Vector2 (distance, distance)</td>
<td valign="top">The position of the roadmap vertex.</td>
</tr>
</table>
\endhtmlonly
\section edge Roadmap Edge Parameters
\htmlonly
<table border="0" cellpadding="3" width="100%">
<tr>
<td valign="top" width="150"><strong>Parameter</strong></td>
<td valign="top" width="150"><strong>Type (unit)</strong></td>
<td valign="top"><strong>Meaning</strong></td>
</tr>
<tr>
<td valign="top">vertexID1</td>
<td valign="top">int</td>
<td valign="top">The ID of the first roadmap vertex of the edge.</td>
</tr>
<tr>
<td valign="top">vertexID2</td>
<td valign="top">int</td>
<td valign="top">The ID of the second roadmap vertex of the edge.</td>
</tr>
</table>
\endhtmlonly
Note that the edges are undirected.
*/
//-----------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -