Commit: 1f99e5efe759009325f886e54efda01bc451451e
Author: Julian Eisel
Date:   Wed Aug 26 17:41:05 2015 +0200
Branches: wiggly-widgets
https://developer.blender.org/rB1f99e5efe759009325f886e54efda01bc451451e

Fix 2-axes constrained widgets not rotating with manipulator correctly

Bah, that one was a hard nut...

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

M       source/blender/editors/transform/transform_manipulator.c
M       source/blender/windowmanager/WM_api.h
M       source/blender/windowmanager/intern/wm_generic_widgets.c

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

diff --git a/source/blender/editors/transform/transform_manipulator.c 
b/source/blender/editors/transform/transform_manipulator.c
index 1471f03..d0c3da8 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -384,7 +384,7 @@ static void manipulator_get_axis_constraint(const int 
axis_idx, int r_axis[3])
 
 static void manipulator_get_axis_special_offset(const int axis_idx, float 
r_ofs[3])
 {
-       float ofs_ax = (U.tw_flag & V3D_3D_WIDGETS) ? 0.8f : 0.8f * U.tw_size;
+       float ofs_ax = 11.0f;
 
        if (ELEM(axis_idx, MAN_AXIS_TRANS_XY, MAN_AXIS_SCALE_XY)) {
                r_ofs[0] = ofs_ax;
@@ -392,14 +392,14 @@ static void manipulator_get_axis_special_offset(const int 
axis_idx, float r_ofs[
                r_ofs[2] = 0.0f;
        }
        else if (ELEM(axis_idx, MAN_AXIS_TRANS_YZ, MAN_AXIS_SCALE_YZ)) {
-               r_ofs[0] = 0.0f;
+               r_ofs[0] = ofs_ax;
                r_ofs[1] = ofs_ax;
-               r_ofs[2] = ofs_ax;
+               r_ofs[2] = 0.0f;
        }
        else if (ELEM(axis_idx, MAN_AXIS_TRANS_ZX, MAN_AXIS_SCALE_ZX)) {
                r_ofs[0] = ofs_ax;
-               r_ofs[1] = 0.0f;
-               r_ofs[2] = ofs_ax;
+               r_ofs[1] = ofs_ax;
+               r_ofs[2] = 0.0f;
        }
 }
 
@@ -1186,7 +1186,8 @@ void WIDGETGROUP_manipulator_create(const struct bContext 
*C, struct wmWidgetGro
                                WM_widget_set_scale(axis, 0.07f);
                                WM_widget_set_origin(axis, rv3d->twmat[3]);
                                WIDGET_plane_set_offset(axis, ofs);
-                               WIDGET_plane_set_direction(axis, 
rv3d->twmat[aidx_norm - 1 > -1 ? aidx_norm - 1 : aidx_norm - 1]);
+                               WIDGET_plane_set_direction(axis, 
rv3d->twmat[aidx_norm - 1 < 0 ? 2 : aidx_norm - 1]);
+                               WIDGET_plane_set_up_vector(axis, 
rv3d->twmat[aidx_norm + 1 > 2 ? 0 : aidx_norm + 1]);
                                break;
                        }
                        case MAN_AXIS_TRANS_C:
diff --git a/source/blender/windowmanager/WM_api.h 
b/source/blender/windowmanager/WM_api.h
index 9352d64..2164d45 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -585,7 +585,8 @@ void WIDGET_dial_set_direction(struct wmWidget *widget, 
const float direction[3]
 
 struct wmWidget *WIDGET_plane_new(struct wmWidgetGroup *wgroup, const char 
*name, const int style);
 void WIDGET_plane_set_direction(struct wmWidget *widget, const float 
direction[3]);
-void WIDGET_plane_set_offset(struct wmWidget *widget, const float 
direction[3]);
+void WIDGET_plane_set_offset(struct wmWidget *widget, const float offset[3]);
+void WIDGET_plane_set_up_vector(struct wmWidget *widget, const float 
direction[3]);
 
 struct wmWidget *WIDGET_rect_transform_new(
         struct wmWidgetGroup *wgroup, const char *name, const int style,
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c 
b/source/blender/windowmanager/intern/wm_generic_widgets.c
index 2ef158b..c4860a4 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -729,15 +729,19 @@ void WIDGET_dial_set_direction(wmWidget *widget, const 
float direction[3])
 
 /********* Plane widget ************/
 
+#define PLANE_UP_VECTOR_SET 1
+
 typedef struct PlaneWidget {
        wmWidget widget;
 
        float direction[3];
        float offset[3];
+       float up[3];
+       int flag;
 } PlaneWidget;
 
 
-static void widget_plane_draw_geom(const float col_inner[4], const float 
col_outer[4])
+static void widget_plane_draw_geom(const float ofs[3], const float 
col_inner[4], const float col_outer[4])
 {
        static float vec[4][3] = {
                {-1, -1, 0},
@@ -746,6 +750,8 @@ static void widget_plane_draw_geom(const float 
col_inner[4], const float col_out
                {-1,  1, 0},
        };
 
+       glTranslatef(UNPACK3(ofs));
+
        glEnable(GL_MULTISAMPLE_ARB);
 
        glEnableClientState(GL_VERTEX_ARRAY);
@@ -759,31 +765,32 @@ static void widget_plane_draw_geom(const float 
col_inner[4], const float col_out
        glDisable(GL_MULTISAMPLE_ARB);
 }
 
-static void widget_plane_draw_intern(const bContext *C, PlaneWidget *plane, 
const bool UNUSED(select), const bool highlight)
+static void widget_plane_draw_intern(
+        const bContext *C, PlaneWidget *plane,
+        const bool UNUSED(select), const bool highlight)
 {
-       RegionView3D *rv3d = CTX_wm_region_view3d(C);
        const float up[3] = {0.0f, 0.0f, 1.0f};
        float col_inner[4], col_outer[4];
        float rot[3][3];
        float mat[4][4];
-       float ofs[3];
 
-       copy_v3_v3(ofs, plane->offset);
-       if ((U.tw_flag & V3D_3D_WIDGETS) == 0) {
-               mul_v3_fl(ofs, ED_view3d_pixel_size(rv3d, 
plane->widget.origin));
+       if (plane->flag & PLANE_UP_VECTOR_SET) {
+               copy_v3_v3(rot[2], plane->direction);
+               copy_v3_v3(rot[1], plane->up);
+               cross_v3_v3v3(rot[0], plane->up, plane->direction);
+       }
+       else {
+               rotation_between_vecs_to_mat3(rot, up, plane->direction);
        }
-
-       rotation_between_vecs_to_mat3(rot, up, plane->direction);
 
        copy_m4_m3(mat, rot);
        copy_v3_v3(mat[3], plane->widget.origin);
        mul_mat3_m4_fl(mat, plane->widget.scale);
 
        glPushMatrix();
-       glTranslatef(UNPACK3(ofs));
        glMultMatrixf(mat);
 
-       if (highlight && !(plane->widget.flag & WM_WIDGET_DRAW_HOVER)) {
+       if (highlight && (plane->widget.flag & WM_WIDGET_DRAW_HOVER) == 0) {
                copy_v4_v4(col_inner, plane->widget.col_hi);
                copy_v4_v4(col_outer, plane->widget.col_hi);
        }
@@ -794,7 +801,7 @@ static void widget_plane_draw_intern(const bContext *C, 
PlaneWidget *plane, cons
        col_inner[3] *= 0.5f;
 
        glEnable(GL_BLEND);
-       widget_plane_draw_geom(col_inner, col_outer);
+       widget_plane_draw_geom(plane->offset, col_inner, col_outer);
        glDisable(GL_BLEND);
 
        glPopMatrix();
@@ -838,11 +845,25 @@ void WIDGET_plane_set_direction(wmWidget *widget, const 
float direction[3])
        normalize_v3(plane->direction);
 }
 
-void WIDGET_plane_set_offset(wmWidget *widget, const float direction[3])
+void WIDGET_plane_set_offset(wmWidget *widget, const float offset[3])
 {
        PlaneWidget *plane = (PlaneWidget *)widget;
 
-       copy_v3_v3(plane->offset, direction);
+       copy_v3_v3(plane->offset, offset);
+}
+
+void WIDGET_plane_set_up_vector(wmWidget *widget, const float direction[3])
+{
+       PlaneWidget *plane = (PlaneWidget *)widget;
+
+       if (direction) {
+               copy_v3_v3(plane->up, direction);
+               normalize_v3(plane->up);
+               plane->flag |= PLANE_UP_VECTOR_SET;
+       }
+       else {
+               plane->flag &= ~PLANE_UP_VECTOR_SET;
+       }
 }
 
 /********* Cage widget ************/

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

Reply via email to