# Getting the 0,0,0 point in the middle of the cameras view

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.

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

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

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


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