Math Lib: add transpose_m3_m3, m3_m4, m4_m4
authorCampbell Barton <ideasman42@gmail.com>
Thu, 30 Oct 2014 11:13:00 +0000 (12:13 +0100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 30 Oct 2014 11:15:14 +0000 (12:15 +0100)
source/blender/blenkernel/intern/particle.c
source/blender/blenlib/BLI_math_matrix.h
source/blender/blenlib/intern/math_matrix.c
source/blender/collada/collada_internal.cpp
source/blender/editors/armature/editarmature_sketch.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/transform/transform_snap.c
source/blender/ikplugin/intern/iksolver_plugin.c
source/blender/render/intern/source/convertblender.c

index ad8276b902c816387ea1faf1e02c942672324a5d..e1b21794f836737730866209e806fbd6736a0549 100644 (file)
@@ -4563,8 +4563,7 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa
                psys_particle_on_emitter(psmd, PART_FROM_FACE, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, loc, nor, 0, 0, 0, 0);
 
        if (psys->part->rotmode == PART_ROT_VEL) {
-               copy_m3_m4(nmat, ob->imat);
-               transpose_m3(nmat);
+               transpose_m3_m4(nmat, ob->imat);
                mul_m3_v3(nmat, nor);
                normalize_v3(nor);
 
index e58e42f3c2d7fc4fe551ce50f93c223853814989..ee8b53037b0e035a88ad23c5c0e30a3526589451 100644 (file)
@@ -144,7 +144,10 @@ void mul_v4d_m4v4d(double r[4], float M[4][4], double v[4]);
 /****************************** Linear Algebra *******************************/
 
 void transpose_m3(float R[3][3]);
+void transpose_m3_m3(float R[3][3], float A[3][3]);
+void transpose_m3_m4(float R[3][3], float A[4][4]);
 void transpose_m4(float R[4][4]);
+void transpose_m4_m4(float R[4][4], float A[4][4]);
 
 int compare_m4m4(float mat1[4][4], float mat2[4][4], float limit);
 
index 115980cb3e63cf53b9346047cf5468b8885299eb..293e90c87130cf12967e26cb470e7552eb008284 100644 (file)
@@ -876,6 +876,37 @@ void transpose_m3(float mat[3][3])
        mat[2][1] = t;
 }
 
+void transpose_m3_m3(float rmat[3][3], float mat[3][3])
+{
+       BLI_assert(rmat != mat);
+
+       rmat[0][0] = mat[0][0];
+       rmat[0][1] = mat[1][0];
+       rmat[0][2] = mat[2][0];
+       rmat[1][0] = mat[0][1];
+       rmat[1][1] = mat[1][1];
+       rmat[1][2] = mat[2][1];
+       rmat[2][0] = mat[0][2];
+       rmat[2][1] = mat[1][2];
+       rmat[2][2] = mat[2][2];
+}
+
+/* seems obscure but in-fact a common operation */
+void transpose_m3_m4(float rmat[3][3], float mat[4][4])
+{
+       BLI_assert(&rmat[0][0] != &mat[0][0]);
+
+       rmat[0][0] = mat[0][0];
+       rmat[0][1] = mat[1][0];
+       rmat[0][2] = mat[2][0];
+       rmat[1][0] = mat[0][1];
+       rmat[1][1] = mat[1][1];
+       rmat[1][2] = mat[2][1];
+       rmat[2][0] = mat[0][2];
+       rmat[2][1] = mat[1][2];
+       rmat[2][2] = mat[2][2];
+}
+
 void transpose_m4(float mat[4][4])
 {
        float t;
@@ -902,6 +933,28 @@ void transpose_m4(float mat[4][4])
        mat[3][2] = t;
 }
 
+void transpose_m4_m4(float rmat[4][4], float mat[4][4])
+{
+       BLI_assert(rmat != mat);
+
+       rmat[0][0] = mat[0][0];
+       rmat[0][1] = mat[1][0];
+       rmat[0][2] = mat[2][0];
+       rmat[0][3] = mat[3][0];
+       rmat[1][0] = mat[0][1];
+       rmat[1][1] = mat[1][1];
+       rmat[1][2] = mat[2][1];
+       rmat[1][3] = mat[3][1];
+       rmat[2][0] = mat[0][2];
+       rmat[2][1] = mat[1][2];
+       rmat[2][2] = mat[2][2];
+       rmat[2][3] = mat[3][2];
+       rmat[3][0] = mat[0][3];
+       rmat[3][1] = mat[1][3];
+       rmat[3][2] = mat[2][3];
+       rmat[3][3] = mat[3][3];
+}
+
 int compare_m4m4(float mat1[4][4], float mat2[4][4], float limit)
 {
        if (compare_v4v4(mat1[0], mat2[0], limit))
@@ -1145,8 +1198,7 @@ bool is_uniform_scaled_m3(float m[3][3])
        float t[3][3];
        float l1, l2, l3, l4, l5, l6;
 
-       copy_m3_m3(t, m);
-       transpose_m3(t);
+       transpose_m3_m3(t, m);
 
        l1 = len_squared_v3(m[0]);
        l2 = len_squared_v3(m[1]);
@@ -1413,9 +1465,7 @@ void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3])
        /* note: this is a workaround for negative matrix not working for rotation conversion, FIXME */
        normalize_m3_m3(mat3_n, mat3);
        if (is_negative_m3(mat3)) {
-               negate_v3(mat3_n[0]);
-               negate_v3(mat3_n[1]);
-               negate_v3(mat3_n[2]);
+               negate_m3(mat3_n);
        }
 
        /* rotation */
@@ -1462,9 +1512,7 @@ void mat4_to_loc_quat(float loc[3], float quat[4], float wmat[4][4])
        /* so scale doesn't interfere with rotation [#24291] */
        /* note: this is a workaround for negative matrix not working for rotation conversion, FIXME */
        if (is_negative_m3(mat3)) {
-               negate_v3(mat3_n[0]);
-               negate_v3(mat3_n[1]);
-               negate_v3(mat3_n[2]);
+               negate_m3(mat3_n);
        }
 
        mat3_to_quat(quat, mat3_n);
index 567ee22b3d62cf5c8d34644e67f7ba6bafd94bb7..2aab9b6e7d3ac022a9c38aff76507a0faa6bb7f1 100644 (file)
@@ -94,8 +94,7 @@ void UnitConverter::dae_matrix_to_mat4_(float out[4][4], const COLLADABU::Math::
 
 void UnitConverter::mat4_to_dae(float out[4][4], float in[4][4])
 {
-       copy_m4_m4(out, in);
-       transpose_m4(out);
+       transpose_m4_m4(out, in);
 }
 
 void UnitConverter::mat4_to_dae_double(double out[4][4], float in[4][4])
index c9effe404da46a84fb6cd01a2da87f06ae3fb7b7..737f901a055f37b668cf71208df3178216399830 100644 (file)
@@ -403,9 +403,7 @@ static void sk_retargetStroke(bContext *C, SK_Stroke *stk)
        RigGraph *rg;
 
        invert_m4_m4(imat, obedit->obmat);
-
-       copy_m3_m4(tmat, obedit->obmat);
-       transpose_m3(tmat);
+       transpose_m3_m4(tmat, obedit->obmat);
 
        arc = sk_strokeToArc(stk, imat, tmat);
 
@@ -1358,9 +1356,7 @@ static void sk_convertStroke(bContext *C, SK_Stroke *stk)
        head = NULL;
 
        invert_m4_m4(invmat, obedit->obmat);
-
-       copy_m3_m4(tmat, obedit->obmat);
-       transpose_m3(tmat);
+       transpose_m3_m4(tmat, obedit->obmat);
 
        for (i = 0; i < stk->nb_points; i++) {
                SK_Point *pt = stk->points + i;
index db04d3ccd66f6afa9017f295b583dc0dd2710456..f8f7bd1137efd09bfbac9b02389284a52820caa3 100644 (file)
@@ -2153,8 +2153,7 @@ static void calcDrawDMNormalScale(Object *ob, drawDMNormal_userData *data)
                invert_m3_m3(data->imat, obmat);
 
                /* transposed inverted matrix */
-               copy_m3_m3(data->tmat, data->imat);
-               transpose_m3(data->tmat);
+               transpose_m3_m3(data->tmat, data->imat);
        }
 }
 
index 8a3e8f19db40d29a89432733cc4427c80ca30d94..47b208442945b5e5a31373b944347e631fcc917f 100644 (file)
@@ -1543,8 +1543,7 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes
                float ray_start_local[3], ray_normal_local[3], local_scale, len_diff = TRANSFORM_DIST_MAX_RAY;
 
                invert_m4_m4(imat, obmat);
-               copy_m3_m4(timat, imat);
-               transpose_m3(timat);
+               transpose_m3_m4(timat, imat);
 
                copy_v3_v3(ray_start_local, ray_start);
                copy_v3_v3(ray_normal_local, ray_normal);
@@ -2101,8 +2100,7 @@ static bool peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[4][4],
 
                invert_m4_m4(imat, obmat);
 
-               copy_m3_m4(timat, imat);
-               transpose_m3(timat);
+               transpose_m3_m4(timat, imat);
                
                copy_v3_v3(ray_start_local, ray_start);
                copy_v3_v3(ray_normal_local, ray_normal);
index cd09b56b262af05105f8baccb56857f5d9cc8bf0..5da06ed91eca7b54424c6b7801b9ffd8944e29d1 100644 (file)
@@ -307,8 +307,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
 
                /* compute rest basis and its inverse */
                copy_m3_m3(rest_basis, bone->bone_mat);
-               copy_m3_m3(irest_basis, bone->bone_mat);
-               transpose_m3(irest_basis);
+               transpose_m3_m3(irest_basis, bone->bone_mat);
 
                /* compute basis with rest_basis removed */
                invert_m3_m3(iR_parmat, R_parmat);
index ef1478235d8be6846002105f67f9935b7b0c50f0..aefb2b7b0e8397c6bfa5a3de12e1ceb4bb1c0883 100644 (file)
@@ -1427,8 +1427,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
 /* 2.5 setup matrices */
        mul_m4_m4m4(mat, re->viewmat, ob->obmat);
        invert_m4_m4(ob->imat, mat);    /* need to be that way, for imat texture */
-       copy_m3_m4(nmat, ob->imat);
-       transpose_m3(nmat);
+       transpose_m3_m4(nmat, ob->imat);
 
        if (psys->flag & PSYS_USE_IMAT) {
                /* psys->imat is the original emitter's inverse matrix, ob->obmat is the duplicated object's matrix */
@@ -2652,8 +2651,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
        negative_scale = is_negative_m4(mat);
 
        /* local object -> world space transform for normals */
-       copy_m4_m4(nmat, mat);
-       transpose_m4(nmat);
+       transpose_m4_m4(nmat, mat);
        invert_m4(nmat);
 
        /* material array */