Commit: 6528310543e347ed0c178872fb89692468a2c9b2
Author: Campbell Barton
Date:   Fri Jun 22 13:56:14 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB6528310543e347ed0c178872fb89692468a2c9b2

Cleanup: move cursor rotation into own function

===================================================================

M       source/blender/editors/include/ED_view3d.h
M       source/blender/editors/space_view3d/view3d_edit.c

===================================================================

diff --git a/source/blender/editors/include/ED_view3d.h 
b/source/blender/editors/include/ED_view3d.h
index bc131b45d37..30176351b6a 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -102,6 +102,7 @@ struct View3DCursor *ED_view3d_cursor3d_get(struct Scene 
*scene, struct View3D *
 void ED_view3d_cursor3d_calc_mat3(const struct Scene *scene, const struct 
View3D *v3d, float mat[3][3]);
 void ED_view3d_cursor3d_calc_mat4(const struct Scene *scene, const struct 
View3D *v3d, float mat[4][4]);
 void ED_view3d_cursor3d_position(struct bContext *C, const int mval[2], float 
cursor_co[3]);
+void ED_view3d_cursor3d_position_rotation(struct bContext *C, const int 
mval[2], float cursor_co[3], float cursor_quat[4]);
 void ED_view3d_cursor3d_update(struct bContext *C, const int mval[2]);
 
 struct Camera *ED_view3d_camera_data_get(struct View3D *v3d, struct 
RegionView3D *rv3d);
diff --git a/source/blender/editors/space_view3d/view3d_edit.c 
b/source/blender/editors/space_view3d/view3d_edit.c
index 977421e7fad..15e2d25e794 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -4591,7 +4591,7 @@ void ED_view3d_cursor3d_position(bContext *C, const int 
mval[2], float cursor_co
        }
 }
 
-void ED_view3d_cursor3d_update(bContext *C, const int mval[2])
+void ED_view3d_cursor3d_position_rotation(bContext *C, const int mval[2], 
float cursor_co[3], float cursor_quat[4])
 {
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
@@ -4599,16 +4599,19 @@ void ED_view3d_cursor3d_update(bContext *C, const int 
mval[2])
        ARegion *ar = CTX_wm_region(C);
        RegionView3D *rv3d = ar->regiondata;
 
-       View3DCursor *cursor_curr = ED_view3d_cursor3d_get(scene, v3d);
-       View3DCursor  cursor_prev = *cursor_curr;
+       /* XXX, caller should check. */
+       if (rv3d == NULL)
+               return;
+
+       ED_view3d_cursor3d_position(C, mval, cursor_co);
 
-       ED_view3d_cursor3d_position(C, mval, cursor_curr->location);
-       copy_qt_qt(cursor_curr->rotation, rv3d->viewquat);
-       cursor_curr->rotation[0] *= -1.0f;
+       copy_qt_qt(cursor_quat, rv3d->viewquat);
+       cursor_quat[0] *= -1.0f;
 
        {
                const float mval_fl[2] = {UNPACK2(mval)};
                float ray_no[3];
+               float ray_co[3];
 
                struct SnapObjectContext *snap_context = 
ED_transform_snap_object_context_create_view3d(
                        bmain, scene, CTX_data_depsgraph(C), 0, ar, v3d);
@@ -4624,16 +4627,21 @@ void ED_view3d_cursor3d_update(bContext *C, const int 
mval[2])
                            .use_object_edit_cage = false,
                        },
                        mval_fl, &dist_px,
-                       cursor_curr->location, ray_no, NULL,
+                       ray_co, ray_no, NULL,
                        &ob_dummy, obmat))
                {
+                       if (U.uiflag & USER_DEPTH_CURSOR) {
+                               copy_v3_v3(cursor_co, ray_co);
+                       }
+
                        float tquat[4];
+
                        /* Math normal (Z). */
                        {
                                float z_src[3] = {0, 0, 1};
-                               mul_qt_v3(cursor_curr->rotation, z_src);
+                               mul_qt_v3(cursor_quat, z_src);
                                rotation_between_vecs_to_quat(tquat, z_src, 
ray_no);
-                               mul_qt_qtqt(cursor_curr->rotation, tquat, 
cursor_curr->rotation);
+                               mul_qt_qtqt(cursor_quat, tquat, cursor_quat);
                        }
 
                        /* Match object matrix (X). */
@@ -4646,15 +4654,28 @@ void ED_view3d_cursor3d_update(bContext *C, const int 
mval[2])
                                const int ortho_axis = 
axis_dominant_v3_ortho_single(ortho_axis_dot);
                                float x_src[3] = {1, 0, 0};
                                float x_dst[3];
-                               mul_qt_v3(cursor_curr->rotation, x_src);
+                               mul_qt_v3(cursor_quat, x_src);
                                project_plane_v3_v3v3(x_dst, obmat[ortho_axis], 
ray_no);
                                normalize_v3(x_dst);
                                rotation_between_vecs_to_quat(tquat, x_src, 
x_dst);
-                               mul_qt_qtqt(cursor_curr->rotation, tquat, 
cursor_curr->rotation);
+                               mul_qt_qtqt(cursor_quat, tquat, cursor_quat);
                        }
                }
                ED_transform_snap_object_context_destroy(snap_context);
        }
+}
+
+void ED_view3d_cursor3d_update(bContext *C, const int mval[2])
+{
+       Scene *scene = CTX_data_scene(C);
+       View3D *v3d = CTX_wm_view3d(C);
+       ARegion *ar = CTX_wm_region(C);
+       RegionView3D *rv3d = ar->regiondata;
+
+       View3DCursor *cursor_curr = ED_view3d_cursor3d_get(scene, v3d);
+       View3DCursor  cursor_prev = *cursor_curr;
+
+       ED_view3d_cursor3d_position_rotation(C, mval, cursor_curr->location, 
cursor_curr->rotation);
 
        /* offset the cursor lock to avoid jumping to new offset */
        if (v3d->ob_centre_cursor) {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to