Menge Plugin Examples
A Collection of Example Plugins for the Menge Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Formations::FreeFormation Class Reference

The class for modeling a freestyle formation. More...

#include <FreeFormation.h>

Inheritance diagram for Formations::FreeFormation:
Menge::Resource

Public Member Functions

 FreeFormation (const std::string &name)
 Constructor. More...
 
 ~FreeFormation ()
 Destructor.
 
virtual const std::string & getLabel () const
 Reports the message label for this resource. More...
 
void addAgent (const Agents::BaseAgent *agt)
 Adds an agent to this formation. More...
 
void removeAgent (const Agents::BaseAgent *agt)
 Removes an agent from the formation. More...
 
void mapAgentsToFormation (const BFSM::FSM *fsm)
 Computes the mapping from tracked agents to formation points. More...
 
bool getGoalForAgent (const Agents::BaseAgent *agt, Agents::PrefVelocity &pVel, Vector2 &target)
 Provides an intermediate goal for the agent. More...
 

Static Public Member Functions

static Resourceload (const std::string &fileName)
 Parses a formation definition and returns a pointer to it. More...
 

Static Public Attributes

static const std::string LABEL
 The unique label for this data type to be used with resource management.
 

Protected Member Functions

void mapAgentToPoint (const Agents::BaseAgent *agt)
 Maps a single agent to a sentinel point. More...
 
void mapPointToAgent (FormationPoint *pt)
 Maps a border point to one of the agents in the formation. More...
 
void addFormationPoint (Vector2 pt, bool borderPoint, float weight)
 Adds a point to the formation. More...
 
void addAgentPoint (const Agents::BaseAgent *agt)
 Adds an agent to the formation. More...
 
void normalizeFormation ()
 Finalize the formation representation for use. More...
 
float formationDistance (FormationPoint *pt1, FormationPoint *pt2)
 A custom distance metric to apply to formation points. Used for evaluating "similarity" between formation points. More...
 

Protected Attributes

std::map< size_t, size_t > _agent_formationPoint
 Maps formation point identifiers to agent identifiers. Why identifiers?
 
std::map< size_t, size_t > _formationPoint_agent
 Maps agent identifiers to formation point identifiers. Why identifiers?
 
std::map< size_t,
FormationPoint * > 
_agentPoints
 Maps agent identifiers to formation points. This lets me seach over a space instead of doing a lot of vector math each timestep ? WHAT ?
 
std::vector< FormationPoint * > _formationPoints
 The formation points defining the formation.
 
std::vector< FormationPoint * > _borderPoints
 A separate cache of border points – this is a subset of _formationPoints.
 
Vector2 _direction
 The formation's direction of travel.
 
float _speed
 The preferred speed of the formation.
 
Vector2 _pos
 The location of the formation center in world space (0,0).
 
float _agentRadius
 The instantaneous max distance from the center of the formation to normalized agent positions ??
 
std::map< size_t, Vector2 > _agentPrefDirs
 A cache of previoius agent preferred directions. Maps agent identifiers to directions.
 
std::map< size_t, Vector2 > _agentPrefVels
 A cache of previoius agent preferred velocities. Maps agent identifiers to velocities.
 
std::map< size_t, float > _agentWeights
 A cache of previoius agent preferred weights. Maps agent identifiers to weights. More...
 
std::map< size_t, const
Agents::BaseAgent * > 
_agents
 A cache of previoius agent preferred directions. Maps agent identifiers to agents.
 

Detailed Description

The class for modeling a freestyle formation.

Constructor & Destructor Documentation

Formations::FreeFormation::FreeFormation ( const std::string &  name)

Constructor.

Parameters
nameThe name of the file containing the target formation.

Member Function Documentation

void Formations::FreeFormation::addAgent ( const Agents::BaseAgent *  agt)

Adds an agent to this formation.

Only agents "added" to the formation will be mapped considered. ?? What happens if more agents htan formation points are added?

Parameters
agtThe agent to add to the formation.
void Formations::FreeFormation::addAgentPoint ( const Agents::BaseAgent *  agt)
protected

Adds an agent to the formation.

Parameters
agtThe agent to add to the formation.
void Formations::FreeFormation::addFormationPoint ( Vector2  pt,
bool  borderPoint,
float  weight 
)
protected

Adds a point to the formation.

Parameters
ptA point (in formation space).
borderPointTrue if the point should be considered a border point (false otherwise).
weightThe weight of the point.
float Formations::FreeFormation::formationDistance ( FormationPoint pt1,
FormationPoint pt2 
)
protected

A custom distance metric to apply to formation points. Used for evaluating "similarity" between formation points.

Parameters
pt1the first point to check
pt2the other point to check
Returns
The "distance" between the two formatin points.
bool Formations::FreeFormation::getGoalForAgent ( const Agents::BaseAgent *  agt,
Agents::PrefVelocity &  pVel,
Vector2 &  target 
)

Provides an intermediate goal for the agent.

This assumes that the agent provided is a member of the formation. It only checks in debug mode (via an assertion).

Parameters
agtThe agent for whom the goal is provided.
pVelThe agent's preferred velocity...does it change??
targetThe intermediate goal value is stored in this vector.
Returns
True if the an intermediate goal exists and is set in target, false otherwise.
virtual const std::string& Formations::FreeFormation::getLabel ( ) const
inlinevirtual

Reports the message label for this resource.

Returns
The label for formations.

Implements Menge::Resource.

Resource * Formations::FreeFormation::load ( const std::string &  fileName)
static

Parses a formation definition and returns a pointer to it.

This function works in conjunction with the ResourceManager. That is why it returns a pointer, not to a Formation, but to a Resource. The ResourceManager uses it to load and instantiateResource instances.

Parameters
fileNameThe path to the file containing the Formation definition.
Returns
A pointer to the new Formation (if the file is valid), NULL if invalid.
void Formations::FreeFormation::mapAgentsToFormation ( const BFSM::FSM *  fsm)

Computes the mapping from tracked agents to formation points.

Parameters
fsmA pointer to the FSM.
void Formations::FreeFormation::mapAgentToPoint ( const Agents::BaseAgent *  agt)
protected

Maps a single agent to a sentinel point.

Parameters
agtThe agent to map to a sentinel point.
void Formations::FreeFormation::mapPointToAgent ( FormationPoint pt)
protected

Maps a border point to one of the agents in the formation.

Parameters
ptA border point to map to an agent.
void Formations::FreeFormation::normalizeFormation ( )
protected

Finalize the formation representation for use.

Normalizing the formation defines distances between the formation center and formation points relative to the size of the formation. This allows for arbitrary scales.

void Formations::FreeFormation::removeAgent ( const Agents::BaseAgent *  agt)

Removes an agent from the formation.

Parameters
agtThe agent to remove.

Member Data Documentation

std::map< size_t, float > Formations::FreeFormation::_agentWeights
protected

A cache of previoius agent preferred weights. Maps agent identifiers to weights.

TODO: Currently, these are always 1.0. Provide mechanism for defininig non-unit weights.


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