class nape.phys.Compound extends Interactor

Available on all platforms

Compound represents a grouping of physics objects into a single object. *

* This compound owns its constituents and works in the callback system and with * respect to adding/removing from a Space as a single object. *

 *       Cmp1_
 *      /    /    \   \
 * Body1 Body2--Joint Cmp2
 *   |     |        \  |
 * Shp1  Shp2        Body3
 *                     |
 *                    Shp3
 * 
* For example if you have a complex car built with several bodies and * constraints you might store this in a Compound providing an easy way * of removing/adding/copying the Car as well as being able to get a single * callback for when the car collides with something. *

* When you add a compound to a Space, all of it's constituents get added * and furthermore, those constituents cannot be added seperately.

Instance Fields

var bodies:BodyList

List of bodies directly owned by this Compound. *

* This list does not include those bodies belonging to sub-compounds. * * @default []

var compound:Null<Compound>

Compound that this compound belongs to. * * @default null

var compounds:CompoundList

List of compounds directly owned by this Compound. *

* This list does not include those compounds belonging to sub-compounds. * * @default []

var constraints:ConstraintList

List of constraints directly owned by this Compound. *

* This list does not include those constraints belonging to sub-compounds. * * @default []

var space:Null<Space>

Space this compound belongs to. *

* This value is immutable when this compound belongs to another parent Compound. * * @default null

function new():Void

Construct a new Compound. * * @result The constructed Compound.

function COM(?weak:Bool = false):Vec2

Compute centre of mass of Compound. * *

weak

If true, the returned Vec2 will be automatically released * to the object pool when passed as an argument to a Nape * function. (default false) *

returns

The centre of mass of compound. *

function breakApart():Void

Breaking compound apart in-place. *

* This method will destroy the compound, moving all of it's components * to the assigned Space if this is the root compound, otherwise to the * parent compound. *

* Apart from being easier than doing this manually it also means that we * do not have to temporarigly remove objects from the space meaning that * things like PreListener ignored interactions will be unaffected.

function copy():Compound

Produce an exact copy of this Compound. *

* This copy will remap owned constraints so that their body properties * refer to the newly copied bodies also owned by this compound. *

* If this compound tree contains any constraints that make references * to outside of this compound; then these properties will be made null. *

     *       Cmp1               [Cmp2.copy()]
     *      /    /        \
     * Body1 Body2___     Cmp2        null    Cmp2'
     *   |     |     \     /  \         \    /    \
     * Shp1  Shp2     Joint--Body3       Joint'--Body3'
     *                         |                   |
     *                        Shp3               Shp3'
     * 
* For instance if copying Cmp1 then all is well, but if we copy Cmp2 the * copied Joint will have one of it's body references null as that body is * not owned directly, or indirectly by the compound.

function rotate(centre:Vec2, angle:Float):Compound

Rotate entire compound about a point. *

* This is equivalent to: compound.visitBodies(function (b) b.rotate(centre, angle)) * *

centre

The centre of rotation in world coordinates. *

angle

The clockwise angle of rotation in radians. *

returns

A reference to this Compound. *

function toString():String

@private

function translate(translation:Vec2):Compound

Translate entire compound. *

* This is equivalent to: compound.visitBodies(function (b) b.translate(translation)) * *

translation

The translation to apply to the Compound. *

returns

A reference to this Compound. *

function visitBodies(lambda:Body ->Void):Void

Method to iterate over all bodies contained directly or indirectly by * this Compound. * *

lambda

The method to apply to each Body. *

function visitCompounds(lambda:Compound ->Void):Void

Method to iterate over all compounds contained directly or indirectly by * this Compound. * *

lambda

The method to apply to each Compound. *

function visitConstraints(lambda:Constraint ->Void):Void

Method to iterate over all constraints contained directly or indirectly by * this Compound. * *

lambda

The method to apply to each Constraint. *