Turbulenz:物理节点如何绑定到场景节点

时间:2013-09-10 16:48:19

标签: javascript typescript game-engine scene turbulenz

如何将物理节点绑定到场景节点?

由于文档读取当对物理节点进行更新时,它传播到场景节点,我假设场景节点的变换矩阵也被更新。这是对的吗?

例如,我有以下场景:

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
    });

和以下物理节点:

       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);

但我不知道如何将它们连接在一起所以当物理球节点从高处落下时,模型也会掉下来。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我创建了一个实用程序函数来传递变量并进行绑定,是:

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);
}