How can I bound a physics node to a scene node?
Since the documentation reads that when an update is made to the physics node its propagated to the scene node I assume that the transformation matrix of the scene node is updated also. Is this correct?
For instance, I have the following scene:
this.scene = Scene.create(this.devices.mathDevice);
this.sceneLoader.load({
scene : this.scene,
append : false,
assetPath : "models/duck.dae",
keepCameras : true,
baseMatrix: this.devices.mathDevice.m43BuildTranslation(0, 100, 0),
graphicsDevice: this.devices.graphicsDevice,
mathDevice : this.devices.mathDevice,
textureManager: this.managers.textureManager,
effectManager : this.managers.effectManager,
shaderManager : this.managers.shaderManager,
requestHandler: this.requestHandler,
dynamic : true
});
and the following physics node:
var ballShape = this.devices.physicsDevice.createSphereShape({
radius: 1.0,
margin: 0.001
});
var mass = 20;
var inertia = ballShape.inertia;
inertia = this.devices.mathDevice.v3ScalarMul(inertia, mass);
var ballObject = this.devices.physicsDevice.createRigidBody({
shape : ballShape,
mass : mass,
inertia : inertia,
transform : this.scene.findNode("LOD3sp").getLocalTransform(),
friction : 0.5,
restitution: 0.3,
frozen : false,
group : this.devices.physicsDevice.FILTER_DYNAMIC,
mask : this.devices.physicsDevice.FILTER_ALL
});
this.dynamicsWorld.addCollisionObject(ballObject);
But I don't know how to link them together so when the physics ball node falls from height the model also falls down.
Thanks in advance for your help.
I created an utility function to pass it the variables and do the binding, is:
public bindPhysicsNodesWithSceneNodes(options):void {
var physicsNode = {
body : options.rigidBody,
target : options.sceneNode,
dynamic: true
};
options.sceneNode.physicsNodes = [physicsNode];
options.sceneNode.setDynamic();
options.physicsManager.physicsNodes.push(physicsNode);
options.physicsManager.dynamicPhysicsNodes.push(physicsNode);
options.physicsManager.enableHierarchy(options.sceneNode, true);
}