Why does linear interpolation pose a problem?
When calling zoomCamera() inside an update() function that is being animated,
there is a smooth lerp effect. However, when called within the onObjectsClick() function, the lerp is sharp.
function onObjectsClick(event) {
event.preventDefault();
setPickPosition(event);
raycasting(pickPosition, scene, camera);
pickedObject = intersectedObjects[0].object;
const notebook = pickedObject.getObjectByName('notebook');
const laptop = pickedObject.getObjectByName('laptop');
if (notebook || laptop) {
zoomCamera();
}
}
canvas.addEventListener('click', onObjectsClick, false);
Within the if statement, there is no smooth lerp effect like in the update(), only a sharp transition. What am I missing?
function zoomCamera() {
const vec = new THREE.Vector3(-1, 2, 2);
const alpha = .1;
camera.position.lerp(vec, alpha);
console.log('zoom');
}
Also, why is onObjectsClick() being called within the animate() function?