Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | Friends | List of all members
Menge::NavMeshEdge Class Reference

The navigation mesh adjacency graph edge. More...

#include <NavMeshEdge.h>

Public Member Functions

 NavMeshEdge ()
 Constructor.
 
 ~NavMeshEdge ()
 Destructor.
 
Vector2 getP0 () const
 Returns the first edge point. More...
 
Vector2 getP0 (float dist) const
 Returns a point inset from the first end point. More...
 
Vector2 getP1 () const
 Returns the second edge point. More...
 
Vector2 getP1 (float dist) const
 Returns a point inset from the second end point. More...
 
Vector2 getDirection () const
 Returns the direction of the edge. More...
 
NavMeshNodegetFirstNode () const
 Returns the first attached NavMeshNode. More...
 
NavMeshNodegetOtherByID (unsigned int id) const
 Returns a pointer to the node on the opposite end of the edge from the given node (by id). More...
 
NavMeshNodegetOtherByPtr (const NavMeshNode *node)
 Returns a pointer to the node on the opposite end of the edge from the given node (by pointer). More...
 
const NavMeshNodegetOtherByPtr (const NavMeshNode *node) const
 Returns a const pointer to the node on the opposite end of the edge from the given node (by pointer). More...
 
void setPoint (const Vector2 &p)
 Sets the edge's point value. More...
 
void setDirection (const Vector2 &d)
 Sets the edge's direction value. More...
 
void setWidth (float w)
 Sets the edge's width value. More...
 
float getWidth () const
 Reports the width of the edge. More...
 
void setNodes (NavMeshNode *n0, NavMeshNode *n1)
 Sets the connected node pointers. More...
 
Vector2 getPoint (float t) const
 Selects a point along the edge. More...
 
bool pointClear (const Vector2 &pos, float radius, float param) const
 Reports if the point q = _point + param * _dir is clear for an agent with the given radius positioned at pos. "Clear" means a straight-line path will not cause it to intersect the ends of the edge. More...
 
Vector2 targetPoint (const Vector2 &pos, float radius) const
 Computes a target point with respect to this edge. The target point is a point along the line of the edge to which the agent with the given radius can head straight towards and be guaranteed NOT to intersect with the end points of the edge. It also leads the agent to get closer to crossing the edge. More...
 
Vector2 getClearDirection (const Vector2 &pos, float radius, const Vector2 &dir) const
 Computes the collision-free velocity towards the portal based on the agent radius and the preferred direction. If the preferred direction is collision free, it is returned. Otherwise, the "best" collision-free approximation of that direction is returned. More...
 
void setClearDirections (const Vector2 &pos, float radius, const Vector2 &dir, Agents::PrefVelocity &pVel) const
 Sets the directions of a preferred velocity that passes through the edge biased towards the indicated direction. More...
 
float getSqDist (const Vector2 &pt) const
 Reports the squared distance to the edge from the given point. More...
 
float getSqDist (const Vector2 &pt, Vector2 &nearPt) const
 Reports the squared distance to the edge from the given point and gives the nearest point. More...
 
float getDist (const Vector2 &pt) const
 Reports the distance to the edge from the given point. More...
 
float getNodeDistance (float minWidth)
 Computes the width-dependent distance between the two nodes connected by this edge. If the edge width is narrower than the given minimum width the distance is "infinite" (indicated by -1). Otherwise it is the distance between node centers. More...
 
float getNodeDistance () const
 Return the Euclidian distance between the two nodes this edge connects. More...
 
bool loadFromAscii (std::ifstream &f, Vector2 *vertices)
 Sets the edge properties from an edge definition in the given ascii file stream. More...
 
bool pointOnLeft (unsigned int id) const
 Reports if _point in this edge is on the left for the node with the given id. More...
 
bool pointOnLeft (const NavMeshNode *node) const
 Reports if _point in this edge is on the left when looked at from within the given node. More...
 

Protected Attributes

Vector2 _point
 The point that defines the portal geometry. The portal is defined as p(t) = _point + t * _dir, t in the range [0, _width].
 
Vector2 _dir
 The unit-length direction of the portal. See _point for how the portal is defined w.r.t. this field member.
 
float _width
 The width of the portal.
 
float _distance
 The "distance" between the two nodes connected by this edge. Used to estimate the cost of a path (the length of the path).
 
NavMeshNode_node0
 A pointer to the first nav mesh node connected by this edge. When standing in this node, the edge's _point is on the left.
 
NavMeshNode_node1
 A pointer to the second nav mesh node connected by this edge. When standing in this node, the edge's _point is on the right.
 

Friends

class NavMesh
 

Detailed Description

The navigation mesh adjacency graph edge.

It is comprised of two parts: the portal geometry and the logical graph connectivity. A NavMeshEdge exists because two navigation mesh polygons share a common edge. The portal geometry is the edge. The graph connectivity indicates that the two mesh polygons (nodes) are connected in the logical graph.

Member Function Documentation

Vector2 Menge::NavMeshEdge::getClearDirection ( const Vector2 pos,
float  radius,
const Vector2 dir 
) const

Computes the collision-free velocity towards the portal based on the agent radius and the preferred direction. If the preferred direction is collision free, it is returned. Otherwise, the "best" collision-free approximation of that direction is returned.

Parameters
posThe position of the agent.
radiusThe radius of the agent.
dirPreferred direction of the agent. Direction is NOT assumed to be of unit-length.
Returns
The collision-free direction that best approximates the preferred direction (may be the preferred direction).
Vector2 Menge::NavMeshEdge::getDirection ( ) const
inline

Returns the direction of the edge.

Returns
The edge's direction.
float Menge::NavMeshEdge::getDist ( const Vector2 pt) const
inline

Reports the distance to the edge from the given point.

Parameters
ptThe point to compute from.
Returns
The squared distance between p and the nearest point on the edge.
NavMeshNode* Menge::NavMeshEdge::getFirstNode ( ) const
inline

Returns the first attached NavMeshNode.

Returns
A pointer to the first navigation mesh node.
float Menge::NavMeshEdge::getNodeDistance ( float  minWidth)

Computes the width-dependent distance between the two nodes connected by this edge. If the edge width is narrower than the given minimum width the distance is "infinite" (indicated by -1). Otherwise it is the distance between node centers.

Parameters
minWidthThe minimum required width.
Returns
The passable distance between the two nodes.
float Menge::NavMeshEdge::getNodeDistance ( ) const
inline

Return the Euclidian distance between the two nodes this edge connects.

Returns
The distance between the two connected node's centers.
NavMeshNode * Menge::NavMeshEdge::getOtherByID ( unsigned int  id) const

Returns a pointer to the node on the opposite end of the edge from the given node (by id).

If the given node is not actually adjacent to the edge, then the first adjacent node is returned.

Parameters
idThe identifier of the operand node.
Returns
A pointer to the node on the other side of the edge.
NavMeshNode * Menge::NavMeshEdge::getOtherByPtr ( const NavMeshNode node)

Returns a pointer to the node on the opposite end of the edge from the given node (by pointer).

If the given node is not actually adjacent to the edge, then the first adjacent node is returned.

Parameters
nodeA pointer to the operand node.
Returns
A pointer to the node on the other side of the edge.
const NavMeshNode * Menge::NavMeshEdge::getOtherByPtr ( const NavMeshNode node) const

Returns a const pointer to the node on the opposite end of the edge from the given node (by pointer).

If the given node is not actually adjacent to the edge, then the first adjacent node is returned.

Parameters
nodeA pointer to the operand node.
Returns
A const pointer to the node on the other side of the edge.
Vector2 Menge::NavMeshEdge::getP0 ( ) const
inline

Returns the first edge point.

Returns
The 2D value of the first edge end point
Vector2 Menge::NavMeshEdge::getP0 ( float  dist) const
inline

Returns a point inset from the first end point.

Parameters
distThe inset distance.
Returns
The 2D value of the point inset dist from the first edge end point
Vector2 Menge::NavMeshEdge::getP1 ( ) const
inline

Returns the second edge point.

Returns
The 2D value of the second edge end point
Vector2 Menge::NavMeshEdge::getP1 ( float  dist) const
inline

Returns a point inset from the second end point.

Parameters
distThe inset distance.
Returns
The 2D value of the point inset dist from the second edge end point
Vector2 Menge::NavMeshEdge::getPoint ( float  t) const
inline

Selects a point along the edge.

Parameters
tThe parameter from _point in the edge direction.
Returns
The point which is: _point + t * _dir;
float Menge::NavMeshEdge::getSqDist ( const Vector2 pt) const

Reports the squared distance to the edge from the given point.

Parameters
ptThe point to compute from.
Returns
The squared distance between p and the nearest point on the edge.
float Menge::NavMeshEdge::getSqDist ( const Vector2 pt,
Vector2 nearPt 
) const

Reports the squared distance to the edge from the given point and gives the nearest point.

Parameters
ptThe point to compute from.
nearPtThe nearest point to pt on the edge. The values of this vector will be changed by the function
Returns
The squared distance between p and the nearest point on the edge.
float Menge::NavMeshEdge::getWidth ( ) const
inline

Reports the width of the edge.

Returns
The width of the edge.
bool Menge::NavMeshEdge::loadFromAscii ( std::ifstream &  f,
Vector2 vertices 
)

Sets the edge properties from an edge definition in the given ascii file stream.

Parameters
fThe input file stream.
verticesThe array of vertices into which the definition indexes.
Returns
A boolean indicating successful parsing (true) or failure (false).
bool Menge::NavMeshEdge::pointClear ( const Vector2 pos,
float  radius,
float  param 
) const

Reports if the point q = _point + param * _dir is clear for an agent with the given radius positioned at pos. "Clear" means a straight-line path will not cause it to intersect the ends of the edge.

Parameters
posThe position of the agent.
radiusThe radius of the agent.
paramThe parameter, along the edge's direction, of the desired goal point.
Returns
A boolean reporting if the straight line path is clear (true) or occlued (false).
bool Menge::NavMeshEdge::pointOnLeft ( unsigned int  id) const

Reports if _point in this edge is on the left for the node with the given id.

Parameters
idThe id of the node to test. (The id is assumed to be connected. It is only checked in debug mode.)
Returns
A boolean reporting if the point in the edge is on the left when facing the edge from the node with the given id.
bool Menge::NavMeshEdge::pointOnLeft ( const NavMeshNode node) const

Reports if _point in this edge is on the left when looked at from within the given node.

Parameters
nodeThe pointer to the node to test. (The id is assumed to be connected. It is only checked in debug mode.)
Returns
A boolean reporting if the point in the edge is on the left when facing the edge from the node with the given id.
void Menge::NavMeshEdge::setClearDirections ( const Vector2 pos,
float  radius,
const Vector2 dir,
Agents::PrefVelocity pVel 
) const

Sets the directions of a preferred velocity that passes through the edge biased towards the indicated direction.

If approaching the portal obliquely, the preferred direction may not provide sufficient clearance. In this case, the direction is changed so the agent makes progress toward the portal without colliding with the portal limits.

At the same time, sets the limits of the preferred velocity based on the actual clearance.

Parameters
posThe position of the agent.
radiusThe radius of the agent.
dirPreferred direction of the agent. Direction is NOT assumed to be of unit-length.
pVelThe preferred velocity whose directions are set.
void Menge::NavMeshEdge::setDirection ( const Vector2 d)
inline

Sets the edge's direction value.

Parameters
dThe direction value to set. It is assumed to be normalized and is not tested.
void Menge::NavMeshEdge::setNodes ( NavMeshNode n0,
NavMeshNode n1 
)
inline

Sets the connected node pointers.

Parameters
n0The pointer to the first connected node.
n1The pointer to the second connected node.
void Menge::NavMeshEdge::setPoint ( const Vector2 p)
inline

Sets the edge's point value.

Parameters
pThe point value to set.
void Menge::NavMeshEdge::setWidth ( float  w)
inline

Sets the edge's width value.

Parameters
wThe width value to set.
Vector2 Menge::NavMeshEdge::targetPoint ( const Vector2 pos,
float  radius 
) const

Computes a target point with respect to this edge. The target point is a point along the line of the edge to which the agent with the given radius can head straight towards and be guaranteed NOT to intersect with the end points of the edge. It also leads the agent to get closer to crossing the edge.

Parameters
posThe position from which to compute nearest point.
radiusThe radius of the agent – required clearance.
Returns
A point which represents the goal point the agent should walk towards to clear the obstacles and pass through the edge.

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