Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

three.js perspectiveCamera + orbitControl how I can get current "zoom" level?

I try to detect current zoom level ( or something like this ) in Three.js scene. I mean "zoom" (dolly) applied by mouse wheel action for example: simple scene contain : perspectiveCamera + orbitControl + object

1: `<= test is here

controls = new THREE.OrbitControls( camera );
controls.dollyOut = function(){    }
controls.dollyIn = function(){    }

controls.addEventListener('change', renderlog); ....` 

TNX

like image 978
den.ts Avatar asked Oct 23 '18 08:10

den.ts


1 Answers

When you are using a PerspectiveCamera in combination with OrbitControls, you have to be aware that "zooming" is not as a variable as it is with a orthographic camera. Instead "zooming" is done by just placing the camera closer to the target.

This means you can get the zoom distance by calculating the distance between the target and the camera position.

var zoom = controls.target.distanceTo( controls.object.position )
like image 89
Ferrybig Avatar answered Oct 31 '22 22:10

Ferrybig