9

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

den.ts
  • 103
  • 1
  • 8
  • 1
    You should add your code in your question instead of a link to it. Editing it you can use the code snippet editor. – PJProudhon Oct 23 '18 at 09:02

1 Answers1

16

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 )
Ferrybig
  • 18,194
  • 6
  • 57
  • 79
  • Perspective Camera with Orbit Control when zoomed it does not change position of camera , it changed projection ( I think ) – den.ts Oct 24 '18 at 07:09
  • But maybe you right : http://jsfiddle.net/denis_miroshnikov_ts/7teqkspu/92/ look at the console – den.ts Oct 24 '18 at 07:17
  • 3
    only with an orthographic it changes the projection, with an perspective camera it changes the position – Ferrybig Oct 24 '18 at 07:52