How to acheive a dolly zoom effect

(mtgg2000) #1

For my next animation, I want to throw aDolly Zoom in the works. My problem is, I do not know how to ‘zoom in’ a camera, I always just move it closer to the subject. Can blenders cameras zoom?

(mtgg2000) #2

Here is a quick example that I knocked up. The cube and quarter sphere in the foreground are parented to the camera so that they stay the same distance from it while the camera moves forward towards the background. I added a quick and dirty DOF to help strengthen the effect.

This seems to work ok for this example, but if there were textures on the walls, or if there were various objects at different intervals down the hallway, this effect would be exposed as a cheap trick.

So, any suggestions?

(patricia3d) #3

Select Camera, Select IPO Curve < Camera >Select Lens Chanel, On Frame 1 Put Value 35, On Frame 20 Put Value=60, On Frame 40 Put Value 35 and its now zooooooooooming.

(mtgg2000) #4

Thankyou, I did not know about the lens setting (smacks his forehead) Didn’t work quite as expected but a bit of tweaking should fix that.

(mtgg2000) #5

Wow, just had a really quick play with a couple of the other curve options inside camera. I’ve been doing things the hard way.

(chipmasque) #6

To get the full effect of a contra-zoom (dolly zoom), it’s best to keep the main subject at the same magnification (scale in image frame) while everything else changes around it:

A Blender contra-zoom

Calculating the magnification needs a proper lens focal length in mm, which the Blender Lens setting is not (last I knew, at least), so the BLenses script might help you some. The movie above was made using BLenses to animate the focal length and camera-to-subject distance. It can also be seen at the bottom of page 2 of the BLenses site.

(Crouch) #7

I’m not exactly certain what you mean by calculating the magnification, but I think it’s possible to achieve this effect without knowing a focal length. All you need is the field of view, which you can easily find (select the camera --> editing buttons --> lens, show in degrees).

The BLenses script is a very nice script, but can imho be a bit of overkill for setting up a dolly zoom (not trying to sound negative about your excellent script chipmasque, you really did some amazing work on it). Below you can find an alternative script, which only does dolly zooms.

To use it:
Animate either the lens value or the location of the camera (for best results use linear interpolation, not bezier)
Select the object you want to focus on (so the object which won’t change in size)
Run the script (alt+P)

And here’s a video with an example result.

import Blender
from Blender import *
import bpy
from math import pi, tan, atan

Dolly zoom
Written by Bartius Crouch
How to use:
    Animate either the lens value or the location of the camera
    Select the object you want to focus on (so the object which won't change in size)
    Run this script (alt+P)

# general variables
scn =
cam_ob =
cam =
ob =

def main():
    animated = False
    ipos = []
    # check if the location of the camera is animated
    if cam_ob.ipo:
        if cam_ob.ipo.curves:
            active = []
            for i in cam_ob.ipo.curves:
                if"LocX" or"LocY" or"LocZ":
            if len(ipos)&gt;0:
                animated = ["loc",ipos[0].interpolation,ipos[0].extend]
    # check if the lens value is animated
    if cam.ipo:
        if cam.ipo[Ipo.CA_LENS]:
            choice = 2
            if animated:
                choice = Draw.PupMenu("Change%t|Lens animation|Location animation")
                if choice == -1:
            if choice == 2:
                animated = ["lens",ipos[0].interpolation,ipos[0].extend]
    # check if at least one parameter is animated
    if not animated:
        Draw.PupMenu("Error%t|Neither the location nor the lens-value of the camera is animated")
    # collect keyframes
    frames = []
    for ipo in ipos:
        for bp in ipo.bezierPoints:
            if[0] not in frames:
    oldframe = Blender.Get('curframe')
    # calculate constant width
    fov = cam.angle
    dist = (Mathutils.Vector(ob.loc) - Mathutils.Vector(cam_ob.loc)).length
    width = dist*2*tan(pi*(fov/360))

    # location is already animated, so set up lens animation
    if animated[0] == "loc":
        if cam.ipo:
            cam_ipo = cam.ipo
            cam_ipo[Ipo.CA_LENS] = None
            cam.ipo = Ipo.New('Camera',"CaIpo")
            cam_ipo = cam.ipo
        curve = cam_ipo.addCurve('Lens')
        for f in frames:
            dist = (Mathutils.Vector(ob.loc) - Mathutils.Vector(cam_ob.loc)).length
            fov = (360*atan(width/(2.0*dist)))/pi
            cam.angle = fov
            if fov&gt;172.85 or fov&lt;7.32:
                message = "Needed zoom is beyond the capability of Blender's camera%t|The ipo that was created doesn't create a correct dolly zoom"
                message = "Success%t|Created correct lens-ipo to set up dolly zoom"
        curve.interpolation = animated[1]
        curve.extend = animated[2]
    # lens is already animated, so set up location animation
    if animated[0] == "lens":
        if cam_ob.ipo:
            cam_ob_ipo = cam_ob.ipo
            cam_ob_ipo[Ipo.OB_LOCX] = None
            cam_ob_ipo[Ipo.OB_LOCY] = None
            cam_ob_ipo[Ipo.OB_LOCZ] = None
            cam_ob.ipo = Ipo.New('Object',"ObIpo")
            cam_ob_ipo = cam_ob.ipo
        curveX = cam_ob_ipo.addCurve('LocX')
        curveY = cam_ob_ipo.addCurve('LocY')
        curveZ = cam_ob_ipo.addCurve('LocZ')
        ori = Mathutils.Vector(ob.loc)
        for f in frames:
            dist = width/(2.0*tan(pi*(cam.angle/360.0)))
            cur_dist = Mathutils.Vector(cam_ob.loc)-ori
            cur_dist.length = dist
            loc = ori+cur_dist
        curveX.interpolation = animated[1]
        curveX.extend = animated[2]
        curveY.interpolation = animated[1]
        curveY.extend = animated[2]
        curveZ.interpolation = animated[1]
        curveZ.extend = animated[2]
        message = "Success%t|Created location-ipo to set up dolly zoom"
    # reset to the old frame and communicate what happened
    if message:

# check if camera and focus object are present
if cam_ob == ob:
    Draw.PupMenu("Error%t|Select an object to focus on (camera can't focus on itself)")
elif cam_ob and ob:
elif cam_ob:
    Draw.PupMenu("Error%t|No active object, select an object to focus on")
    Draw.PupMenu("Error%t|Couldn't find an active camera")

(chipmasque) #8

Yep, it can be done many ways, and you’re right, for just a contra-zoom, BLenses offers more than is necessary – the script can be used in many different ways, so it’s bound to be more complex than a single-function script. But it can help a lot if you want to calc some of the effects beforehand rather than tweaking 'til it looks right.

Magnification is basically the ratio of subject size to image size “on film.” In a camera, if the image is 10mm tall and the subject is 1 m tall then that’s a magnification of .01. In common terms that means the size of the subject in the image frame. To really push the contra-zoom effect it’s usually best to have the subject look as if it’s completely stationary and everything else is changing around it, like space stretching. But both a zoom and a dolly change the magnification, so with a contra-zoom, you’re using one against the other to maintain the magnification as a constant. The result is a change in field of view (as you mentioned) that also changes the perspective characteristics of the scene and that gives you the contra-zoom effect.

With an accurate focal length you can pre-calculate a lot of the animation settings (mainly camera position and focal length) and save some time in getting the effect at its best.

Or not :smiley:

(Crouch) #9

Now I see what you mean by needing the magnification, thanks for the additional info.
And you’re right of course, BLenses can be used for many more things than just this effect.

(patricia3d) #10

Thanks Crouch for sharing the script. Very usefull.