Hi all,
I 'd like to set pivot of the arcRotateCamera, but with the screen view unchanged(user can’t notice any movement)
https://playground.babylonjs.com/#XLS3R1
I need meshes in the scene rotate around the red sphere1, if run camera.setTarget(sphere1) in line 28, the scene moves down.
I don’t hope the movement happen, any ideas?
Hey @Freeman, welcome to the community! As far as changing the pivot (target) without changing the look of the camera’s perspective, the way to do this is a bit complex. The basic steps to accomplish this are
Set the target of your ArcRotateCamera to the desired target (eg. red ball)
Set alpha/beta values for new position to match old position so that current camera direction is parallel to old camera direction
Set radius so that current camera viewport and old camera viewport are on the same plane (perpendicular to camera direction)
Move camera into place with targetScreenOffset
There are probably several ways to do this but if you are able to use inertialPanningX/Y to move your camera (and camera’s target) into place, you can use the same values for the targetScreenOffset as they both move the camera with respect to the screen, as opposed to world.
I took another try at this one and managed to make some progress.
I set targetScreenOffset equal to the delta between the x and y components of the camera’s view matrix before and after setting the target. This works well for maintaining the meshes’ screen positions but the camera’s beta is slightly off which makes the meshes appear rotated. So getting close but still not there yet. https://playground.babylonjs.com/#XLS3R1#2
Edit: after more testing, this only really helps to keep the screen positions constant when z is 0 as in the above playgrounds, which makes sense on further reflection. I’m trying other approaches out again too thou.