[Bf-blender-cvs] [49be79693c6] blender2.8: Manipulator: use matrix instead of origin
Campbell Barton
noreply at git.blender.org
Sun Jun 18 00:34:33 CEST 2017
Commit: 49be79693c6d2e3be20b2cd0ecf81e76a7121b2f
Author: Campbell Barton
Date: Sun Jun 18 05:38:10 2017 +1000
Branches: blender2.8
https://developer.blender.org/rB49be79693c6d2e3be20b2cd0ecf81e76a7121b2f
Manipulator: use matrix instead of origin
This avoids having to use manipulator-type specific functions
to set the orientation.
And will make it simpler to access transformation from Python.
Currently the matrix is still used as an offset in places.
Also per-type orientation values still need to be removed.
===================================================================
M source/blender/editors/manipulator_library/arrow2d_manipulator.c
M source/blender/editors/manipulator_library/arrow3d_manipulator.c
M source/blender/editors/manipulator_library/cage2d_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/manipulator_library_intern.h
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/windowmanager/manipulators/WM_manipulator_types.h
M source/blender/windowmanager/manipulators/intern/wm_manipulator.c
M source/blender/windowmanager/manipulators/wm_manipulator_fn.h
===================================================================
diff --git a/source/blender/editors/manipulator_library/arrow2d_manipulator.c b/source/blender/editors/manipulator_library/arrow2d_manipulator.c
index 159fcd658ec..5e7975d05e3 100644
--- a/source/blender/editors/manipulator_library/arrow2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/arrow2d_manipulator.c
@@ -68,7 +68,7 @@ typedef struct ArrowManipulator2D {
} ArrowManipulator2D;
-static void arrow2d_draw_geom(ArrowManipulator2D *arrow, const float origin[2], const float color[4])
+static void arrow2d_draw_geom(ArrowManipulator2D *arrow, const float matrix[4][4], const float color[4])
{
const float size = 0.11f;
const float size_h = size / 2.0f;
@@ -78,11 +78,13 @@ static void arrow2d_draw_geom(ArrowManipulator2D *arrow, const float origin[2],
uint pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
gpuPushMatrix();
- gpuTranslate2fv(origin);
+ gpuMultMatrix(matrix);
gpuScaleUniform(arrow->manipulator.scale);
gpuRotate2D(RAD2DEGF(arrow->angle));
/* local offset */
- gpuTranslate2f(arrow->manipulator.offset[0] + draw_line_ofs, arrow->manipulator.offset[1]);
+ gpuTranslate2f(
+ arrow->manipulator.matrix_offset[3][0] + draw_line_ofs,
+ arrow->manipulator.matrix_offset[3][1]);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
@@ -113,14 +115,14 @@ static void manipulator_arrow2d_draw(const bContext *UNUSED(C), struct wmManipul
glLineWidth(mpr->line_width);
glEnable(GL_BLEND);
- arrow2d_draw_geom(arrow, mpr->origin, col);
+ arrow2d_draw_geom(arrow, mpr->matrix, col);
glDisable(GL_BLEND);
if (mpr->interaction_data) {
ManipulatorInteraction *inter = arrow->manipulator.interaction_data;
glEnable(GL_BLEND);
- arrow2d_draw_geom(arrow, inter->init_origin, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
+ arrow2d_draw_geom(arrow, inter->init_matrix, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
glDisable(GL_BLEND);
}
}
@@ -139,7 +141,7 @@ static void manipulator_arrow2d_invoke(
{
ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
- copy_v2_v2(inter->init_origin, mpr->origin);
+ copy_m4_m4(inter->init_matrix, mpr->matrix);
mpr->interaction_data = inter;
}
@@ -152,7 +154,7 @@ static int manipulator_arrow2d_test_select(
float mval_local[2];
copy_v2_v2(mval_local, mval);
- sub_v2_v2(mval_local, mpr->origin);
+ sub_v2_v2(mval_local, mpr->matrix[3]);
float line[2][2];
line[0][0] = line[0][1] = line[1][0] = 0.0f;
diff --git a/source/blender/editors/manipulator_library/arrow3d_manipulator.c b/source/blender/editors/manipulator_library/arrow3d_manipulator.c
index f0f7470c058..1d3cb281af1 100644
--- a/source/blender/editors/manipulator_library/arrow3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/arrow3d_manipulator.c
@@ -89,12 +89,12 @@ typedef struct ArrowManipulator3D {
/* -------------------------------------------------------------------- */
-static void manipulator_arrow_position_get(wmManipulator *mpr, float r_pos[3])
+static void manipulator_arrow_matrix_world_get(wmManipulator *mpr, float r_matrix[4][4])
{
ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
- mul_v3_v3fl(r_pos, arrow->direction, arrow->data.offset);
- add_v3_v3(r_pos, arrow->manipulator.origin);
+ copy_m4_m4(r_matrix, arrow->manipulator.matrix);
+ madd_v3_v3fl(r_matrix[3], arrow->direction, arrow->data.offset);
}
static void arrow_draw_geom(const ArrowManipulator3D *arrow, const bool select, const float color[4])
@@ -190,10 +190,10 @@ static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, cons
float col[4];
float rot[3][3];
float mat[4][4];
- float final_pos[3];
+ float final_matrix[4][4];
manipulator_color_get(&arrow->manipulator, highlight, col);
- manipulator_arrow_position_get(&arrow->manipulator, final_pos);
+ manipulator_arrow_matrix_world_get(&arrow->manipulator, final_matrix);
if (arrow->flag & ARROW_UP_VECTOR_SET) {
copy_v3_v3(rot[2], arrow->direction);
@@ -204,12 +204,12 @@ static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, cons
rotation_between_vecs_to_mat3(rot, up, arrow->direction);
}
copy_m4_m3(mat, rot);
- copy_v3_v3(mat[3], final_pos);
+ copy_v3_v3(mat[3], final_matrix[3]);
mul_mat3_m4_fl(mat, arrow->manipulator.scale);
gpuPushMatrix();
gpuMultMatrix(mat);
- gpuTranslate3fv(arrow->manipulator.offset);
+ gpuMultMatrix(arrow->manipulator.matrix_offset);
glEnable(GL_BLEND);
arrow_draw_geom(arrow, select, col);
@@ -221,12 +221,12 @@ static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, cons
ManipulatorInteraction *inter = arrow->manipulator.interaction_data;
copy_m4_m3(mat, rot);
- copy_v3_v3(mat[3], inter->init_origin);
+ copy_v3_v3(mat[3], inter->init_matrix[3]);
mul_mat3_m4_fl(mat, inter->init_scale);
gpuPushMatrix();
gpuMultMatrix(mat);
- gpuTranslate3fv(arrow->manipulator.offset);
+ gpuMultMatrix(arrow->manipulator.matrix_offset);
glEnable(GL_BLEND);
arrow_draw_geom(arrow, select, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f});
@@ -269,7 +269,7 @@ static void manipulator_arrow_modal(bContext *C, wmManipulator *mpr, const wmEve
bool use_vertical = false;
- copy_v3_v3(orig_origin, inter->init_origin);
+ copy_v3_v3(orig_origin, inter->init_matrix[3]);
orig_origin[3] = 1.0f;
add_v3_v3v3(offset, orig_origin, arrow->direction);
offset[3] = 1.0f;
@@ -313,7 +313,7 @@ static void manipulator_arrow_modal(bContext *C, wmManipulator *mpr, const wmEve
float zfac = ED_view3d_calc_zfac(rv3d, orig_origin, NULL);
ED_view3d_win_to_delta(ar, dir2d_final, offset, zfac);
- add_v3_v3v3(orig_origin, offset, inter->init_origin);
+ add_v3_v3v3(orig_origin, offset, inter->init_matrix[3]);
/* calculate view vector for the new position */
if (rv3d->is_persp) {
@@ -402,7 +402,7 @@ static void manipulator_arrow_invoke(
inter->init_scale = mpr->scale;
- manipulator_arrow_position_get(mpr, inter->init_origin);
+ manipulator_arrow_matrix_world_get(mpr, inter->init_matrix);
mpr->interaction_data = inter;
}
@@ -535,7 +535,7 @@ static void MANIPULATOR_WT_arrow_3d(wmManipulatorType *wt)
/* api callbacks */
wt->draw = manipulator_arrow_draw;
wt->draw_select = manipulator_arrow_draw_select;
- wt->position_get = manipulator_arrow_position_get;
+ wt->matrix_world_get = manipulator_arrow_matrix_world_get;
wt->modal = manipulator_arrow_modal;
wt->setup = manipulator_arrow_setup;
wt->invoke = manipulator_arrow_invoke;
diff --git a/source/blender/editors/manipulator_library/cage2d_manipulator.c b/source/blender/editors/manipulator_library/cage2d_manipulator.c
index 9236a5ef10e..bf6c23f98e7 100644
--- a/source/blender/editors/manipulator_library/cage2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/cage2d_manipulator.c
@@ -219,8 +219,8 @@ static void manipulator_rect_transform_draw(const bContext *UNUSED(C), wmManipul
BLI_assert(cage->style != -1);
gpuPushMatrix();
- gpuTranslate2f(mpr->origin[0] + mpr->offset[0],
- mpr->origin[1] + mpr->offset[1]);
+ gpuMultMatrix(mpr->matrix);
+ gpuMultMatrix(mpr->matrix_offset);
if (cage->style & ED_MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM)
gpuScaleUniform(cage->scale[0]);
else
@@ -281,9 +281,9 @@ static int manipulator_rect_transform_test_select(
float aspx = 1.0f, aspy = 1.0f;
/* rotate mouse in relation to the center and relocate it */
- sub_v2_v2v2(point_local, mouse, mpr->origin);
- point_local[0] -= mpr->offset[0];
- point_local[1] -= mpr->offset[1];
+ sub_v2_v2v2(point_local, mouse, mpr->matrix[3]);
+ point_local[0] -= mpr->matrix_offset[3][0];
+ point_local[1] -= mpr->matrix_offset[3][1];
//rotate_m2(matrot, -cage->transform.rotation);
if (cage->style & ED_MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM)
@@ -419,7 +419,7 @@ static void manipulator_rect_transform_invoke(
Cage2D *cage = (Cage2D *)mpr;
RectTransformInteraction *data = MEM_callocN(sizeof(RectTransformInteraction), "cage_interaction");
- copy_v2_v2(data->orig_offset, mpr->offset);
+ copy_v2_v2(data->orig_offset, mpr->matrix_offset[3]);
copy_v2_v2(data->orig_scale, cage->scale);
data->orig_mouse[0] = event->mval[0];
@@ -435,26 +435,26 @@ static void manipulator_rect_transform_modal(
Cage2D *cage = (Cage2D *)mpr;
RectTransformInteraction *data = mpr->interaction_data;
/* needed here as well in case clamping occurs */
- const float orig_ofx = mpr->offset[0], orig_ofy = mpr->offset[1];
+ const float orig_ofx = mpr->matrix_offset[3][0], orig_ofy = mpr->matrix_offset[3][1];
const float valuex = (event->mval[0] - data->orig_mouse[0]);
const float valuey = (event->mval[1] - data->orig_mouse[1]);
if (mpr->highlight_part == ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_TRANSLATE) {
- mpr->offset[0] = data->orig_offset[0] + valuex;
- mpr->offset[1] = data->orig_offset[1] + valuey;
+ mpr->matrix_offset[3][0] = data->orig_offset[0] + valuex;
+ mpr->matrix_offset[3][1] = data->orig_offset[1] + valuey;
}
else if (mpr->highlight_part == ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_SCALEX_LEFT) {
- mpr->offset[0] = data->orig_offset[0] + valuex / 2.0;
+ mpr->matrix_offset[3][0] = data->orig_offset[0] + valuex / 2.0;
cage->scale[0] = (cage->w * data->orig_scale[0] - valuex) / cage->w;
}
else if (mpr->highlight_part == ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_SCALEX_RIGHT) {
- mpr->offset[0] = data->orig_offset[0] + valuex / 2.0;
+ mpr->matrix_offset[3][0] = data->orig_offset[0] + valuex / 2.0;
cage->scale[0] = (cage->w * data->orig_scale[0] + valuex) / cage->w;
}
else if (mpr->highlight_part == ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_SCALEY_DOWN) {
- mpr->offset[1] = data->orig_offset[1] + valuey / 2.0;
+ mpr->matrix_offset[3][1] = data->orig_offset[1] + valuey / 2.0;
if (cage->style & ED_MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) {
cage->scale[0] = (cage->h * data->orig_scale[0] - valuey) / cage->h;
@@ -464,7 +464,7 @@ static void manipulator_rect_transform_modal(
}
}
else if (mpr->highlight_part == ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_SCALEY_UP) {
- mpr->offset[1] = data->orig_offset[1] + valuey / 2.0;
+ mpr->matrix_off
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list