Same camera on switch with targetScreenOffset

Hi,
I’d like to switch camera from ArcRotateCamera to UniversalCamera without changing the look like this thread:
https://forum.babylonjs.com/t/same-camera-on-switch/34373/4

But if the ArcRotateCamera has a targetScreenOffset, the look will change when switch camera.
https://playground.babylonjs.com/#DJP9H4#2

Any one has idea on this?
and @ Takemura

Thanks!

cc @PolygonalSun

Maybe it works if you add:

camera.onViewMatrixChangedObservable.add(() => {
    camera.getViewMatrix().multiplyToRef(new BABYLON.Matrix.Translation(2,2,0),camera.getViewMatrix())
})

in your setUpUniversalCamera-function. Where (2,2,0) is (arcCamera.targetScreenOffset.x,arcCamera.targetScreenOffset.y,0).

1 Like

Yes, I quickly checked something like that. But then, you have to make sure it also does it correctly when returning to the other camera. I suppose you would need to store these offset values and pass them on to the camera. I’m also not sure that the alpha and beta values from the arcRotateCamera are kept the same (since they work from the target).

1 Like

I know that I did something similar to this in an old PG: ArcRotateCamera Offset Demo | Babylon.js Playground (babylonjs.com)

You could probably use something like Vector3.TransformCoordinates(arcCamera.target.position, arcCamera.getViewMatrix()); to get an offset for the ArcRotateCamera’s target and then apply that to your UniversalCamera’s position. Based on your PG’s code though, it might be good to either clone the camera positions or copy the float values to avoid clobbering the other camera’s position (setting one camera’s position vector to the other)

This function call is effectively what AbstractMesh.getPositionInCameraSpace is doing.