如何在三个JS中添加自定义平移事件。在这里,我已禁用轨迹球控件,并将自定义事件用于旋转和缩放功能。在这里,我希望将PAN功能添加到以下代码中。 向我建议一些PAN自定义事件的示例 这是小提琴 https://jsfiddle.net/AjayVenkatesh/e5osm69a/2/
renderer.domElement.addEventListener('mousedown', event => {
isDragging = true;
});
renderer.domElement.addEventListener('mousemove', function (e) {
const that = this;
var deltaMove = {
x: e.offsetX - previousMousePosition.x,
y: e.offsetY - previousMousePosition.y
};
if (isDragging) {
var deltaRotationQuaternion = new THREE.Quaternion()
.setFromEuler(new THREE.Euler(
toRadians(deltaMove.y * 1),
toRadians(deltaMove.x * 1),
0,
'XYZ'
));
cube.quaternion.multiplyQuaternions(deltaRotationQuaternion, cube.quaternion);
}
previousMousePosition = {
x: e.offsetX,
y: e.offsetY
};
});
function toRadians(angle) {
rotateSpeed = 0.1;
return angle * (Math.PI / 180) * rotateSpeed;
}