- Home /
Transition a camera from ortographic to perspective mode (Trombone effect)
I am fiddling with the idea of implementing smooth camera transitions from ortographic to perspective mode. I think this would make for a cool effect in my videogame.
I assume that the values involved in the interpolation would be 'ortographicSize' and 'fieldOfView'.
I plan on modifying those two variables in the Update method, by using Interp or SmoothDamp or any other similar function to smooth out the values.
But, how can I correspond ortographic mode's 'size' to perspective mode's 'fieldOfView'? Is there any actual relationship between them that can be calculated?
I notice that decreasing the fieldOfView actually makes the perspective camera become more and more ortographic, while at the same time zooming in. But I don't want it to zoom in, I just want things to appear gradually flatter.
Answer by DaveA · Apr 14, 2011 at 07:38 AM
What you really want is the 'trombone effect'. Use a perspective camera, but 'fake' the ortho view by using a very small fieldOfView and set a long distance away. Then interpolate over time the fieldOfView to something normal like 60 and closer distance (or vice versa for reverse effect).
It goes something like this (my code is more complex so I'm just snipping the math out here.
Update: tmin = targetGameObject.renderer.bounds.min; tmax = targetGameObject.renderer.bounds.max;
// we would like to keep tmin and tmax constant c = (tmax.x - tmin.x) / 2;
if (Camera.main.transform.position.z > .0001 || Camera.main.transform.position.z < -.0001) Camera.main.fov = Mathf.Abs(4*180.0 / 3.14159 * Mathf.Atan(c/Camera.main.transform.position.z)); if (Camera.main.fov < 0.01) Camera.main.fov = 0.01; if (Camera.main.fov > 180.0) Camera.main.fov = 180.0;
I know, and thanks for answering BTW, but I still don't know how to match a certain 'fieldOfView' with how much zoom out I should do to compensate. I don't want the camera to zoom in or out when changing the fieldOfView.
You'll need to computer the camera view unit in world unit and modify the field of view as you animate the camera position so that the view unit/world unit ratio stays the same.
That is great, $$anonymous$$ Fabre. Thank you. But how can I calculate that? What are the variables for finding that ratio? $$anonymous$$aybe I could get the camera's 'cameraToWorld$$anonymous$$atrix' and then use $$anonymous$$ultiplyPoint() to get the world extents of the camera... I think I'm going to spend a good while studying math about projection matrices right now ;-) Oh, and post an answer ins$$anonymous$$d of a comment, so I can upvote you.
Answer by anomalous_underdog · May 16, 2011 at 06:13 AM
I found this code at the forums and it works like a charm: http://forum.unity3d.com/threads/32765-Smooth-transition-between-perspective-and-orthographic-modes
Your answer
Follow this Question
Related Questions
Help with ortographic camera 1 Answer
Unity3d or Maya-style Camera navigation 5 Answers
Direct positioning with a perspective camera? 2 Answers
Click and Drag Camera only works in Orthographic camera 1 Answer
Help Please - 2D Game Perspective Camera 2 Answers