1
$\begingroup$

I apologize if this isnt in the right section, but I figured there would be some scripting involved to do this process.

What I am looking to do is get the 0,0,0 point to the middle of the camera. I would like to be able to maintain the angle at which the scene is at and not rotate the camera, but instead just have it so the 0,0,0 point becomes the middle of the cameras view.

enter image description here

Lets say this is the view after orienting the camera, and the 0,0,0 point is to the right of center in the camera view

enter image description here

I would like to be able to maintain the rotation of the camera that has been made, but get the view to snap so the 0,0,0 point is in the middle of the cameras view

$\endgroup$

3 Answers 3

2
$\begingroup$

Although the Track To constraint will always put the origin in the middle of the camera view, they will change the rotation of the camera, as it will stay fixed in place.

To keep the rotation we have to find a new location for the camera, presumably only moving within the camera's xy-plane, where it's viewing direction (the camera's z-axis) goes through the origin. This is a simple line-plane intersection problem: Where is the intersection of the line l that goes through point l_0 (0,0,0) and the current xy camera plane, defined by normal vector n and point p_0? l and n are the camera's z-vector, and p_0 is the camera's location.

import bpy
from mathutils import Vector

# get camera object
camera = bpy.context.blend_data.objects["Camera"]
# get camera viewing vector, which is also the normal vector of the
# camera's xy plane
cmat = camera.matrix_world
camera_z = Vector([cmat[i][2] for i in range(3)])

# this is the new center of the camera view
l_0 = Vector((0,0,0))
l = camera_z
n = camera_z
p_0 = camera.location

new_loc = (p_0 - l_0).dot(n)/l.dot(n) * l + l_0

camera.location = new_loc
$\endgroup$
2
$\begingroup$

Press ShiftC to set the 3D cursor to 0,0,0

Add an empty.

Select the camera and add a Track to Constraint.

In the track to constraint set the Empty as Target.

To=-Z

Up= Y

The camera will now point point to the empty set at 0,0,0

enter image description here

$\endgroup$
1
$\begingroup$

If I understand your question correctly you don't need scripting to achieve this. -create an empty at 0,0,0 and add a trackTo constraint to the camera with that empty as target. This will keep the camera always pointing at the origin . You might have to pay with settings on the trackTo constraint to get it right. Does that help?

$\endgroup$

You must log in to answer this question.

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