【问题标题】:CANNON.JS angular velocity behaving strangeCANNON.JS 角速度表现奇怪
【发布时间】:2014-06-18 21:35:58
【问题描述】:

我目前正在尝试使用three.js 和cannon.js。

我有一个像这样的对象:

var ship = {
    mesh: new THREE.Mesh(); //let's pretend there's a mesh in there.
    rigidBody: new CANNON.RigidBody(); //let's pretend there's a rigid body in here.
};

在更新功能上,我将网格旋转到刚体的旋转,如下所示:

var update = function(){
    ship.mesh.rotation.x = ship.rigidBody.quaternion.x;
    ship.mesh.rotation.y = ship.rigidBody.quaternion.y;
    ship.mesh.rotation.z = ship.rigidBody.quaternion.z;
};

这一切都很好,问题是当我定义一个角速度时。

ship.rigidBody.angularVelocity.z = 1; //for example

我认为物体会开始旋转,直到角速度达到 0,但它只是有点前后摇摆。谁能这么好心地解释一下为什么会这样,也许可以给出一个解决方案来保持物体旋转?

【问题讨论】:

    标签: angularjs three.js velocity cannon.js


    【解决方案1】:

    你应该这样做:

    var update = function(){
        ship.mesh.quaternion.x = ship.rigidBody.quaternion.x;
        ship.mesh.quaternion.y = ship.rigidBody.quaternion.y;
        ship.mesh.quaternion.z = ship.rigidBody.quaternion.z;
        ship.mesh.quaternion.w = ship.rigidBody.quaternion.w;
    };
    

    【讨论】:

    • ship.mesh.quaternion.copy( ship.rigidBody.quaternion ); 怎么样?
    • @WestLangley 适用于 r68dev 但不适用于 r67(我的错:/)。
    • 工作就像一个魅力。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多