Body class

Base class for all body types. @example; final shape = CANNON.Sphere(1); final body = CANNON.Body({ 1 *mass; shape,; }) world.addBody(body);

Inheritance

Constructors

Body({int collisionFilterGroup = 1, int collisionFilterMask = -1, bool collisionResponse = true, Vec3? position, Vec3? velocity, double mass = 0, Material? material, double linearDamping = 0.01, BodyTypes? type, bool allowSleep = true, double sleepSpeedLimit = 0.1, num sleepTimeLimit = 1, Quaternion? quaternion, Vec3? angularVelocity, bool fixedRotation = false, double angularDamping = 0.01, Vec3? linearFactor, Vec3? angularFactor, Shape? shape, bool isTrigger = false})

Properties

aabb AABB
World space bounding box of the body and its shapes.
getter/setter pair
aabbNeedsUpdate bool
Indicates if the AABB needs to be updated before use.
getter/setter pair
allowSleep bool
If true, the body will automatically fall to sleep.
getter/setter pair
angularDamping double
How much to damp the body angular velocity each step. It can go from 0 to 1.
getter/setter pair
angularFactor Vec3
Use this property to limit the rotational motion along any world axis. (1,1,1) will allow rotation along all axes while (0,0,0) allows none.
getter/setter pair
angularVelocity Vec3
Angular velocity of the body, in world space. Think of the angular velocity as a vector, which the body rotates around. The length of this vector determines how fast (in radians per second) the body rotates.
getter/setter pair
boundingRadius double
Total bounding radius of the Body including its shapes, relative to body.position.
getter/setter pair
collisionFilterGroup int
The collision group the body belongs to.
getter/setter pair
collisionFilterMask int
The collision group the body can collide with.
getter/setter pair
collisionResponse bool
Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled - i.e. "collide" events will be raised, but forces will not be altered.
getter/setter pair
fixedRotation bool
Set to true if you don't want the body to rotate. Make sure to run .updateMassProperties() if you change this after the body creation.
getter/setter pair
force Vec3
Linear force on the body in world space.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
id int
Identifier of the body.
getter/setter pair
index int
Position of body in World.bodies. Updated by World and used in ArrayCollisionMatrix.
getter/setter pair
inertia Vec3
The inertia of the body.
getter/setter pair
initAngularVelocity Vec3
Initial angular velocity of the body.
getter/setter pair
initPosition Vec3
Initial position of the body.
getter/setter pair
initQuaternion Quaternion
Initial quaternion of the body.
getter/setter pair
initVelocity Vec3
Initial velocity of the body.
getter/setter pair
interpolatedPosition Vec3
Interpolated position of the body.
getter/setter pair
interpolatedQuaternion Quaternion
Interpolated orientation of the body.
getter/setter pair
invInertia Vec3
getter/setter pair
invInertiaSolve Vec3
getter/setter pair
invInertiaWorld Mat3
getter/setter pair
invInertiaWorldSolve Mat3
getter/setter pair
invMass double
getter/setter pair
invMassSolve double
getter/setter pair
isTrigger bool
When true the body behaves like a trigger. It does not collide with other bodies but collision events are still triggered.;
getter/setter pair
linearDamping double
How much to damp the body velocity each step. It can go from 0 to 1.
getter/setter pair
linearFactor Vec3
Use this property to limit the motion along any world axis. (1,1,1) will allow motion along all axes while (0,0,0) allows none.
getter/setter pair
mass double
The mass of the body.
getter/setter pair
material Material?
The physics material of the body. It defines the body interaction with other bodies.
getter/setter pair
position Vec3
World space position of the body.
getter/setter pair
previousPosition Vec3
getter/setter pair
previousQuaternion Quaternion
getter/setter pair
quaternion Quaternion
World space orientation of the body.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shapeOffsets List<Vec3>
Position of each Shape in the body, given in local Body space.
getter/setter pair
shapeOrientations List<Quaternion>
Orientation of each Shape, given in local Body space.
getter/setter pair
shapes List<Shape>
List of Shapes that have been added to the body.
getter/setter pair
sleepSpeedLimit double
If the speed (the norm of the velocity) is smaller than this value, the body is considered sleepy.
getter/setter pair
sleepState BodySleepStates
Current sleep state.
getter/setter pair
sleepTimeLimit num
If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping.
getter/setter pair
timeLastSleepy num
getter/setter pair
torque Vec3
World space rotational force on the body, around center of mass.
getter/setter pair
type BodyTypes
One of: Body.DYNAMIC, Body.static and Body.kinematic.
getter/setter pair
velocity Vec3
World space velocity of the body.
getter/setter pair
vlambda Vec3
getter/setter pair
wakeUpAfterNarrowphase bool
getter/setter pair
wlambda Vec3
getter/setter pair
world World?
Reference to the world the body is living in.
getter/setter pair

Methods

addEventListener(String type, dynamic listener(dynamic)) EventTarget
Add an event listener @return The self object, for chainability.
inherited
addShape(Shape shape, [Vec3? offset, Quaternion? orientation]) Body
Add a shape to the body with a local offset and orientation. @return The body object, for chainability.
applyForce(Vec3 force, [Vec3? relativePoint]) → void
Apply force to a point of the body. This could for example be a point on the Body surface. Applying force this way will add to Body.force and Body.torque. @param force The amount of force to add. @param relativePoint A point relative to the center of mass to apply the force on.
applyImpulse(Vec3 impulse, [Vec3? relativePoint]) → void
Apply impulse to a point of the body. This could for example be a point on the Body surface. An impulse is a force added to a body during a short period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity.; @param impulse The amount of impulse to add.; @param relativePoint A point relative to the center of mass to apply the force on.
applyLocalForce(Vec3 localForce, Vec3 localPoint) → void
Apply force to a local point in the body. @param force The force vector to apply, defined locally in the body frame. @param localPoint A local point in the body to apply the force on.
applyLocalImpulse(Vec3 localImpulse, Vec3 localPoint) → void
Apply locally-defined impulse to a local point in the body. @param force The force vector to apply, defined locally in the body frame. @param localPoint A local point in the body to apply the force on.
applyTorque(Vec3 torque) → void
Apply torque to the body. @param torque The amount of torque to add.
dispatchEvent(Event event) EventTarget
Emit an event. @return The self object, for chainability.
inherited
getVelocityAtWorldPoint(Vec3 worldPoint, Vec3 result) Vec3
Get world velocity of a point in the body. @param worldPoint; @param result; @return The result vector.;
hasAnyEventListener(String type) bool
Check if any event listener of the given type is added
inherited
hasEventListener(String type, void listener()) bool
Check if an event listener is added
inherited
integrate(double dt, [bool quatNormalize = false, bool quatNormalizeFast = false]) → void
Move the body forward in time. @param dt Time step; @param quatNormalize Set to true to normalize the body quaternion; @param quatNormalizeFast If the quaternion should be normalized using "fast" quaternion normalization;
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pointToLocalFrame(Vec3 worldPoint, Vec3? result) Vec3
Convert a world point to local body frame.
pointToWorldFrame(Vec3 localPoint, Vec3? result) Vec3
Convert a local body point to world frame.
removeEventListener(String type, Function listener) EventTarget
Remove an event listener @return The self object, for chainability.
inherited
removeShape(Shape shape) Body
Remove a shape from the body. @return The body object, for chainability.
sleep() → void
Force body sleep
sleepTick(double time) → void
Called every timestep to update internal sleep timer and change sleep state if needed. @param time The world time in seconds;
toString() String
A string representation of this object.
inherited
updateAABB() → void
Updates the .aabb
updateBoundingRadius() → void
Update the bounding radius of the body. Should be done if any of the shapes are changed.
updateInertiaWorld([bool force = false]) → void
Update .inertiaWorld and .invInertiaWorld
updateMassProperties() → void
Should be called whenever you change the body shape or mass.
updateSolveMassProperties() → void
If the body is sleeping, it should be immovable / have infinite mass during solve. We solve it by having a separate "solve mass".
vectorToLocalFrame(Vec3 worldVector, [Vec3? result]) Vec3
Convert a world vector to local body frame
vectorToWorldFrame(Vec3 localVector, [Vec3? result]) Vec3
Convert a local body point to world frame.
wakeUp() → void
Wake the body up.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

collideEventName String
Dispatched after two bodies collide. This event is dispatched on each of the two bodies involved in the collision.; @event collide; @param body The body that was involved in the collision.; @param contact The details of the collision.;
getter/setter pair
idCounter int
getter/setter pair
sleepEvent BodyEvent
Dispatched after a body has fallen asleep. @event sleep;
getter/setter pair
sleepyEvent BodyEvent
Dispatched after a body has gone in to the sleepy state. @event sleepy;
getter/setter pair
wakeupEvent BodyEvent
Dispatched after a sleeping body has woken up. @event wakeup;
getter/setter pair