vector - 在 Three.JS 中的 2 轴上旋转轮子
问题描述
我正在尝试在两个轴 y 和 x 上旋转对象。但它不能正常工作。这是示例
https://imge.to/i/vqyt20局部轴(无旋转)
https://imge.to/i/vqypnA旋转移动后我所拥有的
wheel1.rotation.x += movement;
wheel1.rotation.y = angle;
PS当它们都不是0时它起作用movement == 0
或失败。angle == 0
我尝试使用四元数并乘以旋转向量,但没有任何帮助。提前致谢!
解决方案:
我找到了关于围绕 y 轴矢量旋转的问题的答案
angleX += movement;
[wheel1, wheel2].forEach(function (wheel) {
let vector = new THREE.Vector3(1, 0, 0);
vector.applyAxisAngle(new THREE.Vector3(0, 1, 0), angleY);
wheel.rotation.y = angleY;
wheel.rotation.x = 0;
wheel.rotation.z = 0;
wheel.rotateOnWorldAxis(vector, angleX);
});
评论中给出的另一种解决方案是更改wheel.rotation
为'YXZ'
如何旋转对象并将其旋转重置为零?