Table Of Contents

Previous topic

19.6. The RayHit Object

Next topic

19.8. The Shape Object

This Page

19.7. The RigidBody Object

A RigidBody object represents a dynamic body that physically reacts to collisions with other rigid bodies or with collision objects.

19.7.1. Constructor

A RigidBody object can be constructed with PhysicsDevice.createRigidBody.

19.7.2. Methods

19.7.2.1. calculateTransform

Summary

Calculates the world matrix of the rigid body.

Syntax

var transform = mathDevice.m43BuildIdentity();
var n, rigidBody, node;
for (n = 0; n < numNodes; n += 1)
{
    rigidBody = rigidBodies[n];
    node = nodes[n];

    rigidBody.calculateTransform(transform, node.origin);

    drawNode(node, transform);
}

The transform parameter should be a Matrix43 object and it will be set to the world matrix of the rigid body.

The optional origin parameter can be used to offset the world matrix.

19.7.2.2. calculateExtents

Summary

Calculates the world extents of the rigid body.

Syntax

var extents = [];
rigidBody.calculateExtents(extents);

The extents parameter is the world extents of the rigid body.

19.7.2.3. clone

Summary

Clones the rigid body.

Syntax

var clonedRigidBody = rigidBody.clone();

Returns a new rigid body identical to the original and located at the same position.

19.7.3. Properties

19.7.3.1. transform

Summary

The Matrix43 object representing the rotation and location of the rigid body.

Changing the transform could be an expensive operation because the internal acceleration structures may need updating. Also, it should only be done for kinematic objects.

Syntax

// Get the current location
var matrix = rigidBody.transform;

// Move it to the origin
rigidBody.transform = mathDevice.m43BuildIdentity();

Note

This property is implemented using getters and setters. Setting the property copies the vector values to the RigidBody’s internal storage, and querieng the property generates a new vector and copies the values from the RigidBody’s internal storage.

// THIS WILL NOT WORK!!!
rigidBody.transform[10] = 4;

// THIS WILL NOT WORK!!!
VMath.m43Copy(newTransform, rigidBody.transform);

19.7.3.2. linearVelocity

Summary

The Vector3 object representing the linear velocity of the rigid body in world space.

Syntax

// Get current linear velocity
var linearVelocity = rigidBody.linearVelocity;

// Double it
rigidBody.linearVelocity = mathDevice.v3ScalarMul(linearVelocity, 2.0);

Note

This property is implemented using getters and setters. Setting the property copies the vector values to the RigidBody’s internal storage, and querieng the property generates a new vector and copies the values from the RigidBody’s internal storage.

// THIS WILL NOT WORK!!!
rigidBody.linearVelocity[1] = 4;

// THIS WILL NOT WORK!!!
VMath.v3Copy(newVelocity, rigidBody.linearVelocity);

19.7.3.3. angularVelocity

Summary

The Vector3 object representing the angular velocity of the rigid body.

Syntax

// Get current angular velocity
var angularVelocity = rigidBody.angularVelocity;

// Double it
rigidBody.angularVelocity = mathDevice.v3ScalarMul(angularVelocity, 2.0);

Note

This property is implemented using getters and setters. Setting the property copies the vector values to the RigidBody’s internal storage, and querieng the property generates a new vector and copies the values from the RigidBody’s internal storage.

// THIS WILL NOT WORK!!!
rigidBody.angularVelocity[1] = 4;

// THIS WILL NOT WORK!!!
VMath.v3Copy(newVelocity, rigidBody.angularVelocity);

19.7.3.4. linearDamping

Summary

The linear damping set to the rigid body.

Syntax

// Get current linear damping
var linearDamping = rigidBody.linearDamping;

// Double it
rigidBody.linearDamping = (2.0 * linearDamping);

19.7.3.5. angularDamping

Summary

The angular damping set to the rigid body.

Syntax

// Get current angular damping
var angularDamping = rigidBody.angularDamping;

// Double it
rigidBody.angularDamping = (2.0 * angularDamping);

19.7.3.6. active

Summary

True if the rigid body is currently flagged as active, false otherwise.

Syntax

// Is the body active
var isActive = rigidBody.active;

// Put to sleep
rigidBody.active = false;

19.7.3.7. shape

Summary

The Shape object assigned to the rigid body.

Syntax

var shape = rigidBody.shape;

Note

Read Only

19.7.3.8. mass

Summary

The mass of the rigid body.

Syntax

var mass = rigidBody.mass;

Note

Read Only

19.7.3.9. inertia

Summary

The Vector3 object representing the inertia of the rigid body.

Syntax

var inertia = rigidBody.inertia;

Note

Read Only

19.7.3.10. group

Summary

The collision group number assigned to the rigid body.

Syntax

var collisionGroup = rigidBody.group;

Note

Read Only

19.7.3.11. mask

Summary

The collision mask number assigned to the rigid body.

Syntax

var collisionMask = rigidBody.mask;

Note

Read Only

19.7.3.12. userData

Summary

The user object associated with the rigid body.

Syntax

// Get current user object
var sceneOwner = rigidBody.userData;

// Set a new one
rigidBody.userData = doorEntity;

19.7.3.13. friction

Summary

The friction value of the rigid body.

Syntax

// Get current friction
var friction = rigidBody.friction;

// Double it
rigidBody.friction = (2.0 * friction);

19.7.3.14. restitution

Summary

The restitution value of the rigid body.

Syntax

// Get current restitution
var restitution = rigidBody.restitution;

// Half it
rigidBody.restitution = (0.5 * restitution);

19.7.3.15. kinematic

Summary

True if the rigid body was created as kinematic, false otherwise.

Syntax

var isKinematic = rigidBody.kinematic;

Note

Read Only