[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54018] trunk/blender/source/blender/ blenlib: math: Add functions to decompose transformation matrices
Sergej Reich
sergej.reich at googlemail.com
Wed Jan 23 06:56:07 CET 2013
Revision: 54018
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54018
Author: sergof
Date: 2013-01-23 05:56:05 +0000 (Wed, 23 Jan 2013)
Log Message:
-----------
math: Add functions to decompose transformation matrices
mat4_decompose() is similar to mat4_to_loc_rot_size() but returns
rotation as quaternion.
mat4_to_loc_quat() just returns location and rotation without size.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_math_matrix.h
trunk/blender/source/blender/blenlib/intern/math_matrix.c
Modified: trunk/blender/source/blender/blenlib/BLI_math_matrix.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_matrix.h 2013-01-23 05:42:45 UTC (rev 54017)
+++ trunk/blender/source/blender/blenlib/BLI_math_matrix.h 2013-01-23 05:56:05 UTC (rev 54018)
@@ -173,6 +173,8 @@
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]);
+void mat4_to_loc_quat(float loc[3], float quat[4], float wmat[4][4]);
+void mat4_decompose(float loc[3], float quat[4], float size[3], float wmat[4][4]);
void loc_eul_size_to_mat4(float R[4][4],
const float loc[3], const float eul[3], const float size[3]);
Modified: trunk/blender/source/blender/blenlib/intern/math_matrix.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_matrix.c 2013-01-23 05:42:45 UTC (rev 54017)
+++ trunk/blender/source/blender/blenlib/intern/math_matrix.c 2013-01-23 05:56:05 UTC (rev 54018)
@@ -1212,6 +1212,33 @@
copy_v3_v3(loc, wmat[3]);
}
+void mat4_to_loc_quat(float loc[3], float quat[4], float wmat[4][4])
+{
+ float mat3[3][3];
+ float mat3_n[3][3]; /* normalized mat3 */
+
+ copy_m3_m4(mat3, wmat);
+ normalize_m3_m3(mat3_n, mat3);
+
+ /* 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]);
+ }
+
+ mat3_to_quat(quat, mat3_n);
+ copy_v3_v3(loc, wmat[3]);
+}
+
+void mat4_decompose(float loc[3], float quat[4], float size[3], float wmat[4][4])
+{
+ float rot[3][3];
+ mat4_to_loc_rot_size(loc, rot, size, wmat);
+ mat3_to_quat(quat, rot);
+}
+
void scale_m3_fl(float m[3][3], float scale)
{
m[0][0] = m[1][1] = m[2][2] = scale;
More information about the Bf-blender-cvs
mailing list