Zoom to object in ThreeJS

前端 未结 6 1441
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 09:08

Where can I change the zoom direction in three.js? I would like to zoom in the direction of the mouse cursor but I don\'t get where you can change the zoom target.

6条回答
  •  萌比男神i
    2020-12-10 09:45

    OK! I solved the problem like this...just disable the zoom which is provided by THREEJS.

    controls.noZoom = true;
    
    $('body').on('mousewheel', function (e){
    
            var mouseX = (e.clientX - (WIDTH/2)) * 10;
            var mouseY = (e.clientY - (HEIGHT/2)) * 10;
    
            if(e.originalEvent.deltaY < 0){ // zoom to the front
                camera.position.x -= mouseX * .00125;
                camera.position.y += mouseY * .00125;
                camera.position.z += 1.1 * 10;
                controls.target.x -= mouseX * .00125;
                controls.target.y += mouseY * .00125;
                controls.target.z += 1.1 * 10;
            }else{                          // zoom to the back
                camera.position.x += mouseX * .00125;
                camera.position.y -= mouseY * .00125;
                camera.position.z -= 1.1 * 10;
                controls.target.x += mouseX * .00125;
                controls.target.y -= mouseY * .00125;
                controls.target.z -= 1.1 * 10;
            }
    });
    

    I know it's not perfect...but I hop it will help you a little bit....anyway...I'll work on it to make it even better.

提交回复
热议问题