diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-11-22 13:39:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-11-22 13:39:28 +0300 |
commit | f781780cc043bc26f70c89d1292215f0491d30dc (patch) | |
tree | 38925182938b35a3821c6e906693b1aeff8e138f /source/blender/blenlib | |
parent | 77dff3f9863638a5a95a1ee7e6fc2b0e9b3b8357 (diff) |
- blend_m3_m3m3 and blend_m4_m4m4 now support matrices with negative scales.
- python/mathutils api matrix.lerp(other, factor)
- new function mat3_to_rot_size(), like mat4_to_loc_rot_size but with no location.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_matrix.h | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 55 |
2 files changed, 36 insertions, 25 deletions
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 2144107a6cd..7b21c5f6df7 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -144,6 +144,8 @@ 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 mat3_to_rot_size(float rot[3][3], float size[3], float mat3[][3]); void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[][4]); void loc_eul_size_to_mat4(float R[4][4], @@ -155,8 +157,8 @@ void loc_quat_size_to_mat4(float R[4][4], void loc_axisangle_size_to_mat4(float R[4][4], const float loc[3], const float axis[4], const float angle, const float size[3]); -void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], float t); -void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], float t); +void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], const float t); +void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], const float t); int is_negative_m3(float mat[3][3]); int is_negative_m4(float mat[4][4]); diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index d2bd7a0a2b1..154eb746e5c 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -976,17 +976,15 @@ float mat4_to_scale(float mat[][4]) return mat3_to_scale(tmat); } -void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[][4]) + +void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3]) { - float mat3[3][3]; /* wmat -> 3x3 */ - float mat3_n[3][3]; /* wmat -> normalized, 3x3 */ - float imat3_n[3][3]; /* wmat -> normalized & inverted, 3x3 */ - /* location */ - copy_v3_v3(loc, wmat[3]); + float mat3_n[3][3]; /* mat3 -> normalized, 3x3 */ + float imat3_n[3][3]; /* mat3 -> normalized & inverted, 3x3 */ /* rotation & scale are linked, we need to create the mat's * for these together since they are related. */ - copy_m3_m4(mat3, wmat); + /* so scale doesnt interfear with rotation [#24291] */ /* note: this is a workaround for negative matrix not working for rotation conversion, FIXME */ normalize_m3_m3(mat3_n, mat3); @@ -1010,6 +1008,17 @@ void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wm size[2]= mat3[2][2]; } +void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[][4]) +{ + float mat3[3][3]; /* wmat -> 3x3 */ + + copy_m3_m4(mat3, wmat); + mat3_to_rot_size(rot, size, mat3); + + /* location */ + copy_v3_v3(loc, wmat[3]); +} + void scale_m3_fl(float m[][3], float scale) { m[0][0]= m[1][1]= m[2][2]= scale; @@ -1075,18 +1084,19 @@ void rotate_m4(float mat[][4], const char axis, const float angle) } } -void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], float srcweight) +void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], const float srcweight) { + float srot[3][3], drot[3][3]; float squat[4], dquat[4], fquat[4]; float ssize[3], dsize[3], fsize[3]; float rmat[3][3], smat[3][3]; - mat3_to_quat(dquat,dst); - mat3_to_size(dsize,dst); + mat3_to_rot_size(drot, dsize, dst); + mat3_to_rot_size(srot, ssize, src); + + mat3_to_quat(dquat, drot); + mat3_to_quat(squat, srot); - mat3_to_quat(squat,src); - mat3_to_size(ssize,src); - /* do blending */ interp_qt_qtqt(fquat, dquat, squat, srcweight); interp_v3_v3v3(fsize, dsize, ssize, srcweight); @@ -1097,20 +1107,19 @@ void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], float srcweig mul_m3_m3m3(out, rmat, smat); } -void blend_m4_m4m4(float out[][4], float dst[][4], float src[][4], float srcweight) +void blend_m4_m4m4(float out[][4], float dst[][4], float src[][4], const float srcweight) { + float sloc[3], dloc[3], floc[3]; + float srot[3][3], drot[3][3]; float squat[4], dquat[4], fquat[4]; float ssize[3], dsize[3], fsize[3]; - float sloc[3], dloc[3], floc[3]; - - mat4_to_quat(dquat,dst); - mat4_to_size(dsize,dst); - copy_v3_v3(dloc, dst[3]); - mat4_to_quat(squat,src); - mat4_to_size(ssize,src); - copy_v3_v3(sloc, src[3]); - + mat4_to_loc_rot_size(dloc, drot, dsize, dst); + mat4_to_loc_rot_size(sloc, srot, ssize, src); + + mat3_to_quat(dquat, drot); + mat3_to_quat(squat, srot); + /* do blending */ interp_v3_v3v3(floc, dloc, sloc, srcweight); interp_qt_qtqt(fquat, dquat, squat, srcweight); |