| Package | nape.phys |
| Class | Body |
| Inheritance |
Body Interactor |
Rigid body composed of Shapes
Public Properties
| Property | Defined By | |
|
type : BodyType Rigid body type |
Body | |
|
shapes : ShapeList [read-only] List of Body's shapes |
Body | |
|
compound : Compound Compuond Body belongs to |
Body | |
|
space : Space Space to which Body is contained |
Body | |
|
graphic : Dynamic Assigned graphic |
Body | |
|
graphicUpdate : Body->Void Assigned graphic handler |
Body | |
|
bounds : AABB [read-only] Body world bounds |
Body | |
|
arbiters : ArbiterList [read-only] Immutable list of arbiters |
Body | |
|
constraints : ConstraintList [read-only] List of associated active constraints |
Body | |
|
isSleeping : Bool [read-only] Whether body is asleep |
Body | |
|
localCOM : Vec2 [read-only] Immutable local centre of mass |
Body | |
|
worldCOM : Vec2 [read-only] Immutable world centre of mass |
Body | |
|
position : Vec2 Body position |
Body | |
|
velocity : Vec2 Body linear velocity |
Body | |
|
force : Vec2 Body linear force accumulator |
Body | |
|
rotation : Float Rigid body rotation |
Body | |
|
angularVel : Float Rigid body angular velocity |
Body | |
|
torque : Float Body torque accumulator |
Body | |
|
kinematicVel : Vec2 Additional velocity. |
Body | |
|
kinAngVel : Float Addition angular velocity. |
Body | |
|
surfaceVel : Vec2 Additional contact surface velocity. |
Body | |
|
constraintVelocity : Vec3 [read-only] Velocity seen by constraints |
Body | |
|
allowMovement : Bool = true Body behaves as a kinematic body for linear movement |
Body | |
|
allowRotation : Bool = true Body behaves as a kinematic body for angular movement |
Body | |
|
massMode : MassMode = MassMode.DEFAULT Mass mode of Body |
Body | |
|
mass : Float Mass of Body |
Body | |
|
constraintMass : Float [read-only] Mass seen by constraint |
Body | |
|
gravMassMode : GravMassMode = GravMassMode.DEFAULT GravMass mode of Body |
Body | |
|
gravMass : Float Gravitational mass of Body |
Body | |
|
gravMassScale : Float Ratio of gravMass to mass |
Body | |
|
InertiaMode : InertiaMode = InertiaMode.DEFAULT Inertia mode of Body |
Body | |
|
inertia : Float Moment of inertia of Body |
Body | |
|
constraintInertia : Float [read-only] Moment of inertia seen by constraint |
Body |
Constructor
| Constructor | ||
|
new(?type:BodyType=BodyType.DYNAMIC, ?position:Vec2=(0,0)) Construct new Rigid Body |
Public Methods
| Method | Defined By | |
|
const
isStatic() : Bool Whether Body is static |
Body | |
|
const
isKinematic() : Bool Whether Body is kinematic |
Body | |
|
const
isDynamic() : Bool Whether Body is dynamic |
Body | |
|
|
||
|
setShapeMaterials(material:Material) Set material for every shape |
Body | |
|
setShapeFilters(filter:InteractionFilter) Set filter for every shape |
Body | |
|
setShapeFluidProperties(fluidProperties:FluidProperties) Set fluidProperties for every shape |
Body | |
|
|
||
|
translateShapes(displacement:const Vec2) translate each shape |
Body | |
|
rotateShapes(angle:Float) rotate each shape |
Body | |
|
scaleShapes(scalex:Float, scaley:Float) scale each shape |
Body | |
|
transformShapes(matrix:const Mat23) transform each shape |
Body | |
|
align() align centre of mass of body |
Body | |
|
rotate(centre:const Vec2, angle:Float) rotate body abuot a point |
Body | |
|
const
copy() : Body Produce deep* copy of Body |
Body | |
|
|
||
|
const
localToWorld(v:const Vec2, ?weak:Bool=false) : Vec2 Transform from local to world |
Body | |
|
const
localToRelative(v:const Vec2, ?weak:Bool=false) : Vec2 Transform from local to relative |
Body | |
|
const
relativeToWorld(v:const Vec2, ?weak:Bool=false) : Vec2 Transform from relative to world |
Body | |
|
const
worldToLocal(v:const Vec2, ?weak:Bool=false) : Vec2 Transform from world to local |
Body | |
|
const
worldToRelative(v:const Vec2, ?weak:Bool=false) : Vec2 Transform from world to relative |
Body | |
|
const
relativeToLocal(v:const Vec2, ?weak:Bool=false) : Vec2 Transform from relative to local |
Body | |
|
|
||
|
const
applyLocalForce(force:const Vec2, ?pos:const Vec2=(0,0)) Apply force at local position |
Body | |
|
const
applyRelativeForce(force:const Vec2, ?pos:const Vec2=(0,0)) Apply force at relative position |
Body | |
|
const
applyWorldForce(force:const Vec2, pos:const Vec2) Apply force at world position |
Body | |
|
|
||
|
const
applyLocalImpulse(impulse:const Vec2, ?pos:const Vec2=(0,0)) Apply impulse at local position |
Body | |
|
const
applyRelativeImpulse(impulse:const Vec2, ?pos:const Vec2=(0,0)) Apply impulse at relative position |
Body | |
|
const
applyWorldImpulse(impulse:const Vec2, pos:const Vec2) Apply impulse at world position |
Body | |
|
|
||
|
const
normalImpulse(?body:Body=null, ?freshOnly:Bool=false, ?weak:Bool=false) : Vec2 normal impulses on body |
Body | |
|
const
tangentImpulse(?body:Body=null, ?freshOnly:Bool=false, ?weak:Bool=false) : Vec2 tangent impulses on body |
Body | |
|
const
rollingImpulse(?body:Body=null, ?freshOnly:Bool=false) : Float rolling impulses on body |
Body | |
|
const
totalContactsImpulse(?body:Body=null, ?freshOnly:Bool=false) : Vec3 contact impulses on body |
Body | |
|
|
||
|
const
buoyancyImpulse(?body:Body=null) : Vec3 buoyancy impulses on body |
Body | |
|
const
dragImpulse(?body:Body=null) : Vec3 drag impulses on body |
Body | |
|
const
totalFluidImpulse(?body:Body=null) : Vec3 fluid impulses on body |
Body | |
|
|
||
|
const
constraintsImpulse() : Vec3 constraint impulses on body |
Body | |
|
|
||
|
const
totalImpulse() : Vec3 total impulses on body |
Body | |
|
|
||
|
const
contains(point:const Vec2) : Bool Test point containment |
Body |
Property Detail
| type | property |
property type : BodyTypeRigid body type, you are free to modify this at will though there are performance penalties for conversion from/to BodyType.STATIC for most Space types, which are not great but worth mentioning (Consider if BodyType.KINEMATIC is good enough in such cases to replace BodyType.STATIC).
In conversion from kinematic/static to dynamic, the apparent velocity of the object will be conserved including the kinematic velocity offset in the case of kinematic.
In conversion to kinematic, the kinematic velocity will be set to 0.
| shapes | property |
|
readonly property shapes : ShapeListList of shapes associated with the Body, shapes can only exist once in any shape list, so attempts to add a shape may sometimes fail (Already in list), and adding a shape to a Body's list will remove it from whatever Body it was in previously.
Note this field is readonly, but the list is still mutable!
Immutable if:
isStatic() && space!=null
Whether implicit or explicit operations are performed on this list, an error will be thrown.
| compound | property |
|
property compound : CompoundThe compound this Body belongs to.
| space | property |
|
property space : SpaceSpace the body is contained in. This value can also be set unless the Body is part of a Compound in which case only the root of the tree can have it's space modified.
Error on setter if:
this.compound!=null
Only the root of the tree has a mutable space property| graphic | property |
|
property graphic : DynamicA graphic that can be assigned for auto-placement by nape. Graphic is assumed to be a flash DisplayObject unless the graphicUpdate method is assigned.
| graphicUpdate | property |
|
property graphicUpdate : Body->VoidA function handler taking the Body who's position/rotation has changed and should be rendered.
This takes precedence over any handling of the 'graphic' property and so can be used either on it's own, or together with the graphic property to customise it's placement
For example, you could emulate how nape internally updates the graphic property with the following handler:
body.graphic = ...;
body.graphicUpdate = function(b:Body) {
b.graphic.x = b.position.x;
b.graphic.y = b.position.y;
//rotation is clamped to [-360,360] as flash doesn't like large rotation values
b.graphic.rotation = (b.rotation*180/Math.PI)%360;
}| bounds | property |
|
readonly property bounds : AABBImmutable AABB representing the world limits of the Body.
Error on getter if:
shapes.empty()
| arbiters | property |
|
readonly property arbiters : ArbiterListReference to the immutable list of arbiters belonging to the respective Shapes of this Body. This includes arbiters that have been put to sleep.
| constraints | property |
|
readonly property constraints : ConstraintListList of all 'active' (Meaning inside of a space, with active=true) constraints associated with the body. This list is immutable due to the 'active' criterion which is necessary to allow proper garbage collection of objects (Similar to CbType::bodies case)
| isSleeping | property |
|
readonly property isSleeping : BoolIf true then this body has been put to sleep.
| localCOM | property |
|
readonly property localCOM : Vec2Immutable Vec2 corresponding to the centre of mass of the rigid body in it's local coordinates
Error on getter if:
shapes.empty()| worldCOM | property |
|
readonly property worldCOM : Vec2Immutable Vec2 corresponding to the centre of mass of the rigid body in world/world coordinates
Error on getter if:
shapes.empty()| position | property |
|
property position : Vec2Vec2 of the Body's origin in world coordinates.
Setting the position of a body is equivalent to simply teleporting the body; you should only use this when necessary or appropriate; for instance moving a kinematic body by position is not the way to go about things as there will be no velocity information with which collisions etc will be correctly performed.
Immutable if:
isStatic() && space!=null
Error on setter if:
Vec2 immutable| velocity | property |
|
property velocity : Vec2Vec2 for the Body's linear velocity in world coordinates.
For kinematic bodies, this is the correct way to move the body around.
For static rigid bodies, this field is irrelevant, except that should you change the body into a dynamic one, it would retain the velocity.
| force | property |
|
property force : Vec2Vec2 for the Body's linear force accumulator in world coordinates.
| rotation | property |
|
property rotation : FloatRotation of rigid body about it's origin in clockwise radians, there is no finite range for this value. Setting this value is equivalent to (rotationally speaking) teleporting the body and should only be used if appropriate and necessary.
Error on setter if:
isStatic() && space!=null
| angularVel | property |
|
property angularVel : FloatRigid body's angular velocity. For kinematic bodies, this is the correct way unless you explicitly want to teleport, to rotate the body
| torque | property |
|
property torque : FloatBody torque accumulator
| kinematicVel | property |
|
property kinematicVel : Vec2The kinematic velocity is a velocity added to the normal body velocity each frame before physics computations take place, and afters removed so that it does not directly effect the motion of the body, but does effect the way in which constraints and contact calculations are performed.
The best use of this is for giving a simple velocity field to a fluid for instance
Note that this property is only used for dynamic and kinematic objects, and will be ignored for static objects.
| kinAngVel | property |
|
property kinAngVel : FloatThe same as the kinematicVel field, but for angular velocity.
| surfaceVel | property |
|
property surfaceVel : Vec2The surface velocity is an additional velocity used for dynamic and kinematic objects which only effects contact calculations; there is no angular version of this as the surface velocity is applied in the coordinate frame of the contact point, so that the x-value of the surface velocity effects the tangentenial velocity seen by the contact points regardless of orientation of the contact, and the y-value effects the normal velocity seen by the contact point.
This is best used for such things as conveyor belts, and for such things as trampolines or pinball style bouncers etc.
| constraintVelocity | property |
|
readonly property constraintVelocity : Vec3Property to be used when working with user-defined constraints to get the velocity of the body that should be used (Currently computes the sum of velocities and kinematic velocities)
| allowMovement | property |
|
property allowMovement : BoolThis field only has effect on dynamic bodies, when set to true the body will behave like a kinematic body with respect to normal x,y movement. You will still be able to move it either via changing position, or it's velocity but to all extents it will have infinite mass.
| allowRotation | property |
|
property allowRotation : BoolThis field only has effect on dynamic bodies, when set to true the body will behave like a kinematic body with respect to rotational movement. You will still be able to rotate it either via changing rotation, or it's angular velocity but to all extents it will have infinite inertia.
| massMode | property |
|
property massMode : MassModeMass mode for Body
See Also
| mass | property |
|
property mass : FloatMass of body
Setting this field will implicitly set
massMode = MassMode.FIXED
Error on getter if:
shapes.empty() && massMode==MassMode.DEFAULT
Error on setter if:
mass <= 0
| constraintMass | property |
|
readonly property constraintMass : FloatFor use in user defined constraints, this value defines the inverse mass to be used in effective mass computations, equal to 1/mass for dynamic bodies, and 0 for statics/kinematics and space.world bodies
| gravMassMode | property |
|
property gravMassMode : GravMassModeGravMass mode for Body
See Also
| gravMass | property |
|
property gravMass : FloatGravitational mass of Body; that is the mass that the object will be assumed to have for the purposes of gravity, whether it reflect the real mass or not; you can for instance do a helium balloon by simply setting the gravitational mass to be slightly negative.
Setting this field will implicitly set
gravMassMode = GravMassMode.FIXED
Error on getter if:
shapes.empty() && massMode == MassMode.DEFAULT && gravMassMode != GravMassMode.FIXED
| gravMassScale | property |
|
property gravMassScale : FloatThe ratio of gravMass to mass.
Setting this field will implicitly set
gravMassMode = GravMassMode.SCALED
Error on getter if:
shapes.empty() && massMode == MassMode.DEFAULT && gravMassMode!=MassMode.SCALED
| InertiaMode | property |
|
property InertiaMode : InertiaModeInertia mode of Body
See Also
| inertia | property |
|
property inertia : FloatMomment of inertia of Body
Setting this field will implicitly set
inertiaMode = InertiaMode.FIXED
Error on getter if:
inertiaMode == InertiaMode.DEFAULT && shapes.empty()
Error on setter if:
inertia <= 0
| constraintInertia | property |
|
readonly property constraintInertia : FloatFor use in user defined constraints, this value defines the inverse moment of inertia to be used in effective mass computations, equal to 1/mass for dynamic bodies, and 0 for statics/kinematics and space.world bodies
Constructor Detail
Method Detail
| isStatic | method |
const function isStatic() : BoolWhether Body is static
| isKinematic | method |
|
const function isKinematic() : BoolWhether Body is kinematic
| isDynamic | method |
|
const function isDynamic() : BoolWhether Body is dynamic
| setShapeMaterials | method |
|
function setShapeMaterials(material:Material)If material is not set for sharing, a copy of the given material will be assigned to each shape.
| setShapeFilters | method |
|
function setShapeFilters(filter:InteractionFilter)If filter is not set for sharing, a copy of the given filter will be assigned to each shape.
| setShapeFluidProperties | method |
|
function setShapeFluidProperties(fluidProperties:FluidProperties)If properties is not set for sharing, a copy of the given fluidProperties will be assigned to each shape.
| translateShapes | method |
|
function translateShapes(displacement:const Vec2)Simply maps over Shape::translate for each shape
See Also
| rotateShapes | method |
|
function rotateShapes(angle:Float)Simply maps over Shape::rotate for each shape
See Also
| scaleShapes | method |
|
function scaleShapes(scalex:Float, scaley:Float)Simply maps over Shape::scale for each shape
See Also
| transformShapes | method |
|
function transformShapes(matrix:const Mat23)Simply maps over Shape::transform for each shape
See Also
| align | method |
|
function align()Applies same translation to each shape resulting in the local centre of mass being at the origin, aswell as translating the body itself so that each shape's world state is unchanged.
Error if:
shapes.empty()| rotate | method |
|
function rotate(centre:const Vec2, angle:Float)Rotate the body about a given point in world space
| copy | method |
|
const function copy() : Body| localToWorld | method |
|
const function localToWorld(v:const Vec2, ?weak:Bool=false) : Vec2Transform given Vec2, returning it's equivalent world coordinates
| localToRelative | method |
|
const function localToRelative(v:const Vec2, ?weak:Bool=false) : Vec2Transform given Vec2, returning it's equivalent relative world/world coordinates
| relativeToWorld | method |
|
const function relativeToWorld(v:const Vec2, ?weak:Bool=false) : Vec2Transform given Vec2, returning it's equivalent world/world coordinates
| worldToLocal | method |
|
const function worldToLocal(v:const Vec2, ?weak:Bool=false) : Vec2Transform given Vec2, returning it's equivalent local coordinates
| worldToRelative | method |
|
const function worldToRelative(v:const Vec2, ?weak:Bool=false) : Vec2Transform given Vec2, returning it's equivalent relative world/world coordinates
| relativeToLocal | method |
|
const function relativeToLocal(v:const Vec2, ?weak:Bool=false) : Vec2Transform given Vec2, returning it's equivalent local coordinates
| applyLocalForce | method |
|
const function applyLocalForce(force:const Vec2, ?pos:const Vec2=(0,0))Apply force at local position, note that it is only the position that is in local coordiantes here, the force is taken to be in world/world coordinates
If position is omitted then this is equivalent to applyRelativeForce
| applyRelativeForce | method |
|
const function applyRelativeForce(force:const Vec2, ?pos:const Vec2=(0,0))Apply force at relative position, note that it is only the position that is in relative coordiantes here, the force is taken to be in world/world coordinates
If position is omitted then this is equivalent to applyLocalForce
| applyWorldForce | method |
|
const function applyWorldForce(force:const Vec2, pos:const Vec2)Apply force at world position
| applyLocalImpulse | method |
|
const function applyLocalImpulse(impulse:const Vec2, ?pos:const Vec2=(0,0))Apply impulse at local position, note that it is only the position that is in local coordiantes here, the impulse is taken to be in world/world coordinates
If position is omitted then this is equivalent to applyRelativeImpulse
| applyRelativeImpulse | method |
|
const function applyRelativeImpulse(impulse:const Vec2, ?pos:const Vec2=(0,0))Apply impulse at relative position, note that it is only the position that is in relative coordiantes here, the impulse is taken to be in world/world coordinates
If position is omitted then this is equivalent to applyLocalImpulse
| applyWorldImpulse | method |
|
const function applyWorldImpulse(impulse:const Vec2, pos:const Vec2)Apply impulse at world position
| normalImpulse | method |
|
const function normalImpulse(?body:Body=null, ?freshOnly:Bool=false, ?weak:Bool=false) : Vec2When body is null, returns the sum of all normal impulses from contacts on this body, otherwise returns normal impulses only between the two bodies.
If freshOnly is true, then only new contacts are considered
| tangentImpulse | method |
|
const function tangentImpulse(?body:Body=null, ?freshOnly:Bool=false, ?weak:Bool=false) : Vec2When body is null, returns the sum of all tangent impulses from contacts on this body, otherwise returns tangent impulses only between the two bodies.
If freshOnly is true, then only new contacts are considered
| rollingImpulse | method |
|
const function rollingImpulse(?body:Body=null, ?freshOnly:Bool=false) : FloatWhen body is null, returns the sum of all rolling impulses from contacts on this body, otherwise returns rolling impulses only between the two bodies.
If freshOnly is true, then only new contacts are considered
| totalContactsImpulse | method |
|
const function totalContactsImpulse(?body:Body=null, ?freshOnly:Bool=false) : Vec3When body is null, returns the sum of all contact impulses from contacts on this body, otherwise returns contact impulses only between the two bodies.
If freshOnly is true, then only new contacts are considered
| buoyancyImpulse | method |
|
const function buoyancyImpulse(?body:Body=null) : Vec3When body is null, returns the sum of all buoyancy impulses from fluid arbiters on this body, otherwise returns buoyancy impulses only between the two bodies
| dragImpulse | method |
|
const function dragImpulse(?body:Body=null) : Vec3When body is null, returns the sum of all drag impulses from fluid arbiters on this body, otherwise returns drag impulses only between the two bodies
| totalFluidImpulse | method |
|
const function totalFluidImpulse(?body:Body=null) : Vec3When body is null, returns the sum of all fluid impulses from fluid arbiters on this body, otherwise returns fluid impulses only between the two bodies
| constraintsImpulse | method |
|
const function constraintsImpulse() : Vec3Returns the sum of all constraint impulses acting on the body
| totalImpulse | method |
|
const function totalImpulse() : Vec3If body is null, returns the sum of all constraint, contact and fluid impulses acting on the body, otherwise for contact and fluid impulses considers only those between the two bodies.
| contains | method |
|
const function contains(point:const Vec2) : BoolTest point containment.

Show Inherited Properties