Created
March 3, 2020 21:44
-
-
Save duhaime/82b4a5a25ddc8a4d592a6f35447f5fda to your computer and use it in GitHub Desktop.
Zoom to cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
controls.noZoom = true; | |
window.addEventListener('mousewheel', function(e) { | |
e.preventDefault(); | |
var x = ( event.clientX / window.innerWidth ) * 2 - 1, | |
y = - ( event.clientY / window.innerHeight ) * 2 + 1, | |
vector = new THREE.Vector3(x, y, 1), | |
factor = 0.005, | |
func = e.deltaY < 0 ? 'addVectors' : 'subVectors'; | |
vector.unproject(camera); | |
vector.sub(camera.position); | |
camera.position[func](camera.position,vector.setLength(factor)); | |
controls.target[func](controls.target,vector.setLength(factor)); | |
camera.updateProjectionMatrix(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment