[Bf-blender-cvs] [8403ec51608] blender2.8: Manipulator: Add function to calculate matrix

Campbell Barton noreply at git.blender.org
Wed Aug 9 14:42:44 CEST 2017


Commit: 8403ec51608cd82752ae0dc8efb11670fe428b0b
Author: Campbell Barton
Date:   Wed Aug 9 22:24:05 2017 +1000
Branches: blender2.8
https://developer.blender.org/rB8403ec51608cd82752ae0dc8efb11670fe428b0b

Manipulator: Add function to calculate matrix

Each manipulator was doing this slightly differently,
use shared function which can optionally override each matrix.

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

M	source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
M	source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
M	source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
M	source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
M	source/blender/editors/transform/transform_manipulator.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/manipulator_library/manipulator_types/arrow3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
index f9d6770bdb3..a7a454d62c3 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
@@ -184,22 +184,19 @@ static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, cons
 {
 	wmManipulator *mpr = &arrow->manipulator;
 	float color[4];
-	float final_matrix[4][4];
+	float matrix_basis_adjust[4][4];
+	float matrix_final[4][4];
 
 	manipulator_color_get(mpr, highlight, color);
-	manipulator_arrow_matrix_world_get(mpr, final_matrix);
+	manipulator_arrow_matrix_world_get(mpr, matrix_basis_adjust);
 
-	if (mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) {
-		mul_mat3_m4_fl(final_matrix, arrow->manipulator.scale_final);
-	}
-	mul_m4_m4m4(final_matrix, final_matrix, mpr->matrix_offset);
-	if ((mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) == 0) {
-		mul_mat3_m4_fl(final_matrix, arrow->manipulator.scale_final);
-	}
+	WM_manipulator_calc_matrix_final_params(
+	        mpr, &((struct WM_ManipulatorMatrixParams) {
+	            .matrix_basis = matrix_basis_adjust,
+	        }), matrix_final);
 
 	gpuPushMatrix();
-	gpuMultMatrix(mpr->matrix_space);
-	gpuMultMatrix(final_matrix);
+	gpuMultMatrix(matrix_final);
 	glEnable(GL_BLEND);
 	arrow_draw_geom(arrow, select, color);
 	glDisable(GL_BLEND);
@@ -209,19 +206,15 @@ static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, cons
 	if (mpr->interaction_data) {
 		ManipulatorInteraction *inter = mpr->interaction_data;
 
-		copy_m4_m4(final_matrix, inter->init_matrix_basis);
-		if (mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) {
-			mul_mat3_m4_fl(final_matrix, inter->init_scale_final);
-		}
-		mul_m4_m4m4(final_matrix, final_matrix, mpr->matrix_offset);
-		if ((mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) == 0) {
-			mul_mat3_m4_fl(final_matrix, inter->init_scale_final);
-		}
+		WM_manipulator_calc_matrix_final_params(
+		        mpr, &((struct WM_ManipulatorMatrixParams) {
+		            .matrix_basis = inter->init_matrix_basis,
+		            .scale_final = &inter->init_scale_final,
+		        }), matrix_final);
 
 		gpuPushMatrix();
-		gpuMultMatrix(mpr->matrix_space);
+		gpuMultMatrix(matrix_final);
 
-		gpuMultMatrix(final_matrix);
 
 		glEnable(GL_BLEND);
 		arrow_draw_geom(arrow, select, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f});
diff --git a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
index 742b4c70613..0e8b8722b34 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
@@ -36,8 +36,6 @@
  * - `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).
- *
- * TODO: use matrix_space
  */
 
 #include "BIF_gl.h"
@@ -107,7 +105,6 @@ static void dial_calc_matrix(const wmManipulator *mpr, float mat[4][4])
 	rotation_between_vecs_to_mat3(rot, up, mpr->matrix_basis[2]);
 	copy_m4_m3(mat, rot);
 	copy_v3_v3(mat[3], mpr->matrix_basis[3]);
-	mul_mat3_m4_fl(mat, mpr->scale_final);
 }
 
 /* -------------------------------------------------------------------- */
@@ -275,18 +272,23 @@ static void dial_draw_intern(
         const bContext *C, wmManipulator *mpr,
         const bool select, const bool highlight, float clip_plane[4])
 {
-	float mat[4][4];
+	float matrix_basis_adjust[4][4];
+	float matrix_final[4][4];
 	float col[4];
 
 	BLI_assert(CTX_wm_area(C)->spacetype == SPACE_VIEW3D);
 
 	manipulator_color_get(mpr, highlight, col);
 
-	dial_calc_matrix(mpr, mat);
+	dial_calc_matrix(mpr, matrix_basis_adjust);
+
+	WM_manipulator_calc_matrix_final_params(
+	        mpr, &((struct WM_ManipulatorMatrixParams) {
+	            .matrix_basis = (void *)matrix_basis_adjust,
+	        }), matrix_final);
 
 	gpuPushMatrix();
-	gpuMultMatrix(mat);
-	gpuMultMatrix(mpr->matrix_offset);
+	gpuMultMatrix(matrix_final);
 
 	/* draw rotation indicator arc first */
 	if ((mpr->flag & WM_MANIPULATOR_DRAW_VALUE) &&
@@ -324,7 +326,7 @@ static void dial_draw_intern(
 	}
 
 	/* draw actual dial manipulator */
-	dial_geom_draw(mpr, col, select, mat, clip_plane);
+	dial_geom_draw(mpr, col, select, matrix_basis_adjust, clip_plane);
 
 	gpuPopMatrix();
 }
diff --git a/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
index 605c089f818..7b17a67c9f3 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
@@ -152,22 +152,14 @@ static void grab3d_draw_intern(
         const bool select, const bool highlight)
 {
 	float col[4];
-	float final_matrix[4][4];
+	float matrix_final[4][4];
 
 	manipulator_color_get(mpr, highlight, col);
 
-	copy_m4_m4(final_matrix, mpr->matrix_basis);
-	if (mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) {
-		mul_mat3_m4_fl(final_matrix, mpr->scale_final);
-	}
-	mul_m4_m4m4(final_matrix, final_matrix, mpr->matrix_offset);
-	if ((mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) == 0) {
-		mul_mat3_m4_fl(final_matrix, mpr->scale_final);
-	}
+	WM_manipulator_calc_matrix_final(mpr, matrix_final);
 
 	gpuPushMatrix();
-	gpuMultMatrix(mpr->matrix_space);
-	gpuMultMatrix(final_matrix);
+	gpuMultMatrix(matrix_final);
 	glEnable(GL_BLEND);
 
 	grab_geom_draw(mpr, col, select);
@@ -177,18 +169,14 @@ static void grab3d_draw_intern(
 	if (mpr->interaction_data) {
 		GrabInteraction *inter = mpr->interaction_data;
 
-		copy_m4_m4(final_matrix, inter->init_matrix_basis);
-		if (mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) {
-			mul_mat3_m4_fl(final_matrix, inter->init_scale_final);
-		}
-		mul_m4_m4m4(final_matrix, final_matrix, mpr->matrix_offset);
-		if ((mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) == 0) {
-			mul_mat3_m4_fl(final_matrix, inter->init_scale_final);
-		}
+		WM_manipulator_calc_matrix_final_params(
+		        mpr, &((struct WM_ManipulatorMatrixParams) {
+		            .matrix_basis = inter->init_matrix_basis,
+		            .scale_final = &inter->init_scale_final,
+		        }), matrix_final);
 
 		gpuPushMatrix();
-		gpuMultMatrix(mpr->matrix_space);
-		gpuMultMatrix(final_matrix);
+		gpuMultMatrix(matrix_final);
 		glEnable(GL_BLEND);
 		grab_geom_draw(mpr, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f}, select);
 		glDisable(GL_BLEND);
diff --git a/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
index fae73e5f622..d7378f9dedb 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
@@ -27,8 +27,6 @@
  *
  * \brief Manipulator with primitive drawing type (plane, cube, etc.).
  * Currently only plane primitive supported without own handling, use with operator only.
- *
- * TODO: use matrix_space
  */
 
 #include "BIF_gl.h"
@@ -91,21 +89,19 @@ static void manipulator_primitive_draw_intern(
         const bool highlight)
 {
 	float col_inner[4], col_outer[4];
-	float mat[4][4];
+	float matrix_final[4][4];
 	const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
 
 	manipulator_color_get(mpr, highlight, col_outer);
 	copy_v4_v4(col_inner, col_outer);
 	col_inner[3] *= 0.5f;
 
-	copy_m4_m4(mat, mpr->matrix_basis);
-	mul_mat3_m4_fl(mat, mpr->scale_final);
+	WM_manipulator_calc_matrix_final(mpr, matrix_final);
 
 	gpuPushMatrix();
-	gpuMultMatrix(mat);
+	gpuMultMatrix(matrix_final);
 
 	glEnable(GL_BLEND);
-	gpuMultMatrix(mpr->matrix_offset);
 	manipulator_primitive_draw_geom(col_inner, col_outer, draw_style);
 	glDisable(GL_BLEND);
 
@@ -118,14 +114,16 @@ static void manipulator_primitive_draw_intern(
 		copy_v3_fl(col_outer, 0.5f);
 		col_outer[3] = 0.8f;
 
-		copy_m4_m4(mat, inter->init_matrix_basis);
-		mul_mat3_m4_fl(mat, inter->init_scale_final);
+		WM_manipulator_calc_matrix_final_params(
+		        mpr, &((struct WM_ManipulatorMatrixParams) {
+		            .matrix_basis = inter->init_matrix_basis,
+		            .scale_final = &inter->init_scale_final,
+		        }), matrix_final);
 
 		gpuPushMatrix();
-		gpuMultMatrix(mat);
+		gpuMultMatrix(matrix_final);
 
 		glEnable(GL_BLEND);
-		gpuMultMatrix(mpr->matrix_offset);
 		manipulator_primitive_draw_geom(col_inner, col_outer, draw_style);
 		glDisable(GL_BLEND);
 
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index cddb7113361..e4207adc810 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -1205,6 +1205,7 @@ static void WIDGETGROUP_manipulator_setup(const bContext *UNUSED(C), wmManipulat
 				const float ofs[3] = {ofs_ax, ofs_ax, 0.0f};
 				WM_manipulator_set_scale(axis, 0.07f);
 				WM_manipulator_set_matrix_offset_location(axis, ofs);
+				WM_manipulator_set_flag(axis, WM_MANIPULATOR_DRAW_OFFSET_SCALE, true);
 				break;
 			}
 			case MAN_AXIS_TRANS_C:
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
index a29e31985a0..93ba8f4f762 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_api.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
@@ -102,6 +102,22 @@ void WM_manipulator_set_color(struct wmManipulator *mpr, const float col[4]);
 void WM_manipulator_get_color_highlight(const struct wmManipulator *mpr, float col_hi[4]);
 void WM_manipulator_set_color_highlight(struct wmManipulator *mpr, const float col[4]);
 
+/**
+ * Leaving values NULL use values from #wmManipulator.
+ *

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list