Revision: 49662
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49662
Author:   alexk
Date:     2012-08-07 16:23:31 +0000 (Tue, 07 Aug 2012)
Log Message:
-----------
Adding new functions to BLI_math_matrix

mult_m4_m3m4_q multiples 4x4 and 3x3 matrices and outputs 4x4 (needed for 
rotation). It doesn't do safe check!
mul_v4_m4v3 multiples 4x4 matrix by 3d vector and outputs 4d vector
mul_v3_m4v3_q  multiples 4x4 matrix by 3d vector and outputs 3d vector. It 
doesn't do safe check!

rotate_m4_right rotates 4x4 matrix by 90 degrees. Acceptable paxis values are 
'X', 'Y', 'Z', -'X', -'Y', -'Z'. Negative char rotatates -90 degrees.

Modified Paths:
--------------
    branches/soc-2012-swiss_cheese/source/blender/blenlib/BLI_math_matrix.h
    branches/soc-2012-swiss_cheese/source/blender/blenlib/intern/math_matrix.c

Modified: 
branches/soc-2012-swiss_cheese/source/blender/blenlib/BLI_math_matrix.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenlib/BLI_math_matrix.h     
2012-08-07 16:09:42 UTC (rev 49661)
+++ branches/soc-2012-swiss_cheese/source/blender/blenlib/BLI_math_matrix.h     
2012-08-07 16:23:31 UTC (rev 49662)
@@ -67,6 +67,7 @@
 void sub_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
 void sub_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
 void mult_m4_m4m4_q(float m1[4][4], float m3[4][4], float m2[4][4]);
+void mult_m4_m3m4_q(float m1[4][4], float m3[4][4], float m2[3][3]);
 
 void mul_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
 void mul_m4_m3m4(float R[4][4], float A[3][3], float B[4][4]);
@@ -85,6 +86,8 @@
 
 void mul_m4_v3(float M[4][4], float r[3]);
 void mul_v3_m4v3(float r[3], float M[4][4], const float v[3]);
+void mul_v4_m4v3(float r[4], float M[4][4], const float v[3]);
+void mul_v3_m4v3_q(float r[3], float M[4][4], const float v[3]);
 void mul_mat3_m4_v3(float M[4][4], float r[3]);
 void mul_m4_v4(float M[4][4], float r[4]);
 void mul_v4_m4v4(float r[4], float M[4][4], float v[4]);
@@ -160,6 +163,7 @@
 
 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_m4_right(float mat[4][4], const char axis);
 
 
 void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[][3]);

Modified: 
branches/soc-2012-swiss_cheese/source/blender/blenlib/intern/math_matrix.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenlib/intern/math_matrix.c  
2012-08-07 16:09:42 UTC (rev 49661)
+++ branches/soc-2012-swiss_cheese/source/blender/blenlib/intern/math_matrix.c  
2012-08-07 16:23:31 UTC (rev 49662)
@@ -167,6 +167,31 @@
 
 }
 
+void mult_m4_m3m4_q(float m1[][4], float m3[][4], float m2[][3])
+{
+       /* matrix product: m1[j][k] = m2[j][i].m3[i][k] */
+       m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] + m2[0][2] * 
m3[2][0];
+       m1[0][1] = m2[0][0] * m3[0][1] + m2[0][1] * m3[1][1] + m2[0][2] * 
m3[2][1];
+       m1[0][2] = m2[0][0] * m3[0][2] + m2[0][1] * m3[1][2] + m2[0][2] * 
m3[2][2];
+       m1[0][3] = m2[0][0] * m3[0][3] + m2[0][1] * m3[1][3] + m2[0][2] * 
m3[2][3];
+
+       m1[1][0] = m2[1][0] * m3[0][0] + m2[1][1] * m3[1][0] + m2[1][2] * 
m3[2][0];
+       m1[1][1] = m2[1][0] * m3[0][1] + m2[1][1] * m3[1][1] + m2[1][2] * 
m3[2][1];
+       m1[1][2] = m2[1][0] * m3[0][2] + m2[1][1] * m3[1][2] + m2[1][2] * 
m3[2][2];
+       m1[1][3] = m2[1][0] * m3[0][3] + m2[1][1] * m3[1][3] + m2[1][2] * 
m3[2][3];
+
+       m1[2][0] = m2[2][0] * m3[0][0] + m2[2][1] * m3[1][0] + m2[2][2] * 
m3[2][0];
+       m1[2][1] = m2[2][0] * m3[0][1] + m2[2][1] * m3[1][1] + m2[2][2] * 
m3[2][1];
+       m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * 
m3[2][2];
+       m1[2][3] = m2[2][0] * m3[0][3] + m2[2][1] * m3[1][3] + m2[2][2] * 
m3[2][3];
+
+       m1[3][0] = m3[3][0];
+       m1[3][1] = m3[3][1];
+       m1[3][2] = m3[3][2];
+       m1[3][3] = m3[3][3];
+
+}
+
 void mult_m4_m4m4(float m1[][4], float m3_[][4], float m2_[][4])
 {
        float m2[4][4], m3[4][4];
@@ -339,6 +364,23 @@
        in[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2];
 }
 
+
+void mul_v4_m4v3(float out[4], float mat[][4], const float vec[3])
+{
+       out[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] + mat[2][0] * vec[2] + 
mat[3][0];
+       out[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] + mat[2][1] * vec[2] + 
mat[3][1];
+       out[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] + mat[2][2] * vec[2] + 
mat[3][2];
+       out[3] = vec[0] * mat[0][3] + vec[1] * mat[1][3] + mat[2][3] * vec[2] + 
mat[3][3];
+}
+
+void mul_v3_m4v3_q(float out[3], float mat[][4], const float vec[3])
+{
+       out[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] + mat[2][0] * vec[2] + 
mat[3][0];
+       out[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] + mat[2][1] * vec[2] + 
mat[3][1];
+       out[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] + mat[2][2] * vec[2] + 
mat[3][2];
+
+}
+
 /* same as mul_m4_v3() but doesnt apply translation component */
 void mul_mat3_m4_v3(float mat[][4], float vec[3])
 {
@@ -1225,6 +1267,61 @@
        }
 }
 
+void rotate_m4_right(float mat[][4], const char axis)
+{
+#define COORD(x,y) (4*x + y)
+       const static char mrotx[]  = {1, 2};
+       const static char mrotxn[] = {2, 1};
+
+       const static char mroty[]  = {2, 0};
+       const static char mrotyn[] = {0, 2};
+
+       const static char mrotz[]  = {0, 1};
+       const static char mrotzn[] = {1, 0};
+
+#undef COORD
+
+       const char * rotmat;
+       float tmpf;
+       int i;
+
+
+       switch(axis)
+       {
+               case 'X':
+                       rotmat = mrotx;
+                       break;
+               case (char)-'X':
+                       rotmat = mrotxn;
+                       break;
+               case 'Y':
+                       rotmat = mroty;
+                       break;
+               case (char)-'Y':
+                       rotmat = mrotyn;
+                       break;
+               case 'Z':
+                       rotmat = mrotz;
+                       break;
+               case (char)-'Z':
+                       rotmat = mrotzn;
+                       break;
+               default:
+                       BLI_assert(0);
+
+       }
+
+       for(i=0; i<3; i++)
+       {
+               tmpf = mat[rotmat[1]][i];
+               mat[rotmat[1]][i] = -1.0*mat[rotmat[0]][i];
+               mat[rotmat[0]][i] = tmpf;
+
+       }
+
+}
+
+
 void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], const float 
srcweight)
 {
        float srot[3][3], drot[3][3];

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to