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>2013-07-26 10:12:49 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-07-26 10:12:49 +0400
commit29df776b89691cc44b6d88afd5956a64aba88058 (patch)
tree858ed9eff812b2a72ef710d47f10f1d9c82b7ba7 /source/blender
parent501649a806db6b1175694254f4be3fe249f90163 (diff)
optimization: call one bmesh operator for rotate (not 3).
added pivot_m4() utility function since rotating about an arbitrary point is handy.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/BLI_math_matrix.h2
-rw-r--r--source/blender/blenlib/intern/math_matrix.c15
-rw-r--r--source/blender/bmesh/operators/bmo_utils.c18
3 files changed, 22 insertions, 13 deletions
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index 723122d7814..1d877be67bd 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -175,7 +175,7 @@ void mat4_to_size(float r[3], float M[4][4]);
void translate_m4(float mat[4][4], float tx, float ty, float tz);
void rotate_m4(float mat[4][4], const char axis, const float angle);
void rotate_m2(float mat[2][2], const float angle);
-
+void pivot_m4(float mat[4][4], const float pivot[3]);
void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3]);
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[4][4]);
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 312805e23f6..3f635f97ec0 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -1374,6 +1374,21 @@ void rotate_m2(float mat[2][2], const float angle)
mat[1][0] = -mat[0][1];
}
+/* scale or rotate around a non zero pivot */
+void pivot_m4(float mat[4][4], const float pivot[3])
+{
+ float tmat[4][4];
+
+ unit_m4(tmat);
+
+ copy_v3_v3(tmat[3], pivot);
+ mul_m4_m4m4(mat, tmat, mat);
+
+ /* invert the matrix */
+ negate_v3(tmat[3]);
+ mul_m4_m4m4(mat, mat, tmat);
+}
+
void blend_m3_m3m3(float out[3][3], float dst[3][3], float src[3][3], const float srcweight)
{
float srot[3][3], drot[3][3];
diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c
index 2a0a7864499..053e4da6e02 100644
--- a/source/blender/bmesh/operators/bmo_utils.c
+++ b/source/blender/bmesh/operators/bmo_utils.c
@@ -92,20 +92,14 @@ void bmo_scale_exec(BMesh *bm, BMOperator *op)
void bmo_rotate_exec(BMesh *bm, BMOperator *op)
{
- float vec[3];
-
- BMO_slot_vec_get(op->slots_in, "cent", vec);
-
- /* there has to be a proper matrix way to do this, but
- * this is how editmesh did it and I'm too tired to think
- * through the math right now. */
- mul_v3_fl(vec, -1.0f);
- BMO_op_callf(bm, op->flag, "translate verts=%s vec=%v", op, "verts", vec);
+ float center[3];
+ float mat[4][4];
- BMO_op_callf(bm, op->flag, "transform matrix=%s verts=%s", op, "matrix", op, "verts");
+ BMO_slot_vec_get(op->slots_in, "cent", center);
+ BMO_slot_mat4_get(op->slots_in, "matrix", mat);
+ pivot_m4(mat, center);
- mul_v3_fl(vec, -1.0f);
- BMO_op_callf(bm, op->flag, "translate verts=%s vec=%v", op, "verts", vec);
+ BMO_op_callf(bm, op->flag, "transform matrix=%m4 verts=%s", mat, op, "verts");
}
void bmo_reverse_faces_exec(BMesh *bm, BMOperator *op)