Public Member Functions | Friends | List of all members
RVO::RVOSimulator Class Reference

Defines the simulation. More...

#include <RVOSimulator.h>

Public Member Functions

 RVOSimulator ()
 Constructs a simulator instance.
 
 RVOSimulator (float timeStep, float neighborDist, size_t maxNeighbors, float timeHorizon, float timeHorizonObst, float radius, float maxSpeed, const Vector2 &velocity=Vector2())
 Constructs a simulator instance and sets the default properties for any new agent that is added. More...
 
 ~RVOSimulator ()
 Destroys this simulator instance.
 
size_t addAgent (const Vector2 &position)
 Adds a new agent with default properties to the simulation. More...
 
size_t addAgent (const Vector2 &position, float neighborDist, size_t maxNeighbors, float timeHorizon, float timeHorizonObst, float radius, float maxSpeed, const Vector2 &velocity=Vector2())
 Adds a new agent to the simulation. More...
 
size_t addObstacle (const std::vector< Vector2 > &vertices)
 Adds a new obstacle to the simulation. More...
 
void doStep ()
 Lets the simulator perform a simulation step and updates the two-dimensional position and two-dimensional velocity of each agent.
 
size_t getAgentAgentNeighbor (size_t agentNo, size_t neighborNo) const
 Returns the specified agent neighbor of the specified agent. More...
 
size_t getAgentMaxNeighbors (size_t agentNo) const
 Returns the maximum neighbor count of a specified agent. More...
 
float getAgentMaxSpeed (size_t agentNo) const
 Returns the maximum speed of a specified agent. More...
 
float getAgentNeighborDist (size_t agentNo) const
 Returns the maximum neighbor distance of a specified agent. More...
 
size_t getAgentNumAgentNeighbors (size_t agentNo) const
 Returns the count of agent neighbors taken into account to compute the current velocity for the specified agent. More...
 
size_t getAgentNumObstacleNeighbors (size_t agentNo) const
 Returns the count of obstacle neighbors taken into account to compute the current velocity for the specified agent. More...
 
size_t getAgentNumORCALines (size_t agentNo) const
 Returns the count of ORCA constraints used to compute the current velocity for the specified agent. More...
 
size_t getAgentObstacleNeighbor (size_t agentNo, size_t neighborNo) const
 Returns the specified obstacle neighbor of the specified agent. More...
 
const LinegetAgentORCALine (size_t agentNo, size_t lineNo) const
 Returns the specified ORCA constraint of the specified agent. More...
 
const Vector2getAgentPosition (size_t agentNo) const
 Returns the two-dimensional position of a specified agent. More...
 
const Vector2getAgentPrefVelocity (size_t agentNo) const
 Returns the two-dimensional preferred velocity of a specified agent. More...
 
float getAgentRadius (size_t agentNo) const
 Returns the radius of a specified agent. More...
 
float getAgentTimeHorizon (size_t agentNo) const
 Returns the time horizon of a specified agent. More...
 
float getAgentTimeHorizonObst (size_t agentNo) const
 Returns the time horizon with respect to obstacles of a specified agent. More...
 
const Vector2getAgentVelocity (size_t agentNo) const
 Returns the two-dimensional linear velocity of a specified agent. More...
 
float getGlobalTime () const
 Returns the global time of the simulation. More...
 
size_t getNumAgents () const
 Returns the count of agents in the simulation. More...
 
size_t getNumObstacleVertices () const
 Returns the count of obstacle vertices in the simulation. More...
 
const Vector2getObstacleVertex (size_t vertexNo) const
 Returns the two-dimensional position of a specified obstacle vertex. More...
 
size_t getNextObstacleVertexNo (size_t vertexNo) const
 Returns the number of the obstacle vertex succeeding the specified obstacle vertex in its polygon. More...
 
size_t getPrevObstacleVertexNo (size_t vertexNo) const
 Returns the number of the obstacle vertex preceding the specified obstacle vertex in its polygon. More...
 
float getTimeStep () const
 Returns the time step of the simulation. More...
 
void processObstacles ()
 Processes the obstacles that have been added so that they are accounted for in the simulation. More...
 
bool queryVisibility (const Vector2 &point1, const Vector2 &point2, float radius=0.0f) const
 Performs a visibility query between the two specified points with respect to the obstacles. More...
 
void setAgentDefaults (float neighborDist, size_t maxNeighbors, float timeHorizon, float timeHorizonObst, float radius, float maxSpeed, const Vector2 &velocity=Vector2())
 Sets the default properties for any new agent that is added. More...
 
void setAgentMaxNeighbors (size_t agentNo, size_t maxNeighbors)
 Sets the maximum neighbor count of a specified agent. More...
 
void setAgentMaxSpeed (size_t agentNo, float maxSpeed)
 Sets the maximum speed of a specified agent. More...
 
void setAgentNeighborDist (size_t agentNo, float neighborDist)
 Sets the maximum neighbor distance of a specified agent. More...
 
void setAgentPosition (size_t agentNo, const Vector2 &position)
 Sets the two-dimensional position of a specified agent. More...
 
void setAgentPrefVelocity (size_t agentNo, const Vector2 &prefVelocity)
 Sets the two-dimensional preferred velocity of a specified agent. More...
 
void setAgentRadius (size_t agentNo, float radius)
 Sets the radius of a specified agent. More...
 
void setAgentTimeHorizon (size_t agentNo, float timeHorizon)
 Sets the time horizon of a specified agent with respect to other agents. More...
 
void setAgentTimeHorizonObst (size_t agentNo, float timeHorizonObst)
 Sets the time horizon of a specified agent with respect to obstacles. More...
 
void setAgentVelocity (size_t agentNo, const Vector2 &velocity)
 Sets the two-dimensional linear velocity of a specified agent. More...
 
void setTimeStep (float timeStep)
 Sets the time step of the simulation. More...
 

Friends

class Agent
 
class KdTree
 
class Obstacle
 

Detailed Description

Defines the simulation.

The main class of the library that contains all simulation functionality.

Constructor & Destructor Documentation

◆ RVOSimulator()

RVO::RVOSimulator::RVOSimulator ( float  timeStep,
float  neighborDist,
size_t  maxNeighbors,
float  timeHorizon,
float  timeHorizonObst,
float  radius,
float  maxSpeed,
const Vector2 velocity = Vector2() 
)

Constructs a simulator instance and sets the default properties for any new agent that is added.

Parameters
timeStepThe time step of the simulation. Must be positive.
neighborDistThe default maximum distance (center point to center point) to other agents a new agent takes into account in the navigation. The larger this number, the longer he running time of the simulation. If the number is too low, the simulation will not be safe. Must be non-negative.
maxNeighborsThe default maximum number of other agents a new agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
timeHorizonThe default minimal amount of time for which a new agent's velocities that are computed by the simulation are safe with respect to other agents. The larger this number, the sooner an agent will respond to the presence of other agents, but the less freedom the agent has in choosing its velocities. Must be positive.
timeHorizonObstThe default minimal amount of time for which a new agent's velocities that are computed by the simulation are safe with respect to obstacles. The larger this number, the sooner an agent will respond to the presence of obstacles, but the less freedom the agent has in choosing its velocities. Must be positive.
radiusThe default radius of a new agent. Must be non-negative.
maxSpeedThe default maximum speed of a new agent. Must be non-negative.
velocityThe default initial two-dimensional linear velocity of a new agent (optional).

Member Function Documentation

◆ addAgent() [1/2]

size_t RVO::RVOSimulator::addAgent ( const Vector2 position)

Adds a new agent with default properties to the simulation.

Parameters
positionThe two-dimensional starting position of this agent.
Returns
The number of the agent, or RVO::RVO_ERROR when the agent defaults have not been set.

◆ addAgent() [2/2]

size_t RVO::RVOSimulator::addAgent ( const Vector2 position,
float  neighborDist,
size_t  maxNeighbors,
float  timeHorizon,
float  timeHorizonObst,
float  radius,
float  maxSpeed,
const Vector2 velocity = Vector2() 
)

Adds a new agent to the simulation.

Parameters
positionThe two-dimensional starting position of this agent.
neighborDistThe maximum distance (center point to center point) to other agents this agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe. Must be non-negative.
maxNeighborsThe maximum number of other agents this agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
timeHorizonThe minimal amount of time for which this agent's velocities that are computed by the simulation are safe with respect to other agents. The larger this number, the sooner this agent will respond to the presence of other agents, but the less freedom this agent has in choosing its velocities. Must be positive.
timeHorizonObstThe minimal amount of time for which this agent's velocities that are computed by the simulation are safe with respect to obstacles. The larger this number, the sooner this agent will respond to the presence of obstacles, but the less freedom this agent has in choosing its velocities. Must be positive.
radiusThe radius of this agent. Must be non-negative.
maxSpeedThe maximum speed of this agent. Must be non-negative.
velocityThe initial two-dimensional linear velocity of this agent (optional).
Returns
The number of the agent.

◆ addObstacle()

size_t RVO::RVOSimulator::addObstacle ( const std::vector< Vector2 > &  vertices)

Adds a new obstacle to the simulation.

Parameters
verticesList of the vertices of the polygonal obstacle in counterclockwise order.
Returns
The number of the first vertex of the obstacle, or RVO::RVO_ERROR when the number of vertices is less than two.
Note
To add a "negative" obstacle, e.g. a bounding polygon around the environment, the vertices should be listed in clockwise order.

◆ getAgentAgentNeighbor()

size_t RVO::RVOSimulator::getAgentAgentNeighbor ( size_t  agentNo,
size_t  neighborNo 
) const

Returns the specified agent neighbor of the specified agent.

Parameters
agentNoThe number of the agent whose agent neighbor is to be retrieved.
neighborNoThe number of the agent neighbor to be retrieved.
Returns
The number of the neighboring agent.

◆ getAgentMaxNeighbors()

size_t RVO::RVOSimulator::getAgentMaxNeighbors ( size_t  agentNo) const

Returns the maximum neighbor count of a specified agent.

Parameters
agentNoThe number of the agent whose maximum neighbor count is to be retrieved.
Returns
The present maximum neighbor count of the agent.

◆ getAgentMaxSpeed()

float RVO::RVOSimulator::getAgentMaxSpeed ( size_t  agentNo) const

Returns the maximum speed of a specified agent.

Parameters
agentNoThe number of the agent whose maximum speed is to be retrieved.
Returns
The present maximum speed of the agent.

◆ getAgentNeighborDist()

float RVO::RVOSimulator::getAgentNeighborDist ( size_t  agentNo) const

Returns the maximum neighbor distance of a specified agent.

Parameters
agentNoThe number of the agent whose maximum neighbor distance is to be retrieved.
Returns
The present maximum neighbor distance of the agent.

◆ getAgentNumAgentNeighbors()

size_t RVO::RVOSimulator::getAgentNumAgentNeighbors ( size_t  agentNo) const

Returns the count of agent neighbors taken into account to compute the current velocity for the specified agent.

Parameters
agentNoThe number of the agent whose count of agent neighbors is to be retrieved.
Returns
The count of agent neighbors taken into account to compute the current velocity for the specified agent.

◆ getAgentNumObstacleNeighbors()

size_t RVO::RVOSimulator::getAgentNumObstacleNeighbors ( size_t  agentNo) const

Returns the count of obstacle neighbors taken into account to compute the current velocity for the specified agent.

Parameters
agentNoThe number of the agent whose count of obstacle neighbors is to be retrieved.
Returns
The count of obstacle neighbors taken into account to compute the current velocity for the specified agent.

◆ getAgentNumORCALines()

size_t RVO::RVOSimulator::getAgentNumORCALines ( size_t  agentNo) const

Returns the count of ORCA constraints used to compute the current velocity for the specified agent.

Parameters
agentNoThe number of the agent whose count of ORCA constraints is to be retrieved.
Returns
The count of ORCA constraints used to compute the current velocity for the specified agent.

◆ getAgentObstacleNeighbor()

size_t RVO::RVOSimulator::getAgentObstacleNeighbor ( size_t  agentNo,
size_t  neighborNo 
) const

Returns the specified obstacle neighbor of the specified agent.

Parameters
agentNoThe number of the agent whose obstacle neighbor is to be retrieved.
neighborNoThe number of the obstacle neighbor to be retrieved.
Returns
The number of the first vertex of the neighboring obstacle edge.

◆ getAgentORCALine()

const Line& RVO::RVOSimulator::getAgentORCALine ( size_t  agentNo,
size_t  lineNo 
) const

Returns the specified ORCA constraint of the specified agent.

Parameters
agentNoThe number of the agent whose ORCA constraint is to be retrieved.
lineNoThe number of the ORCA constraint to be retrieved.
Returns
A line representing the specified ORCA constraint.
Note
The halfplane to the left of the line is the region of permissible velocities with respect to the specified ORCA constraint.

◆ getAgentPosition()

const Vector2& RVO::RVOSimulator::getAgentPosition ( size_t  agentNo) const

Returns the two-dimensional position of a specified agent.

Parameters
agentNoThe number of the agent whose two-dimensional position is to be retrieved.
Returns
The present two-dimensional position of the (center of the) agent.

◆ getAgentPrefVelocity()

const Vector2& RVO::RVOSimulator::getAgentPrefVelocity ( size_t  agentNo) const

Returns the two-dimensional preferred velocity of a specified agent.

Parameters
agentNoThe number of the agent whose two-dimensional preferred velocity is to be retrieved.
Returns
The present two-dimensional preferred velocity of the agent.

◆ getAgentRadius()

float RVO::RVOSimulator::getAgentRadius ( size_t  agentNo) const

Returns the radius of a specified agent.

Parameters
agentNoThe number of the agent whose radius is to be retrieved.
Returns
The present radius of the agent.

◆ getAgentTimeHorizon()

float RVO::RVOSimulator::getAgentTimeHorizon ( size_t  agentNo) const

Returns the time horizon of a specified agent.

Parameters
agentNoThe number of the agent whose time horizon is to be retrieved.
Returns
The present time horizon of the agent.

◆ getAgentTimeHorizonObst()

float RVO::RVOSimulator::getAgentTimeHorizonObst ( size_t  agentNo) const

Returns the time horizon with respect to obstacles of a specified agent.

Parameters
agentNoThe number of the agent whose time horizon with respect to obstacles is to be retrieved.
Returns
The present time horizon with respect to obstacles of the agent.

◆ getAgentVelocity()

const Vector2& RVO::RVOSimulator::getAgentVelocity ( size_t  agentNo) const

Returns the two-dimensional linear velocity of a specified agent.

Parameters
agentNoThe number of the agent whose two-dimensional linear velocity is to be retrieved.
Returns
The present two-dimensional linear velocity of the agent.

◆ getGlobalTime()

float RVO::RVOSimulator::getGlobalTime ( ) const

Returns the global time of the simulation.

Returns
The present global time of the simulation (zero initially).

◆ getNextObstacleVertexNo()

size_t RVO::RVOSimulator::getNextObstacleVertexNo ( size_t  vertexNo) const

Returns the number of the obstacle vertex succeeding the specified obstacle vertex in its polygon.

Parameters
vertexNoThe number of the obstacle vertex whose successor is to be retrieved.
Returns
The number of the obstacle vertex succeeding the specified obstacle vertex in its polygon.

◆ getNumAgents()

size_t RVO::RVOSimulator::getNumAgents ( ) const

Returns the count of agents in the simulation.

Returns
The count of agents in the simulation.

◆ getNumObstacleVertices()

size_t RVO::RVOSimulator::getNumObstacleVertices ( ) const

Returns the count of obstacle vertices in the simulation.

Returns
The count of obstacle vertices in the simulation.

◆ getObstacleVertex()

const Vector2& RVO::RVOSimulator::getObstacleVertex ( size_t  vertexNo) const

Returns the two-dimensional position of a specified obstacle vertex.

Parameters
vertexNoThe number of the obstacle vertex to be retrieved.
Returns
The two-dimensional position of the specified obstacle vertex.

◆ getPrevObstacleVertexNo()

size_t RVO::RVOSimulator::getPrevObstacleVertexNo ( size_t  vertexNo) const

Returns the number of the obstacle vertex preceding the specified obstacle vertex in its polygon.

Parameters
vertexNoThe number of the obstacle vertex whose predecessor is to be retrieved.
Returns
The number of the obstacle vertex preceding the specified obstacle vertex in its polygon.

◆ getTimeStep()

float RVO::RVOSimulator::getTimeStep ( ) const

Returns the time step of the simulation.

Returns
The present time step of the simulation.

◆ processObstacles()

void RVO::RVOSimulator::processObstacles ( )

Processes the obstacles that have been added so that they are accounted for in the simulation.

Note
Obstacles added to the simulation after this function has been called are not accounted for in the simulation.

◆ queryVisibility()

bool RVO::RVOSimulator::queryVisibility ( const Vector2 point1,
const Vector2 point2,
float  radius = 0.0f 
) const

Performs a visibility query between the two specified points with respect to the obstacles.

Parameters
point1The first point of the query.
point2The second point of the query.
radiusThe minimal distance between the line connecting the two points and the obstacles in order for the points to be mutually visible (optional). Must be non-negative.
Returns
A boolean specifying whether the two points are mutually visible. Returns true when the obstacles have not been processed.

◆ setAgentDefaults()

void RVO::RVOSimulator::setAgentDefaults ( float  neighborDist,
size_t  maxNeighbors,
float  timeHorizon,
float  timeHorizonObst,
float  radius,
float  maxSpeed,
const Vector2 velocity = Vector2() 
)

Sets the default properties for any new agent that is added.

Parameters
neighborDistThe default maximum distance (center point to center point) to other agents a new agent takes into account in the navigation. The larger this number, the longer he running time of the simulation. If the number is too low, the simulation will not be safe. Must be non-negative.
maxNeighborsThe default maximum number of other agents a new agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
timeHorizonThe default minimal amount of time for which a new agent's velocities that are computed by the simulation are safe with respect to other agents. The larger this number, the sooner an agent will respond to the presence of other agents, but the less freedom the agent has in choosing its velocities. Must be positive.
timeHorizonObstThe default minimal amount of time for which a new agent's velocities that are computed by the simulation are safe with respect to obstacles. The larger this number, the sooner an agent will respond to the presence of obstacles, but the less freedom the agent has in choosing its velocities. Must be positive.
radiusThe default radius of a new agent. Must be non-negative.
maxSpeedThe default maximum speed of a new agent. Must be non-negative.
velocityThe default initial two-dimensional linear velocity of a new agent (optional).

◆ setAgentMaxNeighbors()

void RVO::RVOSimulator::setAgentMaxNeighbors ( size_t  agentNo,
size_t  maxNeighbors 
)

Sets the maximum neighbor count of a specified agent.

Parameters
agentNoThe number of the agent whose maximum neighbor count is to be modified.
maxNeighborsThe replacement maximum neighbor count.

◆ setAgentMaxSpeed()

void RVO::RVOSimulator::setAgentMaxSpeed ( size_t  agentNo,
float  maxSpeed 
)

Sets the maximum speed of a specified agent.

Parameters
agentNoThe number of the agent whose maximum speed is to be modified.
maxSpeedThe replacement maximum speed. Must be non-negative.

◆ setAgentNeighborDist()

void RVO::RVOSimulator::setAgentNeighborDist ( size_t  agentNo,
float  neighborDist 
)

Sets the maximum neighbor distance of a specified agent.

Parameters
agentNoThe number of the agent whose maximum neighbor distance is to be modified.
neighborDistThe replacement maximum neighbor distance. Must be non-negative.

◆ setAgentPosition()

void RVO::RVOSimulator::setAgentPosition ( size_t  agentNo,
const Vector2 position 
)

Sets the two-dimensional position of a specified agent.

Parameters
agentNoThe number of the agent whose two-dimensional position is to be modified.
positionThe replacement of the two-dimensional position.

◆ setAgentPrefVelocity()

void RVO::RVOSimulator::setAgentPrefVelocity ( size_t  agentNo,
const Vector2 prefVelocity 
)

Sets the two-dimensional preferred velocity of a specified agent.

Parameters
agentNoThe number of the agent whose two-dimensional preferred velocity is to be modified.
prefVelocityThe replacement of the two-dimensional preferred velocity.

◆ setAgentRadius()

void RVO::RVOSimulator::setAgentRadius ( size_t  agentNo,
float  radius 
)

Sets the radius of a specified agent.

Parameters
agentNoThe number of the agent whose radius is to be modified.
radiusThe replacement radius. Must be non-negative.

◆ setAgentTimeHorizon()

void RVO::RVOSimulator::setAgentTimeHorizon ( size_t  agentNo,
float  timeHorizon 
)

Sets the time horizon of a specified agent with respect to other agents.

Parameters
agentNoThe number of the agent whose time horizon is to be modified.
timeHorizonThe replacement time horizon with respect to other agents. Must be positive.

◆ setAgentTimeHorizonObst()

void RVO::RVOSimulator::setAgentTimeHorizonObst ( size_t  agentNo,
float  timeHorizonObst 
)

Sets the time horizon of a specified agent with respect to obstacles.

Parameters
agentNoThe number of the agent whose time horizon with respect to obstacles is to be modified.
timeHorizonObstThe replacement time horizon with respect to obstacles. Must be positive.

◆ setAgentVelocity()

void RVO::RVOSimulator::setAgentVelocity ( size_t  agentNo,
const Vector2 velocity 
)

Sets the two-dimensional linear velocity of a specified agent.

Parameters
agentNoThe number of the agent whose two-dimensional linear velocity is to be modified.
velocityThe replacement two-dimensional linear velocity.

◆ setTimeStep()

void RVO::RVOSimulator::setTimeStep ( float  timeStep)

Sets the time step of the simulation.

Parameters
timeStepThe time step of the simulation. Must be positive.

The documentation for this class was generated from the following file: