diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2016-12-08 14:41:27 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2016-12-08 14:41:27 +0300 |
commit | 0a26904a75100da3e7084a80a74b1269d95dfa65 (patch) | |
tree | 4b234b9af5d3fb0cf28fb04f1ff9a99014701fa3 /source/blender/editors/space_view3d/view3d_project.c | |
parent | d5708fdad6a09e1c3b8c6f68e9e852ae673705f2 (diff) |
Fix T49872: 3D cursor places with camera shift in ortographic mode
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_project.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_project.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index 7448d4c658e..65a6dee2f6c 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -28,6 +28,7 @@ * \ingroup spview3d */ +#include "DNA_camera_types.h" #include "DNA_object_types.h" #include "DNA_screen_types.h" #include "DNA_scene_types.h" @@ -40,6 +41,7 @@ #include "BLI_math_vector.h" +#include "BKE_camera.h" #include "BKE_screen.h" #include "ED_view3d.h" /* own include */ @@ -462,9 +464,12 @@ bool view3d_get_view_aligned_coordinate(ARegion *ar, float fp[3], const int mval * \param ar The region (used for the window width and height). * \param depth_pt The reference location used to calculate the Z depth. * \param mval The area relative location (such as event->mval converted to floats). - * \param out The resulting world-space location. + * \param r_out The resulting world-space location. */ -void ED_view3d_win_to_3d(const ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]) +void ED_view3d_win_to_3d( + const View3D *v3d, const ARegion *ar, + const float depth_pt[3], const float mval[2], + float r_out[3]) { RegionView3D *rv3d = ar->regiondata; @@ -488,11 +493,19 @@ void ED_view3d_win_to_3d(const ARegion *ar, const float depth_pt[3], const float else { float dx = (2.0f * mval[0] / (float)ar->winx) - 1.0f; float dy = (2.0f * mval[1] / (float)ar->winy) - 1.0f; + if (rv3d->persp == RV3D_CAMOB) { /* ortho camera needs offset applied */ + const Camera *cam = v3d->camera->data; + const int sensor_fit = BKE_camera_sensor_fit(cam->sensor_fit, ar->winx, ar->winy); const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom) * 4.0f; - dx += rv3d->camdx * zoomfac; - dy += rv3d->camdy * zoomfac; + const float aspx = ar->winx / (float)ar->winy; + const float aspy = ar->winy / (float)ar->winx; + const float shiftx = cam->shiftx * 0.5f * (sensor_fit == CAMERA_SENSOR_FIT_HOR ? 1.0f : aspy); + const float shifty = cam->shifty * 0.5f * (sensor_fit == CAMERA_SENSOR_FIT_HOR ? aspx : 1.0f); + + dx += (rv3d->camdx + shiftx) * zoomfac; + dy += (rv3d->camdy + shifty) * zoomfac; } ray_origin[0] = (rv3d->persinv[0][0] * dx) + (rv3d->persinv[1][0] * dy) + rv3d->viewinv[3][0]; ray_origin[1] = (rv3d->persinv[0][1] * dx) + (rv3d->persinv[1][1] * dy) + rv3d->viewinv[3][1]; @@ -502,13 +515,16 @@ void ED_view3d_win_to_3d(const ARegion *ar, const float depth_pt[3], const float lambda = ray_point_factor_v3(depth_pt, ray_origin, ray_direction); } - madd_v3_v3v3fl(out, ray_origin, ray_direction, lambda); + madd_v3_v3v3fl(r_out, ray_origin, ray_direction, lambda); } -void ED_view3d_win_to_3d_int(const ARegion *ar, const float depth_pt[3], const int mval[2], float out[3]) +void ED_view3d_win_to_3d_int( + const View3D *v3d, const ARegion *ar, + const float depth_pt[3], const int mval[2], + float r_out[3]) { const float mval_fl[2] = {mval[0], mval[1]}; - ED_view3d_win_to_3d(ar, depth_pt, mval_fl, out); + ED_view3d_win_to_3d(v3d, ar, depth_pt, mval_fl, r_out); } /** |