diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-05-20 14:28:40 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-05-20 14:28:40 +0400 |
commit | 4916c44af8a2c916c8f2e1d82ace4af9a2e797a6 (patch) | |
tree | 5981efe3534bfad4899d5699da4216bf7cc0311b /release | |
parent | 2999d0fad9f2a7ec88315610bf998f63b6b97322 (diff) |
simplify window_to_3d_vector() and call it from viewline()
also update python view function to match.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/bpy_extras/view3d_utils.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/release/scripts/modules/bpy_extras/view3d_utils.py b/release/scripts/modules/bpy_extras/view3d_utils.py index 60436328477..7d37b94982f 100644 --- a/release/scripts/modules/bpy_extras/view3d_utils.py +++ b/release/scripts/modules/bpy_extras/view3d_utils.py @@ -36,17 +36,19 @@ def region_2d_to_vector_3d(region, rv3d, coord): """ from mathutils import Vector - viewvec = rv3d.view_matrix.inverted()[2].xyz.normalized() - if rv3d.is_perspective: - dx = (2.0 * coord[0] / region.width) - 1.0 - dy = (2.0 * coord[1] / region.height) - 1.0 + persinv = rv3d.perspective_matrix.inverted() + + out = Vector(((2.0 * coord[0] / region.width) - 1.0, + (2.0 * coord[1] / region.height) - 1.0, + -0.5 + )) - persmat = rv3d.perspective_matrix.copy() - perspinv_x, perspinv_y = persmat.inverted().to_3x3()[0:2] - return ((perspinv_x * dx + perspinv_y * dy) - viewvec).normalized() + w = (out[0] * persinv[0][3]) + (out[1] * persinv[1][3]) + (out[2] * persinv[2][3]) + persinv[3][3] + + return ((out * persinv) / w) - rv3d.view_matrix.inverted()[3].xyz else: - return viewvec + return rv3d.view_matrix.inverted()[2].xyz.normalized() def region_2d_to_location_3d(region, rv3d, coord, depth_location): |