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.
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, Jean Fabre. Thank you. But how can I calculate that? What are the variables for finding that ratio? Maybe I could get the camera's 'cameraToWorldMatrix' and then use MultiplyPoint() 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 instead of a comment, so I can upvote you.
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.
– anon32568066You'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.
– Jean-FabreThat is great, Jean Fabre. Thank you. But how can I calculate that? What are the variables for finding that ratio? Maybe I could get the camera's 'cameraToWorldMatrix' and then use MultiplyPoint() 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 instead of a comment, so I can upvote you.
– anon32568066Posted code, above
– DaveAWhat is variable 'd' for?
– anon32568066