Manipulator: grab3d use own vars to store offset
authorCampbell Barton <ideasman42@gmail.com>
Tue, 15 Aug 2017 07:13:32 +0000 (17:13 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 15 Aug 2017 07:13:32 +0000 (17:13 +1000)
Was complicating general use case, also support for transforming with matrix_space set.
Add matrix_space support for manipulator_window_project_2d too.

source/blender/editors/manipulator_library/manipulator_library_utils.c
source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
source/blender/editors/mesh/editmesh_bisect.c
source/blender/editors/mesh/editmesh_extrude.c
source/blender/windowmanager/manipulators/wm_manipulator_fn.h

index 58999a82bba6e8171d73a4152d25d9e32521d157..d807ee0791752fdbf6806ebcb1cb8135a12c30d1 100644 (file)
@@ -173,11 +173,23 @@ bool manipulator_window_project_2d(
         float r_co[2])
 {
        float mat[4][4];
-       if (use_offset) {
-               mul_m4_series(mat, mpr->matrix_space, mpr->matrix_basis, mpr->matrix_offset);
-       }
-       else {
-               mul_m4_series(mat, mpr->matrix_space, mpr->matrix_basis);
+       {
+               float matrix_basis_buf[4][4];
+               const void *matrix_basis;
+               if (mpr->type->matrix_basis_get) {
+                       mpr->type->matrix_basis_get(mpr, matrix_basis_buf);
+                       matrix_basis = &matrix_basis_buf[0][0];
+               }
+               else {
+                       matrix_basis = &mpr->matrix_basis[0][0];
+               }
+
+               if (use_offset) {
+                       mul_m4_series(mat, mpr->matrix_space, matrix_basis, mpr->matrix_offset);
+               }
+               else {
+                       mul_m4_series(mat, mpr->matrix_space, matrix_basis);
+               }
        }
 
        /* rotate mouse in relation to the center and relocate it */
index 970850dca0637744787fb2c5161e63829f9cf9f1..61f5a7b27862dc0b31eb47b288daf82a11c948d4 100644 (file)
@@ -79,7 +79,7 @@ typedef struct ArrowManipulator3D {
 
 /* -------------------------------------------------------------------- */
 
-static void manipulator_arrow_matrix_basis_get(wmManipulator *mpr, float r_matrix[4][4])
+static void manipulator_arrow_matrix_basis_get(const wmManipulator *mpr, float r_matrix[4][4])
 {
        ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
 
index d3843bbb6cb9abac69a505688f8830c971cb2e61..38e350762c10bab9584159408eb3261fa832fab8 100644 (file)
 #include "../manipulator_geometry.h"
 #include "../manipulator_library_intern.h"
 
+typedef struct GrabManipulator3D {
+       wmManipulator manipulator;
+       /* Added to 'matrix_basis' when calculating the matrix. */
+       float prop_co[3];
+} GrabManipulator3D;
+
+static void manipulator_grab_matrix_basis_get(const wmManipulator *mpr, float r_matrix[4][4])
+{
+       GrabManipulator3D *grab = (GrabManipulator3D *)mpr;
+
+       copy_m4_m4(r_matrix, grab->manipulator.matrix_basis);
+       add_v3_v3(r_matrix[3], grab->prop_co);
+}
+
 static void manipulator_grab_modal(
         bContext *C, wmManipulator *mpr, const wmEvent *event,
         eWM_ManipulatorTweak tweak_flag);
@@ -74,11 +88,6 @@ typedef struct GrabInteraction {
        float init_prop_co[3];
 
        float init_matrix_final[4][4];
-
-       /* final output values, used for drawing */
-       struct {
-               float co_final[3];
-       } output;
 } GrabInteraction;
 
 #define DIAL_RESOLUTION 32
@@ -142,16 +151,23 @@ static void grab3d_get_translate(
        };
 
        RegionView3D *rv3d = ar->regiondata;
-       const float *co_ref = inter->init_prop_co;
+       float co_ref[3];
+       mul_v3_mat3_m4v3(co_ref, mpr->matrix_space, inter->init_prop_co);
        const float zfac = ED_view3d_calc_zfac(rv3d, co_ref, NULL);
 
        ED_view3d_win_to_delta(ar, mval_delta, co_delta, zfac);
+
+       float matrix_space_inv[3][3];
+       copy_m3_m4(matrix_space_inv, mpr->matrix_space);
+       invert_m3(matrix_space_inv);
+       mul_m3_v3(matrix_space_inv, co_delta);
 }
 
 static void grab3d_draw_intern(
         const bContext *C, wmManipulator *mpr,
         const bool select, const bool highlight)
 {
+       GrabInteraction *inter = mpr->interaction_data;
        const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
        const bool align_view = (draw_options & ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW) != 0;
        float color[4];
@@ -160,7 +176,14 @@ static void grab3d_draw_intern(
 
        manipulator_color_get(mpr, highlight, color);
 
-       WM_manipulator_calc_matrix_final(mpr, matrix_final);
+       {
+               float matrix_basis_adjust[4][4];
+               manipulator_grab_matrix_basis_get(mpr, matrix_basis_adjust);
+               WM_manipulator_calc_matrix_final_params(
+                       mpr, &((struct WM_ManipulatorMatrixParams) {
+                           .matrix_basis = matrix_basis_adjust,
+                       }), matrix_final);
+       }
 
        gpuPushMatrix();
        gpuMultMatrix(matrix_final);
@@ -181,8 +204,6 @@ static void grab3d_draw_intern(
        gpuPopMatrix();
 
        if (mpr->interaction_data) {
-               GrabInteraction *inter = mpr->interaction_data;
-
                gpuPushMatrix();
                gpuMultMatrix(inter->init_matrix_final);
 
@@ -219,10 +240,13 @@ static void manipulator_grab_modal(
         bContext *C, wmManipulator *mpr, const wmEvent *event,
         eWM_ManipulatorTweak UNUSED(tweak_flag))
 {
+       GrabManipulator3D *grab = (GrabManipulator3D *)mpr;
        GrabInteraction *inter = mpr->interaction_data;
+       ARegion *ar = CTX_wm_region(C);
 
+       float prop_delta[3];
        if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D) {
-               grab3d_get_translate(mpr, event, CTX_wm_region(C), mpr->matrix_basis[3]);
+               grab3d_get_translate(mpr, event, ar, prop_delta);
        }
        else {
                float mval_proj_init[2], mval_proj_curr[2];
@@ -233,17 +257,18 @@ static void manipulator_grab_modal(
                {
                        return;
                }
-               sub_v2_v2v2(mpr->matrix_basis[3], mval_proj_curr, mval_proj_init);
-               mpr->matrix_basis[3][2] = 0.0f;
+               sub_v2_v2v2(prop_delta, mval_proj_curr, mval_proj_init);
+               prop_delta[2] = 0.0f;
        }
-
-       add_v3_v3v3(inter->output.co_final, inter->init_prop_co, mpr->matrix_basis[3]);
+       add_v3_v3v3(grab->prop_co, inter->init_prop_co, prop_delta);
 
        /* set the property for the operator and call its modal function */
        wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
        if (WM_manipulator_target_property_is_valid(mpr_prop)) {
-               WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, inter->output.co_final);
+               WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, grab->prop_co);
        }
+
+       ED_region_tag_redraw(ar);
 }
 
 static void manipulator_grab_invoke(
@@ -254,12 +279,23 @@ static void manipulator_grab_invoke(
        inter->init_mval[0] = event->mval[0];
        inter->init_mval[1] = event->mval[1];
 
-       WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
-
+#if 0
+       copy_v3_v3(inter->init_prop_co, grab->prop_co);
+#else
        wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
        if (WM_manipulator_target_property_is_valid(mpr_prop)) {
                WM_manipulator_target_property_value_get_array(mpr, mpr_prop, inter->init_prop_co);
        }
+#endif
+
+       {
+               float matrix_basis_adjust[4][4];
+               manipulator_grab_matrix_basis_get(mpr, matrix_basis_adjust);
+               WM_manipulator_calc_matrix_final_params(
+                       mpr, &((struct WM_ManipulatorMatrixParams) {
+                           .matrix_basis = matrix_basis_adjust,
+                       }), inter->init_matrix_final);
+       }
 
        mpr->interaction_data = inter;
 }
@@ -285,7 +321,8 @@ static int manipulator_grab_test_select(
 
 static void manipulator_grab_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
 {
-       WM_manipulator_target_property_value_get_array(mpr, mpr_prop, mpr->matrix_basis[3]);
+       GrabManipulator3D *grab = (GrabManipulator3D *)mpr;
+       WM_manipulator_target_property_value_get_array(mpr, mpr_prop, grab->prop_co);
 }
 
 static int manipulator_grab_cursor_get(wmManipulator *UNUSED(mpr))
@@ -307,12 +344,13 @@ static void MANIPULATOR_WT_grab_3d(wmManipulatorType *wt)
        wt->draw = manipulator_grab_draw;
        wt->draw_select = manipulator_grab_draw_select;
        wt->test_select = manipulator_grab_test_select;
+       wt->matrix_basis_get = manipulator_grab_matrix_basis_get;
        wt->invoke = manipulator_grab_invoke;
        wt->property_update = manipulator_grab_property_update;
        wt->modal = manipulator_grab_modal;
        wt->cursor_get = manipulator_grab_cursor_get;
 
-       wt->struct_size = sizeof(wmManipulator);
+       wt->struct_size = sizeof(GrabManipulator3D);
 
        /* rna */
        static EnumPropertyItem rna_enum_draw_style[] = {
index 5f50ce1f37bf149ec74453644d4b4edfb3dda72e..228677a51c81d13c4d4ff8ffa610be5e19ce519e 100644 (file)
@@ -428,8 +428,8 @@ static void manipulator_mesh_bisect_update_from_op(ManipulatorGroup *man)
        RNA_property_float_get_array(op->ptr, man->data.prop_plane_no, plane_no);
 
        WM_manipulator_set_matrix_location(man->translate_z, plane_co);
-       WM_manipulator_set_matrix_location(man->translate_c, plane_co);
        WM_manipulator_set_matrix_location(man->rotate_c, plane_co);
+       /* translate_c location comes from the property. */
 
        WM_manipulator_set_matrix_rotation_from_z_axis(man->translate_z, plane_no);
 
index aa1d18b18c94230ad28e32e028c876b9bb5c7c80..e7fcad9e633410771bf6837d5817660b7537e0d0 100644 (file)
@@ -861,9 +861,9 @@ static void manipulator_mesh_spin_update_from_op(ManipulatorSpinGroup *man)
        RNA_property_float_get_array(op->ptr, man->data.prop_axis_no, plane_no);
 
        WM_manipulator_set_matrix_location(man->translate_z, plane_co);
-       WM_manipulator_set_matrix_location(man->translate_c, plane_co);
        WM_manipulator_set_matrix_location(man->rotate_c, plane_co);
        WM_manipulator_set_matrix_location(man->angle_z, plane_co);
+       /* translate_c location comes from the property. */
 
        WM_manipulator_set_matrix_rotation_from_z_axis(man->translate_z, plane_no);
        WM_manipulator_set_matrix_rotation_from_z_axis(man->angle_z, plane_no);
index a9dd9b1f114b66576b31e929b20ae1681a8a42c2..a92648455d41fee7b035ffe54399e8d62aa2bbc2 100644 (file)
@@ -52,7 +52,7 @@ typedef void    (*wmManipulatorFnDrawSelect)(const struct bContext *, struct wmM
 typedef int     (*wmManipulatorFnTestSelect)(struct bContext *, struct wmManipulator *, const struct wmEvent *);
 typedef void    (*wmManipulatorFnModal)(struct bContext *, struct wmManipulator *, const struct wmEvent *, eWM_ManipulatorTweak);
 typedef void    (*wmManipulatorFnPropertyUpdate)(struct wmManipulator *, struct wmManipulatorProperty *);
-typedef void    (*wmManipulatorFnMatrixWorldGet)(struct wmManipulator *, float[4][4]);
+typedef void    (*wmManipulatorFnMatrixWorldGet)(const struct wmManipulator *, float[4][4]);
 typedef void    (*wmManipulatorFnInvoke)(struct bContext *, struct wmManipulator *, const struct wmEvent *);
 typedef void    (*wmManipulatorFnExit)(struct bContext *, struct wmManipulator *, const bool);
 typedef int     (*wmManipulatorFnCursorGet)(struct wmManipulator *);