# World origin coordinate in rendered image

HI,

I render some images with animations for use in a game engine. The camera is setup to an isometric view and the result looks fine.
My only problem is to offset the position in the game engine to show the animation at a realistic (0,0) position. So I need somehow to find out which 2D position in the rendered image is my world origin based on my camera. I’m sure there’s a way to calculate it. Has someone done this before? Maybe there’s a blender function for this.

Regards
Andreas

1 Like

This should help. If I understood your question correctly.

``````import bpy
from bpy_extras.object_utils import world_to_camera_view

scene = bpy.context.scene

# Getting resolution of the final render ( important to know where in pixel the point is )
render = scene.render
res_x = render.resolution_x
res_y = render.resolution_y

# Getting objects
obj = bpy.data.objects['Cube']     # The object the origin of which we want to calculate
cam = bpy.data.objects['Camera']   # The camera from which we want to calculate

# The actual XYZ location of the object ( the origin )
coords = obj.location

# Voodoo magic blender can do to find the coordinate of the point, from camera XYZ
coords_2d = world_to_camera_view(scene, cam, coords)

# Printing into the terminal the coordinates
print("In pixels X:", coords_2d.x * res_x) # in X
print("In pixels Y:", coords_2d.y * res_y) # in Y
``````

I did a quick check and the results look fine. I just need to know that the y is calculated from a bottom coordinate, but this could be fixed easy with a res_y-y.

Thanks you very much!

``````import bpy
import mathutils
from bpy_extras.object_utils import world_to_camera_view

scene = bpy.context.scene

# Getting resolution of the final render ( important to know where in pixel the point is )
render = scene.render
res_x = render.resolution_x
res_y = render.resolution_y

# Getting the current camera
cam = bpy.context.scene.camera

# The actual XYZ location of the origin
coords = mathutils.Vector((0.0, 0.0, 0.0))

# Voodoo magic blender can do to find the coordinate of the point, from camera XYZ
coords_2d = world_to_camera_view(scene, cam, coords)

# Printing into the terminal the coordinates
print("In pixels X:", coords_2d.x * res_x) # in X
print("In pixels Y:", res_y - (coords_2d.y * res_y)) # in Y
``````