我正在尝试使用threeJS来控制我场景中的相机。我目前使用键盘上的左右键将相机设置为围绕我的对象绕一圈运行。但是有人知道我会如何缩放吗?这是我当前的代码:
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.set(0,20,35);
var rotSpeed = .02;
function checkRotation(){
var x = camera.position.x,
y = camera.position.y,
z = camera.position.z;
if (keyboard.pressed("left")){ //MH - find a way to do this in a switch statement
camera.position.x = x * Math.cos(rotSpeed) + z * Math.sin(rotSpeed);
camera.position.z = z * Math.cos(rotSpeed) - x * Math.sin(rotSpeed);
} else if (keyboard.pressed("right")){
camera.position.x = x * Math.cos(rotSpeed) - z * Math.sin(rotSpeed);
camera.position.z = z * Math.cos(rotSpeed) + x * Math.sin(rotSpeed);
} else if(keyboard.pressed("up")){
//zoom in
} else if (keyboard.pressed("down")){
//zoom out
}
camera.lookAt(scene.position);
}