diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-08-09 15:24:05 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-08-09 15:34:08 +0300 |
commit | 8403ec51608cd82752ae0dc8efb11670fe428b0b (patch) | |
tree | 693bade20f88596c49059cd6d2ecc5db6191a2ed /source/blender/editors/manipulator_library/manipulator_types | |
parent | b5e6a21f1dbd76f3ea72932c4e764338f926f79f (diff) |
Manipulator: Add function to calculate matrix
Each manipulator was doing this slightly differently,
use shared function which can optionally override each matrix.
Diffstat (limited to 'source/blender/editors/manipulator_library/manipulator_types')
4 files changed, 42 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); |