Table Of Contents

Previous topic

21.33. The Observer Object

Next topic

21.35. The PostEffects Object

This Page

21.34. The PhysicsManager Object

Provides loading and managing of physics nodes. Physics nodes are linked to target scene nodes which they update with the results of physics simulation, DynamicsWorld.update(), by calling the PhysicsManager.update() method. When the target SceneNode the physics object it bound to is destroyed the physics objects are destroyed too. If the SceneNode is removed from the scene the developer is responsible for disabling the physics objects, if they wish to do so. Rigid body nodes should not have a parent node.

Required scripts

The PhysicsManager object requires:

/*{{ javascript("jslib/physicsmanager.js") }}*/
/*{{ javascript("jslib/utilities.js") }}*/

As well as the SceneNode’s required scripts.

21.34.1. Constructor

21.34.1.1. create

Summary

Syntax

var physicsManager = PhysicsManager.create(mathsDevice, physicsDevice, dynamicsWorld);

21.34.2. Methods

21.34.2.1. addNode

Summary

Add a SceneNode and its relevant physics object to the manager.

Syntax

physicsManager.addNode(sceneNode, physicsObject, origin, triangleArray);
SceneNode
The SceneNode object.
physicsObject
The physics object to be assigned to the SceneNode.
origin
Optional parameter to offset the world matrix for the physics object.
triangleArray
Optional parameter to set the triangle array to be used for debug rendering.

Note

This method calls enableHierarchy.

21.34.2.2. update

Summary

Called once a frame after the physics simulation to write back the state from the physics nodes back to the target scene nodes.

This should be called after DynamicsWorld.update() but before Scene.update().

Syntax

physicsManager.update();

21.34.2.3. enableHierarchy

Summary

Called to enable or disable physics simulation of a SceneNode and its descendants.

Syntax

physicsManager.enableHierarchy(sceneNode, enabled);
SceneNode
The SceneNode object.
enabled
A JavaScript boolean.

21.34.2.4. enableNode

Summary

Called to enable or disable physics simulation of a SceneNode.

Syntax

physicsManager.enableNode(sceneNode, enabled);
SceneNode
A SceneNode object.
enabled
A JavaScript boolean.

21.34.2.5. deleteHierarchy

Summary

Called to remove physics objects from a SceneNode and its descendants.

Syntax

physicsManager.deleteHierarchy(sceneNode);
SceneNode
The SceneNode object.

21.34.2.6. deleteNode

Summary

Called to remove physics objects from a SceneNode.

Syntax

physicsManager.deleteNode(sceneNode);
SceneNode
A SceneNode object.

21.34.2.7. calculateHierarchyExtents

Summary

Called to calculate the extents of the physics objects of a SceneNode and its descendants.

Returns undefined if there are none.

Syntax

var physicsExtents = physicsManager.calculateHierarchyExtents(sceneNode);
SceneNode
The SceneNode object.

Returns an extents object.

21.34.2.8. calculateExtents

Summary

Called to calculate the extents of the physics objects of a SceneNode.

Returns undefined if there are none.

Syntax

var physicsExtents = physicsManager.calculateExtents(sceneNode);
SceneNode
The SceneNode object.

Returns an extents object.

21.34.2.9. createSnapshot

Summary

Create a snapshot of the state of all the dynamic physic objects.

Syntax

var snapshot = physicsManager.createSnapshot();

Returns a snapshot object.

21.34.2.10. restoreSnapshot

Summary

Restore the state of all the dynamic physic objects from the snapshot object.

Syntax

physicsManager.restoreSnapshot(snapshot);

21.34.3. Properties

21.34.3.1. version

Summary

The version number of the PhysicsManager implementation.

Syntax

var versionNumber = physicsManager.version;