The Dolly-Zoom effect

Blitz3D Forums/Blitz3D Programming/The Dolly-Zoom effect

Kryzon(Posted 2013) [#1]
Also known as the "vertigo effect", the dolly-zoom is a cinematographic camera effect achieved by zooming in the camera and moving it away from the subject (or inversely, zooming out and moving it closer to the subject).

You get this:



While the subject's appearance remains pretty much the same, the background and surrounding elements all expand or diminish in a sort of unsettling way because the perspective is changing.

The math behind it, in simple words, consists of finding what position the camera needs to be at if it zooms with a certain field-of-view - you are compensating for the loss of view by "physically" moving the camera.
It's not an approximation, it's the ideal value.

Blitz3D code:


...and an executable version for the people who don't have Blitz3D right now but still want to see it in action: dollyZoom.zip

Now imagine in your game you look down a cliff and play this effect. Good stuff.

Last edited 2013


Floyd(Posted 2013) [#2]
I don't quite see the point of all those FOV and compensationValue calculations.

Zoom factor and size on screen are directly proportional; if the CameraZoom doubles then the size on screen doubles.
( For a 3D entity that's approximate because different parts are different distances from the camera )

That means you must adjust distance and zoom so their ratio is unchanged. See CameraZoom in this example.



Trivia note: I checked imdb.com after seeing this thread. Kim Novak, the star of Vertigo, turns eighty in a few weeks.

Last edited 2013


Kryzon(Posted 2013) [#3]
Well, that just blew my mind good sir.

This is my reasoning behind the FOV calculations:





I was also thinking about using camera scale. If you scale a camera's Z axis you get the same effect as zooming, and since you're compressing/expanding the space that the camera can see, you simply modulate (multiply) the distance to the subject based on the inverse of that scale to compensate.

Most engines don't work with Blitz3D's zoom factor method, only with FOV angles, so there's not much to do besides using the above.
Anyway, your example illustrates the effect very well - can I produce a Code-Archive entry with it?

Last edited 2013


Floyd(Posted 2013) [#4]
can I produce a Code-Archive entry with it?

Sure, it's just a single multiplication.

To unify our methods, Blitz3D uses the concept of zoom while another common approach uses FOV.
As seen in the SetCameraFOV function they are related by

Zoom = 1 / Tan( FOV / 2 )

Now we have Zoom, D, FOV and also Zoom', D', FOV'. In the middle equation at the bottom of your diagram is

D' = D * Tan( FOV / 2 ) / Tan( FOV' / 2 )

We can rearrange this to D' * Tan( FOV' / 2 ) = D * Tan( FOV / 2 ).

Finally, replace both Tan( FOV / 2 ) with the appropriate 1 / Zoom to get
D' / Zoom' = D / Zoom
This is exactly what I was using in my example. D and Zoom both vary, but the ratio D / Zoom stays the same.


Kryzon(Posted 2013) [#5]
Thanks for the keen explanation.

In case someone stumbles on this thread, the archive entry is here: http://blitzbasic.com/codearcs/codearcs.php?code=3014
The FOV and distance ratio methods give the same results, but the Z-scale I mentioned earlier seems to disrupt the lighting of the scene.