[Bf-blender-cvs] [f860369ebf5] blender2.8: Manipulator: use matrix for manipulator direction

Campbell Barton noreply at git.blender.org
Sun Jun 18 00:34:34 CEST 2017


Commit: f860369ebf58f1ce683a587be136e2bf7dd08372
Author: Campbell Barton
Date:   Sun Jun 18 07:43:45 2017 +1000
Branches: blender2.8
https://developer.blender.org/rBf860369ebf58f1ce683a587be136e2bf7dd08372

Manipulator: use matrix for manipulator direction

Remove type-specific axis functions.

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

M	source/blender/editors/include/ED_manipulator_library.h
M	source/blender/editors/manipulator_library/arrow3d_manipulator.c
M	source/blender/editors/manipulator_library/dial3d_manipulator.c
M	source/blender/editors/manipulator_library/grab3d_manipulator.c
M	source/blender/editors/manipulator_library/primitive3d_manipulator.c
M	source/blender/editors/mesh/editmesh_bisect.c
M	source/blender/editors/mesh/editmesh_extrude.c
M	source/blender/editors/space_node/node_manipulators.c
M	source/blender/editors/space_view3d/view3d_manipulators.c
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/editors/transform/transform_manipulator2d.c
M	source/blender/windowmanager/manipulators/WM_manipulator_api.h
M	source/blender/windowmanager/manipulators/intern/wm_manipulator.c

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

diff --git a/source/blender/editors/include/ED_manipulator_library.h b/source/blender/editors/include/ED_manipulator_library.h
index 8d74ed941d0..421fdbf1212 100644
--- a/source/blender/editors/include/ED_manipulator_library.h
+++ b/source/blender/editors/include/ED_manipulator_library.h
@@ -77,8 +77,6 @@ enum {
 };
 
 void ED_manipulator_arrow3d_set_style(struct wmManipulator *mpr, int style);
-void ED_manipulator_arrow3d_set_direction(struct wmManipulator *mpr, const float direction[3]);
-void ED_manipulator_arrow3d_set_up_vector(struct wmManipulator *mpr, const float direction[3]);
 void ED_manipulator_arrow3d_set_line_len(struct wmManipulator *mpr, const float len);
 void ED_manipulator_arrow3d_set_ui_range(struct wmManipulator *mpr, const float min, const float max);
 void ED_manipulator_arrow3d_set_range_fac(struct wmManipulator *mpr, const float range_fac);
@@ -117,11 +115,9 @@ enum {
 };
 
 void ED_manipulator_dial3d_set_style(struct wmManipulator *mpr, int style);
-void ED_manipulator_dial3d_set_up_vector(
-        struct wmManipulator *mpr, const float direction[3]);
-void ED_manipulator_dial3d_set_start_vector(
-        struct wmManipulator *mpr, const bool enabled, const float direction[3]);
-void ED_manipulator_dial3d_set_double_helper(
+void ED_manipulator_dial3d_set_use_start_y_axis(
+        struct wmManipulator *mpr, const bool enabled);
+void ED_manipulator_dial3d_set_use_double_helper(
         struct wmManipulator *mpr, const bool enabled);
 
 /* -------------------------------------------------------------------- */
@@ -132,8 +128,6 @@ enum {
 };
 
 void ED_manipulator_grab3d_set_style(struct wmManipulator *mpr, int style);
-void ED_manipulator_grab3d_set_up_vector(
-        struct wmManipulator *mpr, const float direction[3]);
 
 
 /* -------------------------------------------------------------------- */
@@ -144,8 +138,6 @@ enum {
 };
 
 void ED_manipulator_primitive3d_set_style(struct wmManipulator *mpr, int style);
-void ED_manipulator_primitive3d_set_direction(struct wmManipulator *mpr, const float direction[3]);
-void ED_manipulator_primitive3d_set_up_vector(struct wmManipulator *mpr, const float direction[3]);
 
 
 #endif  /* __ED_MANIPULATOR_LIBRARY_H__ */
diff --git a/source/blender/editors/manipulator_library/arrow3d_manipulator.c b/source/blender/editors/manipulator_library/arrow3d_manipulator.c
index 1d3cb281af1..7c688ea077f 100644
--- a/source/blender/editors/manipulator_library/arrow3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/arrow3d_manipulator.c
@@ -32,6 +32,10 @@
  *
  * \brief Simple arrow manipulator which is dragged into a certain direction.
  * The arrow head can have varying shapes, e.g. cone, box, etc.
+ *
+ * - `matrix[0]` is derived from Y and Z.
+ * - `matrix[1]` is 'up' for manipulator types that have an up.
+ * - `matrix[2]` is the arrow direction (for all arrowes).
  */
 
 #include "BIF_gl.h"
@@ -81,8 +85,6 @@ typedef struct ArrowManipulator3D {
 	int flag;
 
 	float len;          /* arrow line length */
-	float direction[3];
-	float up[3];
 	float aspect[2];    /* cone style only */
 } ArrowManipulator3D;
 
@@ -94,7 +96,7 @@ static void manipulator_arrow_matrix_world_get(wmManipulator *mpr, float r_matri
 	ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
 
 	copy_m4_m4(r_matrix, arrow->manipulator.matrix);
-	madd_v3_v3fl(r_matrix[3], arrow->direction, arrow->data.offset);
+	madd_v3_v3fl(r_matrix[3], arrow->manipulator.matrix[2], arrow->data.offset);
 }
 
 static void arrow_draw_geom(const ArrowManipulator3D *arrow, const bool select, const float color[4])
@@ -186,31 +188,17 @@ static void arrow_draw_geom(const ArrowManipulator3D *arrow, const bool select,
 
 static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, const bool highlight)
 {
-	const float up[3] = {0.0f, 0.0f, 1.0f};
 	float col[4];
-	float rot[3][3];
-	float mat[4][4];
 	float final_matrix[4][4];
 
 	manipulator_color_get(&arrow->manipulator, highlight, col);
 	manipulator_arrow_matrix_world_get(&arrow->manipulator, final_matrix);
 
-	if (arrow->flag & ARROW_UP_VECTOR_SET) {
-		copy_v3_v3(rot[2], arrow->direction);
-		copy_v3_v3(rot[1], arrow->up);
-		cross_v3_v3v3(rot[0], arrow->up, arrow->direction);
-	}
-	else {
-		rotation_between_vecs_to_mat3(rot, up, arrow->direction);
-	}
-	copy_m4_m3(mat, rot);
-	copy_v3_v3(mat[3], final_matrix[3]);
-	mul_mat3_m4_fl(mat, arrow->manipulator.scale);
+	mul_mat3_m4_fl(final_matrix, arrow->manipulator.scale);
+	mul_m4_m4m4(final_matrix, final_matrix, arrow->manipulator.matrix_offset);
 
 	gpuPushMatrix();
-	gpuMultMatrix(mat);
-	gpuMultMatrix(arrow->manipulator.matrix_offset);
-
+	gpuMultMatrix(final_matrix);
 	glEnable(GL_BLEND);
 	arrow_draw_geom(arrow, select, col);
 	glDisable(GL_BLEND);
@@ -219,13 +207,13 @@ static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, cons
 
 	if (arrow->manipulator.interaction_data) {
 		ManipulatorInteraction *inter = arrow->manipulator.interaction_data;
+		float offset_matrix[4][4];
 
-		copy_m4_m3(mat, rot);
-		copy_v3_v3(mat[3], inter->init_matrix[3]);
-		mul_mat3_m4_fl(mat, inter->init_scale);
+		copy_m4_m4(offset_matrix, inter->init_matrix);
+		mul_mat3_m4_fl(offset_matrix, inter->init_scale);
 
 		gpuPushMatrix();
-		gpuMultMatrix(mat);
+		gpuMultMatrix(offset_matrix);
 		gpuMultMatrix(arrow->manipulator.matrix_offset);
 
 		glEnable(GL_BLEND);
@@ -271,7 +259,7 @@ static void manipulator_arrow_modal(bContext *C, wmManipulator *mpr, const wmEve
 
 	copy_v3_v3(orig_origin, inter->init_matrix[3]);
 	orig_origin[3] = 1.0f;
-	add_v3_v3v3(offset, orig_origin, arrow->direction);
+	add_v3_v3v3(offset, orig_origin, arrow->manipulator.matrix[2]);
 	offset[3] = 1.0f;
 
 	/* calculate view vector */
@@ -285,7 +273,7 @@ static void manipulator_arrow_modal(bContext *C, wmManipulator *mpr, const wmEve
 
 	/* first determine if view vector is really close to the direction. If it is, we use
 	 * vertical movement to determine offset, just like transform system does */
-	if (RAD2DEG(acos(dot_v3v3(viewvec, arrow->direction))) > 5.0f) {
+	if (RAD2DEG(acos(dot_v3v3(viewvec, arrow->manipulator.matrix[2]))) > 5.0f) {
 		/* multiply to projection space */
 		mul_m4_v4(rv3d->persmat, orig_origin);
 		mul_v4_fl(orig_origin, 1.0f / orig_origin[3]);
@@ -330,11 +318,11 @@ static void manipulator_arrow_modal(bContext *C, wmManipulator *mpr, const wmEve
 		cross_v3_v3v3(plane, tangent, viewvec);
 
 		const float plane_offset = dot_v3v3(plane, offset);
-		const float plane_dir = dot_v3v3(plane, arrow->direction);
+		const float plane_dir = dot_v3v3(plane, arrow->manipulator.matrix[2]);
 		const float fac = (plane_dir != 0.0f) ? (plane_offset / plane_dir) : 0.0f;
 		facdir = (fac < 0.0) ? -1.0 : 1.0;
 		if (isfinite(fac)) {
-			mul_v3_v3fl(offset, arrow->direction, fac);
+			mul_v3_v3fl(offset, arrow->manipulator.matrix[2], fac);
 		}
 	}
 	else {
@@ -373,14 +361,11 @@ static void manipulator_arrow_setup(wmManipulator *mpr)
 {
 	ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
 
-	const float dir_default[3] = {0.0f, 0.0f, 1.0f};
-
 	arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_ACTIVE;
 
 	arrow->style = -1;
 	arrow->len = 1.0f;
 	arrow->data.range_fac = 1.0f;
-	copy_v3_v3(arrow->direction, dir_default);
 }
 
 static void manipulator_arrow_invoke(
@@ -449,34 +434,6 @@ void ED_manipulator_arrow3d_set_style(struct wmManipulator *mpr, int style)
 }
 
 /**
- * Define direction the arrow will point towards
- */
-void ED_manipulator_arrow3d_set_direction(wmManipulator *mpr, const float direction[3])
-{
-	ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
-
-	copy_v3_v3(arrow->direction, direction);
-	normalize_v3(arrow->direction);
-}
-
-/**
- * Define up-direction of the arrow manipulator
- */
-void ED_manipulator_arrow3d_set_up_vector(wmManipulator *mpr, const float direction[3])
-{
-	ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
-
-	if (direction) {
-		copy_v3_v3(arrow->up, direction);
-		normalize_v3(arrow->up);
-		arrow->flag |= ARROW_UP_VECTOR_SET;
-	}
-	else {
-		arrow->flag &= ~ARROW_UP_VECTOR_SET;
-	}
-}
-
-/**
  * Define a custom arrow line length
  */
 void ED_manipulator_arrow3d_set_line_len(wmManipulator *mpr, const float len)
diff --git a/source/blender/editors/manipulator_library/dial3d_manipulator.c b/source/blender/editors/manipulator_library/dial3d_manipulator.c
index 0aa3e929439..f4459b6bef2 100644
--- a/source/blender/editors/manipulator_library/dial3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/dial3d_manipulator.c
@@ -32,6 +32,10 @@
  *
  * \brief Circle shaped manipulator for circular interaction.
  * Currently no own handling, use with operator only.
+ *
+ * - `matrix[0]` is derived from Y and Z.
+ * - `matrix[1]` is 'up' when DialManipulator.use_start_y_axis is set.
+ * - `matrix[2]` is the axis the dial rotates around (all dials).
  */
 
 #include "BIF_gl.h"
@@ -69,12 +73,10 @@ static void manipulator_dial_modal(bContext *C, wmManipulator *mpr, const wmEven
 typedef struct DialManipulator {
 	wmManipulator manipulator;
 	int style;
-	float direction[3];
 
 	/* Optional, for drawing the start of the pie based on on a vector
 	 * instead of the initial mouse location. Only for display. */
-	float start_direction[3];
-	uint use_start_direction : 1;
+	uint use_start_y_axis : 1;
 
 	/* Show 2x helper angles (a mirrored segment).
 	 * Use when the dial represents a plane. */
@@ -108,7 +110,7 @@ static void dial_calc_matrix(const DialManipulator *dial, float mat[4][4])
 	float rot[3][3];
 	const float up[3] = {0.0f, 0.0f, 1.0f};
 
-	rotation_between_vecs_to_mat3(rot, up, dial->direction);
+	rotation_between_vecs_to_mat3(rot, up, dial->manipulator.matrix[2]);
 	copy_m4_m3(mat, rot);
 	copy_v3_v3(mat[3], dial->manipulator.matrix[3]);
 	mul_mat3_m4_fl(mat, dial->manipulator.scale);
@@ -209,7 +211,7 @@ static void dial_ghostarc_get_angles(
 	/* we might need to invert the direction of the angles */
 	float view_vec[3], axis_vec[3];
 	ED_view3d_global_to_vector(rv3d, dial->manipulator.matrix[3], view_vec);
-	normalize_v3_v3(axis_vec, dial->direction);
+	normalize_v3_v3(axis_vec, dial->manipulator.matrix[2]);
 
 	float proj_outer_rel[3];
 	mul_v3_project_m4_v3(proj_outer_rel

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list