我目前正在尝试使用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,但它只是来回摆动。任何人都可以如此善良并解释为什么会发生这种情况,也许可以提供一个解决方案来保持对象旋转?
答案 0 :(得分: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;
};