How to switch camera between perspective and orthographic with similar 'zoom'?

  if (this._cameraState.type == CameraMode.Perspective) {
    this._mainCamera = this._perspectiveCamera;
    this._mainCamera.position.copy(this._orthographicCamera.position);
    this._mainCamera.rotation.copy(this._orthographicCamera.rotation);
  } else if (this._cameraState.type == CameraMode.Orthographic) {
    this._mainCamera = this._orthographicCamera;
    this._mainCamera.position.copy(this._perspectiveCamera.position);
    this._mainCamera.rotation.copy(this._perspectiveCamera.rotation);
  }

  this._control.object = this._mainCamera;

I hope the visual effect is similar when I switch the mode. Position and rotation work fine, but how to copy ‘zoom’? Directly copy zoom from perspectiveCamera seems useless.:grimacing: I think perspective camera’s ‘zoom’ is determined by distance.:thinking:

My related question: How to make a CombinedCamera? - #3 by ToniFF (I have to manage two cameras myself without an available CombinedCamera. I tried to update cameras like what CombinedCamera do in toOrthographic and toPerpspective, but I failed.)

Hi,

“zooming” can have different meaning depending on the context… In a orthographic camera context, it means reducing the frustum, and in perspective it could mean moving the camera forth OR decreasing the FOV.

So what you really want to do I guess is to tweak these parameters depending on the camera your are using, in order to make an object take the same space on screen.

There is a thread where you can find how to do this, and if you search the forum you can find more.

1 Like

This is useful for me to set my camera’s position at begin!:hugs: But the function can’t be used on orthographic cameras because it require’s camera’s fov. My problem is that after I make any random controls by OrbitControls with perspective camera, how to copy the state with orthographic camera? (And copy orthographic to perspective when I switch the mode again).

But you can use the same concept with orthographic camera I think.
Namely, an “illusion of same zoom” function that takes as argument the object to focus on ( you need a reference ), in which you get the distance between the centre of this object and each plane of the camera frustum ( but near and far planes ). Once you have these distances, you switch to orthographic camera with the same position and rotation than the perspective camera, as you already did apparently, and then you set the ortho camera’s frustum planes to the distances you got earlier.
Would it seem like a good option ?

There is no one-size-fit-all option, because you must adapth the frustum according to a reference object, as illustrated on this drawing :

2 Likes

I can’t fully understand but I will try to make it. Thank you! :smiling_face_with_three_hearts: