Fix T74577: world_to_camera_view broken for off-axis projection

The issue was that the projection would be inverted.
So if you shifted 0.1 along the y axis, world_to_camera_view would act
as if you had shited it -0.1 along the y axis.
This commit is contained in:
Sebastian Parborg 2020-05-19 16:23:44 +02:00
parent 0c20fce2f2
commit 7fcf2e7d4a
Notes: blender-bot 2023-02-14 18:59:59 +01:00
Referenced by issue blender/blender-addons#74577, world_to_camera_view broken for off-axis projection
1 changed files with 4 additions and 4 deletions

View File

@ -256,15 +256,15 @@ def world_to_camera_view(scene, obj, coord):
z = -co_local.z
camera = obj.data
frame = [-v for v in camera.view_frame(scene=scene)[:3]]
frame = [v for v in camera.view_frame(scene=scene)[:3]]
if camera.type != 'ORTHO':
if z == 0.0:
return Vector((0.5, 0.5, 0.0))
else:
frame = [(v / (v.z / z)) for v in frame]
frame = [-(v / (v.z / z)) for v in frame]
min_x, max_x = frame[1].x, frame[2].x
min_y, max_y = frame[0].y, frame[1].y
min_x, max_x = frame[2].x, frame[1].x
min_y, max_y = frame[1].y, frame[0].y
x = (co_local.x - min_x) / (max_x - min_x)
y = (co_local.y - min_y) / (max_y - min_y)