我在这个图书馆工作了很短的时间,但我遇到了一个让我很生气的问题。
我有 2 个立方体,一个带有 phisy.js,另一个带有三个.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 上创建它,因为网络工作者)
http://demo.cristobaldiaz.cl/test/
我也将源代码留在了 zip 文件中 ---> http://demo.cristobaldiaz.cl/test/issue.zip
您可以在http://demo.cristobaldiaz.cl/test/src/app.js第 95 行检查运动功能
无论如何,如果你用鼠标旋转相机,你可以检查当你将立方体旋转到红色网格的方向时出现问题。