Currently, I'm utilizing threeJS to manipulate a camera within my scene. The camera is configured to orbit in a circular motion around an object when the left and right keys are pressed on the keyboard. However, I am seeking guidance on how to implement zoom functionality. Below is the snippet of my existing code:
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")){
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);
}