[Bf-blender-cvs] [042e8e4] wiggly-widgets: Fix manipulator not scaling correctly in 3D widgets drawing mode

Julian Eisel noreply at git.blender.org
Mon Aug 24 22:23:18 CEST 2015


Commit: 042e8e4b77bfc3216cde444716b05376b4b289b9
Author: Julian Eisel
Date:   Mon Aug 24 22:22:03 2015 +0200
Branches: wiggly-widgets
https://developer.blender.org/rB042e8e4b77bfc3216cde444716b05376b4b289b9

Fix manipulator not scaling correctly in 3D widgets drawing mode

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

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 1d9de6f..1471f03 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -382,6 +382,27 @@ 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;
+
+	if (ELEM(axis_idx, MAN_AXIS_TRANS_XY, MAN_AXIS_SCALE_XY)) {
+		r_ofs[0] = ofs_ax;
+		r_ofs[1] = ofs_ax;
+		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[1] = ofs_ax;
+		r_ofs[2] = ofs_ax;
+	}
+	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;
+	}
+}
+
 
 /* **************** Preparation Stuff **************** */
 
@@ -1123,6 +1144,7 @@ void WIDGETGROUP_manipulator_create(const struct bContext *C, struct wmWidgetGro
 
 		manipulator_get_axis_color(rv3d, axis_idx, col, col_hi);
 		manipulator_get_axis_constraint(axis_idx, constraint_axis);
+
 		WM_widget_set_origin(axis, rv3d->twmat[3]);
 		WM_widget_set_colors(axis, col, col_hi);
 		/* custom handler! */
@@ -1154,31 +1176,16 @@ void WIDGETGROUP_manipulator_create(const struct bContext *C, struct wmWidgetGro
 			case MAN_AXIS_SCALE_YZ:
 			case MAN_AXIS_SCALE_ZX:
 			{
-				const float ofs_fac = U.tw_size * 0.7f;
-				float origin[4];
-				float px;
+				float ofs[3];
 
 				/* XXX hrmpf, widgets call this twice on every redraw, could use update flag */
-				ED_view3d_update_viewmat(CTX_data_scene(C), CTX_wm_view3d(C), CTX_wm_region(C), NULL, NULL);
-
-				copy_v4_v4(origin, rv3d->twmat[3]);
-				px = ED_view3d_pixel_size(rv3d, origin);
+				ED_view3d_update_viewmat(CTX_data_scene(C), v3d, CTX_wm_region(C), NULL, NULL);
 
-				if (ELEM(axis_idx, MAN_AXIS_TRANS_XY, MAN_AXIS_SCALE_XY)) {
-					origin[0] += px * ofs_fac;
-					origin[1] += px * ofs_fac;
-				}
-				else if (ELEM(axis_idx, MAN_AXIS_TRANS_YZ, MAN_AXIS_SCALE_YZ)) {
-					origin[1] += px * ofs_fac;
-					origin[2] += px * ofs_fac;
-				}
-				else if (ELEM(axis_idx, MAN_AXIS_TRANS_ZX, MAN_AXIS_SCALE_ZX)) {
-					origin[2] += px * ofs_fac;
-					origin[0] += px * ofs_fac;
-				}
+				manipulator_get_axis_special_offset(axis_idx, ofs);
 
 				WM_widget_set_scale(axis, 0.07f);
-				WM_widget_set_origin(axis, origin);
+				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]);
 				break;
 			}
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index cee2740..9352d64 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -585,6 +585,7 @@ 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]);
 
 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 c4bbbdb..2ef158b 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -526,7 +526,7 @@ wmWidget *WIDGET_arrow_new(wmWidgetGroup *wgroup, const char *name, const int st
 
 
 	arrow->widget.draw = widget_arrow_draw;
-	arrow->widget.get_final_position = 	widget_arrow_get_final_pos;
+	arrow->widget.get_final_position = widget_arrow_get_final_pos;
 	arrow->widget.intersect = NULL;
 	arrow->widget.handler = widget_arrow_handler;
 	arrow->widget.invoke = widget_arrow_invoke;
@@ -733,6 +733,7 @@ typedef struct PlaneWidget {
 	wmWidget widget;
 
 	float direction[3];
+	float offset[3];
 } PlaneWidget;
 
 
@@ -758,12 +759,19 @@ 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(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));
+	}
 
 	rotation_between_vecs_to_mat3(rot, up, plane->direction);
 
@@ -772,6 +780,7 @@ static void widget_plane_draw_intern(PlaneWidget *plane, const bool UNUSED(selec
 	mul_mat3_m4_fl(mat, plane->widget.scale);
 
 	glPushMatrix();
+	glTranslatef(UNPACK3(ofs));
 	glMultMatrixf(mat);
 
 	if (highlight && !(plane->widget.flag & WM_WIDGET_DRAW_HOVER)) {
@@ -791,15 +800,15 @@ static void widget_plane_draw_intern(PlaneWidget *plane, const bool UNUSED(selec
 	glPopMatrix();
 }
 
-static void widget_plane_render_3d_intersect(const bContext *UNUSED(C), wmWidget *widget, int selectionbase)
+static void widget_plane_render_3d_intersect(const bContext *C, wmWidget *widget, int selectionbase)
 {
 	GPU_select_load_id(selectionbase);
-	widget_plane_draw_intern((PlaneWidget *)widget, true, false);
+	widget_plane_draw_intern(C, (PlaneWidget *)widget, true, false);
 }
 
-static void widget_plane_draw(const bContext *UNUSED(C), wmWidget *widget)
+static void widget_plane_draw(const bContext *C, wmWidget *widget)
 {
-	widget_plane_draw_intern((PlaneWidget *)widget, false, (widget->flag & WM_WIDGET_HIGHLIGHT));
+	widget_plane_draw_intern(C, (PlaneWidget *)widget, false, (widget->flag & WM_WIDGET_HIGHLIGHT));
 }
 
 wmWidget *WIDGET_plane_new(wmWidgetGroup *wgroup, const char *name, const int UNUSED(style))
@@ -811,7 +820,10 @@ wmWidget *WIDGET_plane_new(wmWidgetGroup *wgroup, const char *name, const int UN
 	plane->widget.intersect = NULL;
 	plane->widget.render_3d_intersection = widget_plane_render_3d_intersect;
 	plane->widget.flag |= WM_WIDGET_SCALE_3D;
+
+	/* defaults */
 	copy_v3_v3(plane->direction, dir_default);
+	zero_v3(plane->offset);
 
 	wm_widget_register(wgroup, &plane->widget, name);
 
@@ -826,6 +838,13 @@ 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])
+{
+	PlaneWidget *plane = (PlaneWidget *)widget;
+
+	copy_v3_v3(plane->offset, direction);
+}
+
 /********* Cage widget ************/
 
 enum {




More information about the Bf-blender-cvs mailing list