How to set zooming based on the position of cursor in mouse-wheel?

This is now in the latest version of Babylonjs, see https://playground.babylonjs.com/#GT8E7R#1 for an example.

1 Like


Updated Babylon to version 5.0.0-alpha.15.
But the method “zoomToMouseLocation” doesn’t work. :sleepy:

You’ll need to use “latest” version:
image

Thank! Happened!
But what if the objects are not located at the center of the coordinate system?
The camera begins to behave inappropriately.

can you provide a playground example of the problem you describe?

https://playground.babylonjs.com/#Q8VH3H#7

box.position = new BABYLON.Vector3(-10, -50, 0);
sphere.position = new BABYLON.Vector3(0, -40, 0);
plane.position.z = 10;
plane.position.y = -50;
cylinder.position.z = -10;
cylinder.position.y = -50;
cylinder.position.y = -50;
torus.position.x = 10;
torus.position.y = -50;
knot.position.y = -60;

Imagine that we have moved all the elements below.
I want the camera to be at the bottom now too. And everything worked the same way as in the center of the coordinate system.

Try this version: https://playground.babylonjs.com/#Q8VH3H#11

1 Like

Hi @clovett, this is amazing, a total upgrade of the experience in my app with a single line of code, thank you! I was wondering if the pinch-zoom support was added yet? And if no, is there a way to help?

1 Like

Yes it’d be great to have pinch zoom to location in both Babylon.js and Babyon Native.

Sorry for the ignorance, but - is it not the case?

In my testing it only works with mouse wheel zoom, not pinch zoom. The method is ArcRotateCamera.zoomToMouseLocation() ArcRotateCamera | Babylon.js Documentation

that’s a different subject then, no? Is there an issue specifically in babylon native?

If you want this feature we take feature requests, and I am sure @PolygonalSun can comment on that :slight_smile:

AFAIK, zoomToMouseLocation is only applicable to the mouse wheel but I could see it potentially being adapted for use with the pinch zoom gesture. I could see this being a good feature to request but it may take a while before it gets implemented. If it’s needed or wanted sooner than later, I could also recommend to take a crack at implementing it and putting it in a pull request.

2 Likes