Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-08-09 15:24:05 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-08-09 15:34:08 +0300
commit8403ec51608cd82752ae0dc8efb11670fe428b0b (patch)
tree693bade20f88596c49059cd6d2ecc5db6191a2ed
parentb5e6a21f1dbd76f3ea72932c4e764338f926f79f (diff)
Manipulator: Add function to calculate matrix
Each manipulator was doing this slightly differently, use shared function which can optionally override each matrix.
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c35
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c18
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c30
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c20
-rw-r--r--source/blender/editors/transform/transform_manipulator.c1
-rw-r--r--source/blender/windowmanager/manipulators/WM_manipulator_api.h16
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator.c38
7 files changed, 97 insertions, 61 deletions
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.
+ */
+struct WM_ManipulatorMatrixParams {
+ const float(*matrix_space)[4];
+ const float(*matrix_basis)[4];
+ const float(*matrix_offset)[4];
+ const float *scale_final;
+};
+
+void WM_manipulator_calc_matrix_final_params(
+ const struct wmManipulator *mpr, const struct WM_ManipulatorMatrixParams *params,
+ float r_mat[4][4]);
+
+void WM_manipulator_calc_matrix_final(const struct wmManipulator *mpr, float r_mat[4][4]);
+
/* properties */
void WM_manipulator_properties_create_ptr(struct PointerRNA *ptr, struct wmManipulatorType *wt);
void WM_manipulator_properties_create(struct PointerRNA *ptr, const char *opstring);
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
index 3f10864995f..3e6e851c6e0 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
@@ -508,6 +508,44 @@ int wm_manipulator_is_visible(wmManipulator *mpr)
return WM_MANIPULATOR_IS_VISIBLE_UPDATE | WM_MANIPULATOR_IS_VISIBLE_DRAW;
}
+void WM_manipulator_calc_matrix_final_params(
+ const wmManipulator *mpr,
+ const struct WM_ManipulatorMatrixParams *params,
+ float r_mat[4][4])
+{
+ const float (* const matrix_space)[4] = params->matrix_space ? params->matrix_space : mpr->matrix_space;
+ const float (* const matrix_basis)[4] = params->matrix_basis ? params->matrix_basis : mpr->matrix_basis;
+ const float (* const matrix_offset)[4] = params->matrix_offset ? params->matrix_offset : mpr->matrix_offset;
+ const float *scale_final = params->scale_final ? params->scale_final : &mpr->scale_final;
+
+ float final_matrix[4][4];
+
+ copy_m4_m4(final_matrix, matrix_basis);
+
+ if (mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) {
+ mul_mat3_m4_fl(final_matrix, *scale_final);
+ mul_m4_m4m4(final_matrix, final_matrix, matrix_offset);
+ }
+ else {
+ mul_m4_m4m4(final_matrix, final_matrix, matrix_offset);
+ mul_mat3_m4_fl(final_matrix, *scale_final);
+ }
+
+ mul_m4_m4m4(r_mat, final_matrix, matrix_space);
+}
+
+void WM_manipulator_calc_matrix_final(const wmManipulator *mpr, float r_mat[4][4])
+{
+ WM_manipulator_calc_matrix_final_params(
+ mpr,
+ &((struct WM_ManipulatorMatrixParams) {
+ .matrix_space = mpr->matrix_space,
+ .matrix_basis = mpr->matrix_basis,
+ .matrix_offset = mpr->matrix_offset,
+ .scale_final = &mpr->scale_final,
+ }), r_mat
+ );
+}
/** \name Manipulator Propery Access
*