I'm pretty new to three.js so I'm sorry if this question seems a bit convoluted.
So I already have my scene set up in three.js, but I want my camera's position to animate smoothly from point A to point B (I will specify the positions for A and B in my code). I would probably do this using Tween.js to ease the camera animation.
I want my camera's change in position to happen whenever the left mouse button is clicked. So basically, the camera's position gets toggled from position A to position B and vice versa whenever the left mouse button is clicked anywhere on the scene.
However, I'm not sure how to even replicate something like this. I found tutorials on how to change positions whenever the mouse is held down, but nothing that toggles the position back and forth, in fixed positions, whenever the mouse is clicked. I don't know if to do this I would have to make an 'if' statement in the function render() section of my code, that states if the mouse is clicked to change camera position, but I guess that would be too simple?
Any help is appreciated.
EDIT:
Here's the code for my render() scene:
function render() {
var timer = Date.now() * 0.00030;
camera.position.x += ( 0.5*Math.sin( timer ) * mouseX - camera.position.x ) * 0.05;
camera.position.y += ( 0.5*Math.cos( timer ) *- mouseY - camera.position.y ) * 0.05;
camera.position.z = 0;
camera.lookAt( scene.position );
for ( i = 0; i < scene.children.length; i ++ ) {
var object = scene.children[ i ];
if ( object instanceof THREE.Points ) {
object.rotation.y = time * ( i < 4 ? i + 1 : - ( i + 1 ) );
}
}
for ( i = 0; i < materials.length; i ++ ) {
color = parameters[i][0];
h = ( 0 * ( color[0] + time ) % 360 ) / 360;
materials[i].color.setHSL( h, color[1], color[2] );
}
renderer.render( scene, camera );
}
Just to clarify, I was hoping to animate camera.position.z = 0;
to a different specific position whenever the left mouse button is clicked on my scene.