MovementGenerator Class Reference

#include <MovementGenerator.h>

Inheritance diagram for MovementGenerator:

greatGathering groupRoaming randomRoaming realWorldRoaming

List of all members.


Detailed Description

(Abstract) MovementGenerator class

An interface for different movement generation set-ups.

Public Member Functions

 MovementGenerator (double areaDimension, double speed, NeighborMap *Neighbors)
 Initialize the generator with the movement area dimensions and node movement speed.
virtual ~MovementGenerator ()
virtual void move ()=0
 Defined in subclasses only.
Vector2D getPosition ()
 Get the nodes current position.

Protected Member Functions

void testBounds ()
 Prevents the node from leaving the defined area.
void flock ()
 Simple flocking algorithm.

Protected Attributes

double areaDimension
double speed
Vector2D direction
Vector2D position
Vector2D target
NeighborMapNeighbors
NeighborMap::iterator itNeighbors


Constructor & Destructor Documentation

MovementGenerator::MovementGenerator ( double  areaDimension,
double  speed,
NeighborMap Neighbors 
)

Initialize the generator with the movement area dimensions and node movement speed.

@param areaDimension Movement range from [-areaDimension, -areaDimension] to [areaDimension, areaDimension]. @param speed Movement speed in units per movement.

00032 {
00033     this->areaDimension = areaDimension;
00034     this->speed = speed;
00035     this->Neighbors = Neighbors;
00036 
00037     Vector2D center(areaDimension / 2, areaDimension / 2);
00038     position.x = uniform(0.0, areaDimension);
00039     position.y = uniform(0.0, areaDimension);
00040     direction = center - position;
00041     direction.normalize();
00042 }

virtual MovementGenerator::~MovementGenerator (  )  [inline, virtual]

00053 {}


Member Function Documentation

virtual void MovementGenerator::move (  )  [pure virtual]

Defined in subclasses only.

Implemented in greatGathering, groupRoaming, randomRoaming, and realWorldRoaming.

Vector2D MovementGenerator::getPosition (  ) 

Get the nodes current position.

@return Returns the current node position.

00045 {
00046     return position;
00047 }

void MovementGenerator::testBounds (  )  [protected]

Prevents the node from leaving the defined area.

00050 {
00051     if(position.x < 0.0) position.x = 0.0;
00052     if(position.x > areaDimension) position.x = areaDimension;
00053     if(position.y < 0.0) position.y = 0.0;
00054     if(position.y > areaDimension) position.y = areaDimension;
00055 }

void MovementGenerator::flock (  )  [protected]

Simple flocking algorithm.

00058 {
00059     Vector2D separation, alignment, cohesion, toTarget;
00060     int NeighborCount = 0;
00061 
00062     for(itNeighbors = Neighbors->begin(); itNeighbors != Neighbors->end(); ++itNeighbors)
00063         if(position.distanceSqr(itNeighbors->second.position) < 5.0 && direction.cosAngle(itNeighbors->second.position - position) > -0.75) {
00064             separation += position - itNeighbors->second.position;
00065             alignment += itNeighbors->second.direction;
00066             cohesion += itNeighbors->second.position;
00067             ++NeighborCount;
00068         }
00069 
00070     if(NeighborCount > 0) {
00071         cohesion /= (double)NeighborCount;
00072         cohesion = cohesion - position;
00073         separation.normalize();
00074         alignment.normalize();
00075         cohesion.normalize();
00076     }
00077     toTarget = target - position;
00078     toTarget.normalize();
00079 
00080     direction = separation * 0.4 + alignment * 0.1 + cohesion * 0.35 + toTarget * 0.25;
00081     direction.normalize();
00082 }


Member Data Documentation

double MovementGenerator::areaDimension [protected]

double MovementGenerator::speed [protected]

Vector2D MovementGenerator::direction [protected]

Vector2D MovementGenerator::position [protected]

Vector2D MovementGenerator::target [protected]

NeighborMap* MovementGenerator::Neighbors [protected]

NeighborMap::iterator MovementGenerator::itNeighbors [protected]


The documentation for this class was generated from the following files:
Generated on Thu Apr 17 13:19:29 2008 for ITM OverSim by  doxygen 1.5.3