我希望能够使用鼠标绕伽马轴旋转3D对象,就像在此示例中:https://www.jasondavies.com/maps/rotate/一样,但是在Three.js中。我有一些代码,其中网格是3D立方体,我可以围绕世界z轴旋转它,但是我不知道如何使旋转取决于鼠标的位置(角度)。我将摄像机位置设置为:camera.position.set(0,0,5)。
function mouseMove(e) {
if(isDragging) {
var deltaMove = {
x: e.offsetX - previousMousePosition.x,
y: e.offsetY - previousMousePosition.y
};
var rotation = mesh.matrix;
var rotationSpeed;
if (isDraggingCircle) {
var angle=0.1;
var worldZAxis = new THREE.Vector3(0, 0, 1).applyMatrix4(new
THREE.Matrix4().getInverse(rotation));
var rotationWorldZ = new
THREE.Matrix4().makeRotationAxis(worldZAxis, angle);
rotation.multiply(rotationWorldZ);
}
}
previousMousePosition = {x: e.offsetX, y: e.offsetY};
mesh.matrixAutoUpdate = false;
mesh.matrix = rotation;
}