3
$\begingroup$

This isn't for an animation, so I'm not inserting keyframes - as I view the model through the virtual camera, I want to experiment with different focal length values in Eevee and Cycles; but to not lose the model, I want to move along the Y-axis specifically to keep the model roughly the same size in the frame.

$\endgroup$
4
  • $\begingroup$ Can't you just select the camera then press G + Y to move the camera on the Y axis? While keeping the camera focused on one object by setting the camera to do so in the camera settings? $\endgroup$ Commented Feb 1, 2020 at 4:23
  • 1
    $\begingroup$ Sure, but that would not be driving the camera's movement with the Focal Length. $\endgroup$ Commented Feb 1, 2020 at 4:44
  • 1
    $\begingroup$ The local -Z axis is the "business end" of a camera. Related blender.stackexchange.com/questions/107365/… blender.stackexchange.com/questions/128185/… blender.stackexchange.com/questions/130404/… $\endgroup$
    – batFINGER
    Commented Feb 1, 2020 at 12:05
  • $\begingroup$ Last night when I should have been sleeping, I wondered if I'm looking for a scripted expression. Camera's Z; d'oh! Yes, thank you. :) I think my first time making some python code will be ugly enough to offend a lot of people; I'll use another object to control both parts of the camera, Location and FL. I'll find out what the code call part is for Focal Length. I'll drive it with a shapely empty's Rotation, maybe parented to the camera (in view). $\endgroup$ Commented Feb 1, 2020 at 14:16

1 Answer 1

4
$\begingroup$

This solution uses only 1 driver, to drive the y value of the camera's transform depending on its focal length.

I used a linear regression calculator online (Search "Linear regression calculator" on your favorite search engine) and I mapped a few values of the focal length and the resulting y value necessary to keep more or less the same objects in frame. I arrived at a value of y (transform) = 0.28 * focal length +1. I assume the exact values will be different from scene to scene but it can be found quite easily using said regression calculator. I used this simple setup :

enter image description here

In order to drive the y transform value, right click in the focal length field and choose "Copy as new driver". Right click in the y transform field of the camera and choose "Paste driver". Right click again in the field, and choose "Edit driver". Then change the evaluation type to "scripted expression" and enter the above formula (in my case 0.28 * lens + 1) :

enter image description here

The result :

enter image description here

Edit :

If you want to use this technique to be always true for its local z-axis, that is to say the forward/backward axis of the camera, follow this :

  • Select the camera, Press SHIFT + S then choose "Cursor to Selected"
  • Press SHIFT + A then choose "Empty" (whichever type)
  • Add a "track to" constraint to the empty, set it to one of the objects of focus in your scene. If you don't have a particular object, just add a new empty and set it somewhere in the middle of your scene. The constraint should look like this :

enter image description here

  • Select the camera object, then the empty, and press CTRL + P, choose "Set parent and keep transform" Now when you move the empty around your scene, the camera should follow it exactly and always turn toward the focus object you chose earlier. Do not move the camera directly . If you followed previous steps this should already be working. You will most certainly have to tweak the values a little bit though.

Result :

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ Wow. The linear regression tip is really handy. Local -Z might be more general than Global Y? Maybe not, you'd have to define a target... $\endgroup$
    – Robin Betts
    Commented Feb 2, 2020 at 15:21
  • $\begingroup$ Of course ! I updated my answer for the local Z axis $\endgroup$
    – Gorgious
    Commented Feb 2, 2020 at 18:21
  • $\begingroup$ I am delighted. At first I didn't think this was really answerable - then I stumbled and fumbled my way onto another object affecting the Camera Global Y (thru Transform constraint) and that Y location Driving the "lens" mm. There's no Copy/Paste involved, it updates IRT like your update; however, yours answers the initial question! So I'm picking it. Mine answers the later thought, so I could be compelled to post it unless BSE frowns on such things. "Linear Regression." Never heard of it until now. Sincere thanks! $\endgroup$ Commented Feb 3, 2020 at 17:39
  • $\begingroup$ @HelloHiHola Alright, I am interested, do post it if you find the time ! A Linear regression is just a way to "reverse engineer" an affine equation of type y = a * x + b when you just have several x values and their corresponding y values. It only works for linear equations though. (no y = a * x ^2 + b * x + c for instance, this one is a little bit more complicated since it can have multiple or non-real solutions) anyways, MATHS are fun ! :) $\endgroup$
    – Gorgious
    Commented Feb 4, 2020 at 10:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .