我使用这个库的时间很短,我有一个问题要了我的命。
我有两个立方体,一个是phisy.js的,另一个是three.js的,我有一个函数可以在你按下A、S、D或W键时根据相机的旋转来旋转它们,我的代码是这样的:
var v = new THREE.Vector3(0, 0, 0);
if (keys.forward === 1)
v.x = -1;
if (keys.right === 1)
v.z = 1;
if (keys.backward === 1)
v.x = 1;
if (keys.left === 1)
v.z = -1;
//get the searched angle
var angle = camera.rotation.y + Math.atan2(v.x, v.z);
var rot = normalMesh.rotation.y;
var diff = angle - rot;
if (Math.abs(diff) > Math.PI) {
//find the shortest way to rotate
if (diff > 0)
rot += 2 * Math.PI;
else
rot -= 2 * Math.PI;
diff = angle - rot;
}
//get the /2 for a smooth rotation, i really need this
if (diff !== 0)
rot += diff / 2;
normalMesh.rotation.set(0, rot, 0);在three.js多维数据集上工作正常,但在physi.js多维数据集上我不能工作。
我为此创建了一个演示(我不能在jsfiddle上创建它,因为web worker)
http://demo.cristobaldiaz.cl/test/
我还把源代码放在一个压缩文件中-> http://demo.cristobaldiaz.cl/test/issue.zip
您可以在http://demo.cristobaldiaz.cl/test/src/app.js第95行上检查移动功能
无论如何,如果您使用鼠标旋转摄影机,则可以检查当您将立方体旋转到红色网格的方向时是否出现问题。
发布于 2016-06-19 17:23:15
可以从动画循环中移除旋转更新,并将其移动到物理循环中:
scene.addEventListener('update', function(){
actor.onRender();
})这样,它将始终保持同步。
有关更多详细信息,请参阅此页面https://github.com/chandlerprall/Physijs/wiki/Callbacks-&-Events。
https://stackoverflow.com/questions/27653572
复制相似问题