x


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.

more ▼

asked Apr 14 '11 at 07:03 AM

Aurelio Provedo gravatar image

Aurelio Provedo
92 1 1 7

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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;
more ▼

answered Apr 14 '11 at 07:38 AM

DaveA gravatar image

DaveA
26.5k 151 171 256

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.

Apr 14 '11 at 07:46 AM Aurelio Provedo

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.

Apr 14 '11 at 07:57 AM Jean Fabre

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.

Apr 14 '11 at 09:38 AM Aurelio Provedo

Posted code, above

Apr 14 '11 at 05:11 PM DaveA

What is variable 'd' for?

Apr 15 '11 at 06:39 AM Aurelio Provedo
(comments are locked)
10|3000 characters needed characters left
more ▼

answered May 16 '11 at 06:13 AM

anomalous_underdog gravatar image

anomalous_underdog
335 3 6 18

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3009
x58
x57
x6
x1

asked: Apr 14 '11 at 07:03 AM

Seen: 1900 times

Last Updated: Apr 14 '11 at 09:24 AM