How to calculate a point projected from the local Z axis of camera?

Long time no post! :slight_smile: Glad to be doing some Python programming in Blender again.

I’d like to figure out how to project a point somewhere down the local Z axis of the camera.

So, say the camera is at 0,0,0, and rotations are set to 90, 0, 0 such that the camera is pointed directly down the +Y axis. It’d be easy enough to project a point an arbitrary distance away down the local Z axis of the camera (let’s say 5 blender units away). The point would have a location of 0, 5, 0.

Now let’s take an arbitrary camera transformation: location of (-1, -2, 2) and rotation of (70, 0, -30). How would I calculate a point 5 blender units away directly down the local Z axis of the camera given these camera transformations?

Hi there Oh Snap,


import bpy


cam = bpy.data.objects.get("Camera")
cube = bpy.data.objects.get("Cube")


#local matrix


m = cam.matrix_local
cube.matrix_world = cam.matrix_world


m = m * m.Translation((0,0,5))


cube.matrix_world = m


VERY nice, thank you. I’ve always been a little confused by this matrix visualization in the viewport. How do you get rid of the matrix visualization after querying it like this?

Never mind.

del(m)

seems to do the trick.