Package populus :: Module Formation :: Class CompositeFormation
[frames] | no frames]

Class CompositeFormation



A composite formation is a specific arrangement of component formation units
in space.

Think of lines, rows, arcs, squares, these are all possible arrangement for
a group of formation units.

A C{CompositeFormation} can be composed of others composite formations or
basic formation units.

Every composite formation has 3 different states
1. I{Forming}: the formation has to form, that is the units has to initially
reach an certain arrangement.
2. I{Formed}: the units are arranged and formation is stable and well
formed.  
3. I{Broken}: the units temporarily breaks the formation without a new
arrangement has been chosen.

Instance Methods
 
__init__(self)
Create an empty CompositeFormation.
 
dismiss(self)
Destroy the formation and dismiss the units form arranging in a certain way.
Vec3
direction(self)
Return the direction or orientation of the formation.
Point3
position(self)
Return the position of the formation.
tuple
bounds(self)
Return the AABB of the formation.
float
radius(self)
Return the total radius of the formation.
 
speed(self)
The unit speed.
 
setPosition(self, point)
Set the position of the formation.
 
setDirection(self, dir)
Set the direction or orientation of the formation.
 
add(self, unit)
Add a unit to the formation.
 
remove(self, unit)
Remove a unit from the formation.
FormationUnit
getUnit(self, n)
Get the n-th unit of the formation.
int
getNumUnits(self)
Get the number of units in the formation.
 
rearrange(self)
Rearrange the formation.
 
goTo(self, point)
Move the formation to a given point.
 
enterForming(self)
This method is called before entering the state Forming.
 
enterFormed(self)
This function is called before entering the state Formed.
 
enterBroken(self)
This function is called before entering the state Broken.
 
exitForming(self)
This function is called before leaving the state Forming.
 
exitFormed(self)
This function is called before leaving the state Formed.
 
exitBroken(self)
This function is called before leaving the state Broken.
 
whenForming(self)
This function is called every time while in state Forming.
 
whenFormed(self)
This function is called every time while in state Formed.
 
whenBroken(self)
This function is called every time while in state Broken.
 
update(self, dt)
Continuously update the formation state.
 
annotate(self)
Draw formation bounds.

Inherited from FormationUnit: turnTo

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables
  SEPARATION = 1.0
  STABILITY_THRESHOLD = 0.15
  SHAPE_TOLERANCE = 0.5
Properties

Inherited from object: __class__

Method Details

__init__(self)
(Constructor)

 

Create an empty CompositeFormation.

Overrides: object.__init__

direction(self)

 

Return the direction or orientation of the formation.

Returns: Vec3
The direction in global coordinates.
Overrides: FormationUnit.direction

position(self)

 

Return the position of the formation.

Returns: Point3
The position of the formation.
Overrides: FormationUnit.position

bounds(self)

 

Return the AABB of the formation.

Returns: tuple
The AABB as a tuple of two points.
Overrides: FormationUnit.bounds

radius(self)

 

Return the total radius of the formation.

Returns: float
The total radius.
Overrides: FormationUnit.radius

To Do: The current is an approximated computation of the total radius of a composite formation. It will replaced by a better one.

speed(self)

 

The unit speed.

Overrides: FormationUnit.speed
(inherited documentation)

setPosition(self, point)

 

Set the position of the formation.

Parameters:
  • point (Point3) - A point in global coordinates.

setDirection(self, dir)

 

Set the direction or orientation of the formation. The direction will be normalized.

Parameters:
  • dir (Vec3)

add(self, unit)

 

Add a unit to the formation.

Parameters:
Overrides: FormationUnit.add

remove(self, unit)

 

Remove a unit from the formation.

Parameters:
Overrides: FormationUnit.remove

getUnit(self, n)

 

Get the n-th unit of the formation.

Parameters:
  • n (int) - The index of the unit.
Returns: FormationUnit
The formation unit at index n.
Overrides: FormationUnit.getUnit

getNumUnits(self)

 

Get the number of units in the formation.

Returns: int
The number of units.
Overrides: FormationUnit.getNumUnits

rearrange(self)

 

Rearrange the formation. The formation will go into a Forming state.

Note: You may want to call this method when units are added or removed.

goTo(self, point)

 

Move the formation to a given point.

Parameters:
  • point (Point3) - A point in global coordinates.
Overrides: FormationUnit.goTo

enterForming(self)

 

This method is called before entering the state Forming.

Note: Implement in subclasses when necessary.

enterFormed(self)

 

This function is called before entering the state Formed.

Note: Implement in subclasses when necessary.

enterBroken(self)

 

This function is called before entering the state Broken.

Note: Implement in subclasses when necessary.

exitForming(self)

 

This function is called before leaving the state Forming.

Note: Implement in subclasses when necessary.

exitFormed(self)

 

This function is called before leaving the state Formed.

Note: Implement in subclasses when necessary.

exitBroken(self)

 

This function is called before leaving the state Broken.

Note: Implement in subclasses when necessary.

whenForming(self)

 

This function is called every time while in state Forming.

Note: Implement in subclasses when necessary.

whenFormed(self)

 

This function is called every time while in state Formed.

Note: Implement in subclasses when necessary.

whenBroken(self)

 

This function is called every time while in state Broken.

Note: Implement in subclasses when necessary.

update(self, dt)

 

Continuously update the formation state.

Parameters:
  • dt (float) - Delta time since the simulation step.
Overrides: FormationUnit.update