ArcRotateCamera.zoomToMouseLocation does not take targetScreenOffset into account

Hello again!
I believe I found a bug so I came straight to the forum to ask about it :slight_smile:

When I set zoomToMouseLocation to true on ArcRotateCamera (cool feature btw :+1:) and also targetScreenOffset to something other than (0, 0) → it seems like its not accounted for during the zoom.

Attached is a playground demonstrating the bug: https://playground.babylonjs.com/#SRZRWV#1679 (try zooming while pointing at the left side of the plane) When you remove line 59 the zoom works as expected again.

It seems like the targetScreenOffset is simply not taken into account in the ArcRotateCameraMouseWheelInput?

Thank you in advance

1 Like

Adding @PolygonalSun our camera expert :slight_smile:

Based on what I’m seeing in the PG, it does indeed look like the offset isn’t being taken into account. Lemme take a look at the code.

1 Like

Here’s a simple PR to address the offset: ArcRotateCamera: Account for offset when using zoom to mouse location by PolygonalSun · Pull Request #13856 · BabylonJS/Babylon.js (github.com)

3 Likes

:rocket: thank you, cant wait to try it!

@PolygonalSun there is one more issue with targetScreenOffset i’m running into:
The specular reflection seems to also not take it into account… but I have a feeling that this might be by design?
Sorry if this is a noob question but I cant find much about the targetScreenOffset in the documentation and that’s why I’m not sure if it should be taken into account everywhere or only in some situations.

I updated the playground to illustrate it: https://playground.babylonjs.com/#SRZRWV#1682, when you zoom in you can see that the specular reflection is towards the original camera position without the offset… remove line 59 for comparison.

(additional context why i would really love to make this work: this is the behaviour im trying to achieve How to change the camera target without having that target automatically centered on the screen - #14 by PolygonalSun maybe you remember the old thread :slight_smile: → with these issues solved there could be a complete feature in Babylon’s ArcRotateCamera = update the target position without centering the camera which i think many people could appreciate)

I’m not too familiar with the lighting system and how the specular reflection is handled. Maybe @Evgeni_Popov might have a better idea?

It’s expected, it’s not the camera position in 3D space which is modified. The target offset is an offset in screen space, it’s as if everything was scrolled in the X/Y direction, but the specular highlight does not change place wrt the mesh.

It still seems broken? I ran into this, and testing OP’s PR still shows that it’s not quite working

What do you mean by “broken”? I tested the PG and it seems ok to me.

Regarding the highlight, it’s expected it does not change position, see my answer above.

@Evgeni_Popov

Try using the mousewheel when the camera is rotated.

Here is the playground with a rotated starting position. Try zooming in on any of the objects.

cc @PolygonalSun, it seems targetScreenOffset is not taken into account when zoomToMouseLocation = true?

It looks like it is being taken into account but there was an issue with how the offset was handled. Here’s a PR with a fix: ArcRotateCamera: Modify offset math to correctly zoom to point by PolygonalSun · Pull Request #14209 · BabylonJS/Babylon.js (github.com)

2 Likes

PR has been merged