I 'd like to set pivot of the arcRotateCamera, but with the screen view unchanged（user can’t notice any movement）
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?
Adding @PolygonalSun for the camera
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 know that there’s another discussion about this (How to change the camera target without having that target automatically centered on the screen - #7 by foufara) but there currently is not definitive solution. You might be able to find some inspiration in this thread though.
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.
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.
Maybe I’m misunderstanding the problem, but you can use camera.lockedTarget for this.
I’m trying to find some decent example in the playground …
EDIT: On re-reading the thread, I think I am misunderstanding the problem