class nape.space.Space

Available on all platforms

The heart of all Nape simulations.

Instance Fields

var arbiters:ArbiterList

List of all active arbiters in Space. *

* This list is immutable.

var bodies:BodyList

List of all Bodys directly placed in space. *

* This list is mutable, and adding an element to this list is one way of * adding a Body to this Space equivalent to: body.space = space *

* This list is only those bodies directly placed in the space, any * body that is a child of a Compound will not be in this list.

var broadphase:Broadphase

Broadphase type in use.

var compounds:CompoundList

List of all Compounds directly placed in space. *

* This list is mutable, and adding an element to this list is one way of * adding a Compound to this Space equivalent to: compound.space = space *

* This list is only those compounds directly placed in the space, any * compound that is a child of another compound will not be in this list.

var constraints:ConstraintList

List of all Constraints directly placed in space. *

* This list is mutable, and adding an element to this list is one way of * adding a Constraint to this Space equivalent to: constraint.space = space *

* This list is only those bodies directly placed in the space, any * constraint that is a child of a Compound will not be in this list.

var elapsedTime:Float

The elapsed simulation time. *

* This is the total amount of 'time' that has elapsed in the Space simulation.

var gravity:Vec2

Space gravity. *

* Units are of pixels/second/second * @default (0,0)

var listeners:ListenerList

List of all Listeners in space. *

* This list is mutable, and adding an element to this list is one way of * adding a Listener to this Space equivalent to: listener.space = space

var liveBodies:BodyList

List of all active dynamic Bodies in space. *

* This list contains all dynamic bodies that are awake regardless of their containment in a Compound. *

* This list is immutable.

var liveConstraints:ConstraintList

List of all active Constraints in space. *

* This list contains all constraints regardless of their containment in a Compound. *

* This list is immutable.

var sortContacts:Bool

Flag controlling sorting of contact points. *

* If true, then collisions will be resolved in an order defined by their * penetration depths. This can be shown to improve stability of the physics * as well as making simulations more consistent regardless of which broadphase * is used. *

* Having sorting enabled obviously incurs a cost, and you may consider * disabling it if you are having issues with performance (Though things * such as number of physics iterations will have much greater bearing on * performance than this, especcialy since enabling this may permit you * to use less iterations). * * @default true

var timeStamp:Int

The time stamp of this Space object. *

* This is equal to the number of times that space.step(..) has been invoked.

var userData:DynamicDynamic

Dynamic object for user to store additional data. *

* This object cannot be set, only its dynamically created * properties may be set. In AS3 the type of this property is &#42 *

* This object will be lazily constructed so that until accessed * for the first time, will be null internally. * * @default {}

var world:Body

Static, immutable Body for constraint purposes. *

* This is a completely static, uncollidable, uninteractable Body * with no Shapes, that cannot be modified in any way. *

* Its purpose is to provide a means for attaching Constraints * from one Body to the Space itself, for instance pinning a body * against a static point in space.

var worldAngularDrag:Float

Angular drag applied to all bodies in Space. *

* This represents the fraction of a body's angular velocity which will be * removed per second. This value has no unit attached. * * @default 0.015

var worldLinearDrag:Float

Linear drag applied to all bodies in Space. *

* This represents the fraction of a body's linear velocity which will be * removed per second. This value has no unit attached. * * @default 0.015

var zpp_inner:ZPP_Space

@private

function new(?gravity:Vec2 = null, ?broadphase:Broadphase = null):Void

Construct a new Space object. * *

gravity

The gravity of this space. (default (0,0)) *

broadphase

The broadphase type to use. (default DYNAMICAABBTREE) *

returns

The constructed Space object. *

function bodiesInAABB(aabb:AABB, ?containment:Bool = false, ?strict:Bool = true, ?filter:InteractionFilter = null, ?output:BodyList = null):BodyList

Evaluate all Bodies given an AABB. *

* If the filter argument is non-null, then only bodies with a shape * classified as being part of the AABB, whose filter agrees to collide * will be considered. * *

aabb

The bounding box to query bodies by, *

containment

If true, then only Bodies entirely contained (Rather * than simply intersecting) will be considered. * (default false) *

strict

If false, then the body's shape's bounding box will be used to * classify the shapes of the body, instead of the Shape itself. * (default true) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the shapes for given AABB. *

function bodiesInBody(body:Body, ?filter:InteractionFilter = null, ?output:BodyList = null):BodyList

Evaluate all Bodies given a Body. *

* If the filter argument is non-null, then only bodies with a shape * classified as being part of the input body, whose filter agrees to collide * will be considered. The input body is considered a purely geometric * *

body

The body to use in classifying other bodies. *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the bodies for given body. *

function bodiesInCircle(position:Vec2, radius:Float, ?containment:Bool = false, ?filter:InteractionFilter = null, ?output:BodyList = null):BodyList

Evaluate all Bodies given a circle. *

* If the filter argument is non-null, then only bodies with a shape * classified as being part of the circle, whose filter agrees to collide * will be considered. * *

position

The position of the centre of the circle. *

radius

The radius of the circle. *

containment

If true, then only Bodies entirely contained (Rather * than simply intersecting) will be considered. If a * filter is supplied, only shapes that agree to collide * will be used in this containment check. * (default false) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the shapes for given circle. *

function bodiesInShape(shape:Shape, ?containment:Bool = false, ?filter:InteractionFilter = null, ?output:BodyList = null):BodyList

Evaluate all Bodies given a shape. *

* If the filter argument is non-null, then only bodies with a shape * classified as being part of the input shape, whose filter agrees to collide * will be considered. The input shape is considered a purely geometric *

* The input shape must be part of a Body so as to be well defined. * *

shape

The shape to use in classifying other shapes. *

containment

If true, then only Bodies entirely contained (Rather * than simply intersecting) will be considered. * (default false) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the bodies for given shape. *

function bodiesUnderPoint(point:Vec2, ?filter:InteractionFilter = null, ?output:BodyList = null):BodyList

Evaluate all Bodies under a given Point. *

* If the filter argument is non-null, then only bodies with a shape containing * the given point whose filter agrees to 'collide' will be considered. * *

point

The point to evaluate bodies. *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the Bodies containing the given point. *

function clear():Void

Clear the Space of all objects. *

* Things such as the elapsed simulation time, and time step will too be * reset to 0. *

* Parameters such as gravity, and worldLinearDrag will be untouched by * this operation.

function convexCast(shape:Shape, deltaTime:Float, ?liveSweep:Bool = false, ?filter:InteractionFilter = null):Null<ConvexResult>

Perform a convex cast for soonest collision. *

* This method will return only the soonest collision result (if any), to find * more than this, use the convexMultiCast method. The shape will not be * swept further than the time delta provided. * Shapes already intersecting * the sweep shape at t = 0 are ignored. *

* If the filter argument is null, then all shapes will be collidable * otherwise only those for whose filter agrees to 'collide'. * *

shape

The Shape to be cast through space. This shape must belong * to a body whose velocity is used to define the sweep. *

deltaTime

The amount of time to sweep the shape forward. *

liveSweep

If true, then moving objects in the space will have their motion considered during the sweep. Otherwise; like with normal rayCast, objects in the space are considered un-moving for the cast. (default false) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

returns

The soonest result (if any) of convex intersection. *

function convexMultiCast(shape:Shape, deltaTime:Float, ?liveSweep:Bool = false, ?filter:InteractionFilter = null, output:ConvexResultList):ConvexResultList

Perform a convex cast for all collisions in time order. *

* This method will return all collisions, or an empty list if there are none. * The shape will not be * swept further than the time delta provided. Shapes already intersecting * the sweep shape at t = 0 are ignored. *

* If the filter argument is null, then all shapes will be collidable * otherwise only those for whose filter agrees to 'collide'. * *

shape

The Shape to be cast through space. This shape must belong * to a body whose velocity is used to define the sweep. *

deltaTime

The amount of time to sweep the shape forward. *

liveSweep

If true, then moving objects in the space will have their motion considered during the sweep. Otherwise; like with normal rayCast, objects in the space are considered un-moving for the cast. (default false) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

A list to append results to instead of allocating a new one (default null) *

returns

The collision results in time order. *

function interactionType(shape1:Shape, shape2:Shape):Null<InteractionType>

Determine the interaction type that would occur between a pair of Shapes. *

* This function takes into account everything possible, and ignoring the * callback system will tell you precisely the type of interaction (if any * at all) which will occur between these Shapes. *

* This function can only work if the Shapes belong to a Body. *

* This function can only make use of any constraints 'ignore' property * to determine if 'null' should be returned if the constraints being used * are inside of a Space. * *

shape1

The first Shape to test. *

shape2

The second Shape to test. *

returns

The interaction type that will occur between these shapes, or null if no interaction will occur.

function rayCast(ray:Ray, ?inner:Bool = false, ?filter:InteractionFilter = null):Null<RayResult>

Perform a ray cast for closest result. *

* This method will return only the closest result (if any), to find more * the first result, use the rayMultiCast method. The ray will not be * cast beyond its maxDistance. *

* If the filter argument is null, then all shapes will be intersectable * otherwise only those for whose filter agrees to 'collide'. * *

ray

The ray to cast through space. *

inner

If true then inner surfaces of shapes will also be intersected. * otherwise only the outer surfaces. (default false) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

returns

The closest result (if any) of ray intersection. *

function rayMultiCast(ray:Ray, ?inner:Bool = false, ?filter:InteractionFilter = null, ?output:RayResultList = null):RayResultList

Perform a ray cast for all valid results. *

* This method will return all intersections (in distance order) of ray * with shapes in the space up to the ray's maxDistance. *

* If the filter argument is null, then all shapes will be intersectable * otherwise only those for whose filter agrees to 'collide'. * *

ray

The ray to cast through space. *

inner

If true then inner surfaces of shapes will also be intersected. * otherwise only the outer surfaces. (default false) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

A list to append results to instead of allocating a new one (default null) *

returns

All valid results of ray cast in distance order from closest to furthest. *

function shapesInAABB(aabb:AABB, ?containment:Bool = false, ?strict:Bool = true, ?filter:InteractionFilter = null, ?output:ShapeList = null):ShapeList

Evaluate all Shapes given an AABB. *

* If the filter argument is non-null, then only shapes who's filter * agrees to 'collide' will be considered. * *

aabb

The bounding box to query shapes by, *

containment

If true, then only Shapes entirely contained (Rather * than simply intersected) will be considered. * (default false) *

strict

If false, then the Shape's bounding box will be used to * classify the Shape, instead of the Shape itself. * (default true) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the shapes for given AABB. *

function shapesInBody(body:Body, ?filter:InteractionFilter = null, ?output:ShapeList = null):ShapeList

Evaluate all Shapes given a Body. *

* If the filter argument is non-null, then only shapes who's filter * agrees to 'collide' will be considered. The input body's shape's own filters * are never used in this method. The input body is considered a purely * geometric object. * *

body

The body to use in classifying other shapes. *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the shapes for given body. *

function shapesInCircle(position:Vec2, radius:Float, ?containment:Bool = false, ?filter:InteractionFilter = null, ?output:ShapeList = null):ShapeList

Evaluate all Shapes given a circle. *

* If the filter argument is non-null, then only shapes who's filter * agrees to 'collide' will be considered. * *

position

The position of the centre of the circle. *

radius

The radius of the circle. *

containment

If true, then only Shapes entirely contained (Rather * than simply intersected) will be considered. * (default false) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the shapes for given circle. *

function shapesInShape(shape:Shape, ?containment:Bool = false, ?filter:InteractionFilter = null, ?output:ShapeList = null):ShapeList

Evaluate all Shapes given another shape. *

* If the filter argument is non-null, then only shapes who's filter * agrees to 'collide' will be considered. The input shape's own filter * is never used in this method. The input shape is considered a purely * geometric object. *

* The input shape must be part of a Body so as to be well defined. * *

shape

The shape to use in classifying other shapes. *

containment

If true, then only Shapes entirely contained (Rather * than simply intersected) will be considered. * (default false) *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the shapes for given shape. *

function shapesUnderPoint(point:Vec2, ?filter:InteractionFilter = null, ?output:ShapeList = null):ShapeList

Evaluate all Shapes under a given Point. *

* If the filter argument is non-null, then only shapes who's filter * agrees to 'collide' will be considered. * *

point

The point to evaluate shapes. *

filter

Optional filter to pick and choose shapes, based on whether * the filters agree to collide. (default null) *

output

Optional list to append results to instead of creating a new list (default null). *

returns

A list of all the Shapes containing the given point. *

function step(deltaTime:Float, ?velocityIterations:Int = 10, ?positionIterations:Int = 10):Void

Step simulation forward in time. * *

deltaTime

The number of seconds to simulate. For 60fps physics * you would use a value of 1/60. *

velocityIterations

The number of iterations to use in resolving * errors in the velocities of objects. This is * together with collision detection the most * expensive phase of a simulation update, as well * as the most important for stable results. * (default 10) *

positionIterations

The number of iterations to use in resolving * errors in the positions of objects. This is * far more lightweight than velocity iterations, * as well as being less important for the * stability of results. (default 10) *

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

Apply given function to all bodies in space. *

* This method is a way to iterate over 'every' Body in the Space * regardless of containment in a Compound. * *

lambda

The function to apply to each Body. *

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

Apply given function to all compounds in space. *

* This method is a way to iterate over 'every' Compound in the Space * regardless of containment in another Compound. * *

lambda

The function to apply to each Compound. *

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

Apply given function to all constraints in space. *

* This method is a way to iterate over 'every' Constraint in the Space * regardless of containment in a Compound. * *

lambda

The function to apply to each Constraint. *