Fix T49872: 3D cursor places with camera shift in ortographic mode
authorJulian Eisel <eiseljulian@gmail.com>
Thu, 8 Dec 2016 11:41:27 +0000 (12:41 +0100)
committerJulian Eisel <eiseljulian@gmail.com>
Thu, 8 Dec 2016 11:41:27 +0000 (12:41 +0100)
14 files changed:
source/blender/editors/armature/armature_add.c
source/blender/editors/curve/editcurve.c
source/blender/editors/curve/editcurve_paint.c
source/blender/editors/gpencil/gpencil_convert.c
source/blender/editors/include/ED_view3d.h
source/blender/editors/interface/interface_eyedropper.c
source/blender/editors/mesh/editmesh_bisect.c
source/blender/editors/mesh/editmesh_extrude.c
source/blender/editors/mesh/editmesh_knife.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_project.c
source/blender/editors/space_view3d/view3d_ruler.c
source/blender/editors/transform/transform.c

index 559d93c7eb1510a99bf41c8bac109f6fb6bb6f3a..6228874343b394cb171d5cc9cf996178549d7d3a 100644 (file)
@@ -231,7 +231,7 @@ static int armature_click_extrude_invoke(bContext *C, wmOperator *op, const wmEv
        copy_v3_v3(oldcurs, fp);
 
        VECCOPY2D(mval_f, event->mval);
-       ED_view3d_win_to_3d(ar, fp, mval_f, tvec);
+       ED_view3d_win_to_3d(v3d, ar, fp, mval_f, tvec);
        copy_v3_v3(fp, tvec);
 
        /* extrude to the where new cursor is and store the operation result */
index e40dde24ce2812d98244e8cadb30eedbad3d29e4..e9fd5fb5a438a29ddf8425bb0e485ad75f2c5851 100644 (file)
@@ -4993,7 +4993,7 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                        copy_v3_v3(location, ED_view3d_cursor3d_get(vc.scene, vc.v3d));
                }
 
-               ED_view3d_win_to_3d_int(vc.ar, location, event->mval, location);
+               ED_view3d_win_to_3d_int(vc.v3d, vc.ar, location, event->mval, location);
 
                if (use_proj) {
                        const float mval[2] = {UNPACK2(event->mval)};
index 2d8fc76ee7eca9ea2b940d8e8c8939afdfc81b44..34e026a3ef4e1e58d4a4362f760a10a6e710a84a 100644 (file)
@@ -353,7 +353,7 @@ static bool stroke_elem_project_fallback(
                surface_offset, radius,
                r_location_world, r_normal_world);
        if (is_depth_found == false) {
-               ED_view3d_win_to_3d(cdd->vc.ar, location_fallback_depth, mval_fl, r_location_world);
+               ED_view3d_win_to_3d(cdd->vc.v3d, cdd->vc.ar, location_fallback_depth, mval_fl, r_location_world);
                zero_v3(r_normal_local);
        }
        mul_v3_m4v3(r_location_local, cdd->vc.obedit->imat, r_location_world);
@@ -1135,7 +1135,7 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                const float mval_fl[2] = {UNPACK2(event->mval)};
                float center[3];
                negate_v3_v3(center, cdd->vc.rv3d->ofs);
-               ED_view3d_win_to_3d(cdd->vc.ar, center, mval_fl, cdd->prev.location_world);
+               ED_view3d_win_to_3d(cdd->vc.v3d, cdd->vc.ar, center, mval_fl, cdd->prev.location_world);
                copy_v3_v3(cdd->prev.location_world_valid, cdd->prev.location_world);
        }
 
index c502ed1aa839799e0a659f03b7b633b960f3508c..d0f68c4b8f332b62ea2ffd053abd0bb48d3c052e 100644 (file)
@@ -191,7 +191,7 @@ static void gp_strokepoint_convertcoords(
                        }
                }
                
-               ED_view3d_win_to_3d(ar, fp, mvalf, p3d);
+               ED_view3d_win_to_3d(v3d, ar, fp, mvalf, p3d);
        }
 }
 
index 48c1e2d1996f2ab31c5033aea0b7ebcb9e312faa..79176d9e9cf72da419d01769256920607e8ead2f 100644 (file)
@@ -216,8 +216,14 @@ bool ED_view3d_win_to_ray_ex(
         const struct ARegion *ar, const struct View3D *v3d, const float mval[2],
         float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip);
 void ED_view3d_global_to_vector(const struct RegionView3D *rv3d, const float coord[3], float vec[3]);
-void ED_view3d_win_to_3d(const struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]);
-void ED_view3d_win_to_3d_int(const struct ARegion *ar, const float depth_pt[3], const int mval[2], float out[3]);
+void ED_view3d_win_to_3d(
+        const struct View3D *v3d, const struct ARegion *ar,
+        const float depth_pt[3], const float mval[2],
+        float r_out[3]);
+void ED_view3d_win_to_3d_int(
+        const struct View3D *v3d, const struct ARegion *ar,
+        const float depth_pt[3], const int mval[2],
+        float r_out[3]);
 void ED_view3d_win_to_delta(const struct ARegion *ar, const float mval[2], float out[3], const float zfac);
 void ED_view3d_win_to_origin(const struct ARegion *ar, const float mval[2], float out[3]);
 void ED_view3d_win_to_vector(const struct ARegion *ar, const float mval[2], float out[3]);
index 5f7a018e4c2e01f477bff09c6068588b80e024de..5154a77ad217e43e5052769158805e229722d1ba 100644 (file)
@@ -882,7 +882,6 @@ static void depthdropper_exit(bContext *C, wmOperator *op)
  */
 static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx, int my, float *r_depth)
 {
-
        /* we could use some clever */
        wmWindow *win = CTX_wm_window(C);
        ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my);
@@ -923,7 +922,7 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx,
                                        float co_align[3];
 
                                        /* quick way to get view-center aligned point */
-                                       ED_view3d_win_to_3d(ar, co, mval_center_fl, co_align);
+                                       ED_view3d_win_to_3d(v3d, ar, co, mval_center_fl, co_align);
 
                                        *r_depth = len_v3v3(view_co, co_align);
 
index 0e1ba2b1c254e59bd3d4ba5bcb2c81a618405c80..3a9e278f0395538d93f0eb7526247403d32555a3 100644 (file)
@@ -73,6 +73,7 @@ static bool mesh_bisect_interactive_calc(
        wmGesture *gesture = op->customdata;
        BisectData *opdata;
 
+       View3D *v3d = CTX_wm_view3d(C);
        ARegion *ar = CTX_wm_region(C);
        RegionView3D *rv3d = ar->regiondata;
 
@@ -101,7 +102,7 @@ static bool mesh_bisect_interactive_calc(
        normalize_v3(plane_no);  /* not needed but nicer for user */
 
        /* point on plane, can use either start or endpoint */
-       ED_view3d_win_to_3d(ar, co_ref, co_a_ss, plane_co);
+       ED_view3d_win_to_3d(v3d, ar, co_ref, co_a_ss, plane_co);
 
        if (opdata->is_first == false)
                EDBM_redo_state_restore(opdata->mesh_backup, em, false);
index d4c49833c2c548a469e23a2eb227caaad7dc5386..0f1badd93cd0ad30b9cb5d99ec86100235d3b8cc 100644 (file)
@@ -584,7 +584,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
                copy_v3_v3(min, cent);
 
                mul_m4_v3(vc.obedit->obmat, min);  /* view space */
-               ED_view3d_win_to_3d_int(vc.ar, min, event->mval, min);
+               ED_view3d_win_to_3d_int(vc.v3d, vc.ar, min, event->mval, min);
                mul_m4_v3(vc.obedit->imat, min); // back in object space
 
                sub_v3_v3(min, cent);
@@ -633,7 +633,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
                BMOIter oiter;
                
                copy_v3_v3(min, curs);
-               ED_view3d_win_to_3d_int(vc.ar, min, event->mval, min);
+               ED_view3d_win_to_3d_int(vc.v3d, vc.ar, min, event->mval, min);
 
                invert_m4_m4(vc.obedit->imat, vc.obedit->obmat);
                mul_m4_v3(vc.obedit->imat, min); // back in object space
index 44453d03ade70a1a2dc5399d8a8c04b020a4f2da..bf59693b85655fbaf4d08efd1418d9378f8645bf 100644 (file)
@@ -971,7 +971,7 @@ static void knifetool_draw_angle_snapping(const KnifeTool_OpData *kcd)
 
                        copy_v3_v3(co_depth, kcd->prev.cage);
                        mul_m4_v3(kcd->ob->obmat, co_depth);
-                       ED_view3d_win_to_3d(kcd->ar, co_depth, kcd->curr.mval, curr_cage_adjust);
+                       ED_view3d_win_to_3d(kcd->vc.v3d, kcd->ar, co_depth, kcd->curr.mval, curr_cage_adjust);
                        mul_m4_v3(kcd->ob->imat, curr_cage_adjust);
 
                        sub_v3_v3v3(ray_dir, curr_cage_adjust, kcd->prev.cage);
index ef2f2d36ab7a38c5a09eb82e8f0caa37dbff4a31..47f0220726bd345427f3c8083affff9c3ccb2c4b 100644 (file)
@@ -4187,7 +4187,7 @@ static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Bru
 
                /* compute 3d coordinate at same z from original location + mouse */
                mul_v3_m4v3(loc, ob->obmat, cache->orig_grab_location);
-               ED_view3d_win_to_3d(cache->vc->ar, loc, mouse, grab_location);
+               ED_view3d_win_to_3d(cache->vc->v3d, cache->vc->ar, loc, mouse, grab_location);
 
                /* compute delta to move verts by */
                if (!cache->first_time) {
index 9e41ad6a8f61bad4f2817e7f1c7975ac10d2ac70..080f205b530ab23bb352ab70f8b3dffb2fc49bfd 100644 (file)
@@ -789,7 +789,7 @@ static void viewops_data_create_ex(bContext *C, wmOperator *op, const wmEvent *e
                                    (float)vod->ar->winx / 2.0f,
                                    (float)vod->ar->winy / 2.0f};
 
-                               ED_view3d_win_to_3d(vod->ar, vod->dyn_ofs, mval_ar_mid, rv3d->ofs);
+                               ED_view3d_win_to_3d(vod->v3d, vod->ar, vod->dyn_ofs, mval_ar_mid, rv3d->ofs);
                                negate_v3(rv3d->ofs);
                        }
                        negate_v3(vod->dyn_ofs);
@@ -3289,7 +3289,7 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev
                else {
                        /* fallback to simple pan */
                        negate_v3_v3(new_ofs, rv3d->ofs);
-                       ED_view3d_win_to_3d_int(ar, new_ofs, event->mval, new_ofs);
+                       ED_view3d_win_to_3d_int(v3d, ar, new_ofs, event->mval, new_ofs);
                }
                negate_v3(new_ofs);
                ED_view3d_smooth_view(
@@ -4708,7 +4708,7 @@ void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2])
        if (depth_used == false) {
                float depth_pt[3];
                copy_v3_v3(depth_pt, fp);
-               ED_view3d_win_to_3d_int(ar, depth_pt, mval, fp);
+               ED_view3d_win_to_3d_int(v3d, ar, depth_pt, mval, fp);
        }
 }
 
@@ -4957,7 +4957,7 @@ bool ED_view3d_autodist(
        }
 
        if (fallback_depth_pt) {
-               ED_view3d_win_to_3d_int(ar, fallback_depth_pt, mval, mouse_worldloc);
+               ED_view3d_win_to_3d_int(v3d, ar, fallback_depth_pt, mval, mouse_worldloc);
                return true;
        }
        else {
index 7448d4c658e507f983cdd4b49a0104bad5629f41..65a6dee2f6cb4d9ad257fd9acce076c41a604f4f 100644 (file)
@@ -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);
 }
 
 /**
index 3c13ab9d5950304724863b5a9105c35c88472fba..688f459108b546e25166c991f0912bc547ca77c4 100644 (file)
@@ -700,7 +700,7 @@ static void view3d_ruler_free(RulerInfo *ruler_info)
 static void view3d_ruler_item_project(RulerInfo *ruler_info, float r_co[3],
                                       const int xy[2])
 {
-       ED_view3d_win_to_3d_int(ruler_info->ar, r_co, xy, r_co);
+       ED_view3d_win_to_3d_int(ruler_info->sa->spacedata.first, ruler_info->ar, r_co, xy, r_co);
 }
 
 /* use for mousemove events */
index d4cd2351f46491a76d08c4d0bf0e75b81ea72176..20c62e91d01cc1fdec345778ae49625cf2457171 100644 (file)
@@ -2880,7 +2880,7 @@ static void initBend(TransInfo *t)
 
        curs = ED_view3d_cursor3d_get(t->scene, t->view);
        copy_v3_v3(data->warp_sta, curs);
-       ED_view3d_win_to_3d(t->ar, curs, mval_fl, data->warp_end);
+       ED_view3d_win_to_3d(t->sa->spacedata.first, t->ar, curs, mval_fl, data->warp_end);
 
        copy_v3_v3(data->warp_nor, t->viewinv[2]);
        if (t->flag & T_EDIT) {