diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-07-20 08:01:42 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-07-20 08:01:42 +0400 |
commit | 7c7b7302d33b9a43f5436589a726bc733be91a33 (patch) | |
tree | f7151512b3ba95ead50f991daf1ec29ca5b7f811 /source/blender/blenlib | |
parent | 3ca78a40e8b9eb7fa7c01404590ca2592a0b390d (diff) |
Math Lib: use variable length args for mul_serie_m3,m4 (instead of trailing NULL's)
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_matrix.h | 35 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 207 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 2 |
3 files changed, 172 insertions, 72 deletions
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 49183934412..1c1e4e7eb3f 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -34,6 +34,8 @@ extern "C" { #endif +#include "BLI_compiler_attrs.h" + /********************************* Init **************************************/ void zero_m3(float R[3][3]); @@ -67,12 +69,33 @@ void mul_m4_m4m3(float R[4][4], float A[4][4], float B[3][3]); void mul_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]); void mul_m3_m3m4(float R[3][3], float A[4][4], float B[3][3]); -void mul_serie_m3(float R[3][3], - float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3], - float M5[3][3], float M6[3][3], float M7[3][3], float M8[3][3]); -void mul_serie_m4(float R[4][4], - float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4], - float M5[4][4], float M6[4][4], float M7[4][4], float M8[4][4]); +/* mul_serie_m3 */ +void _va_mul_serie_m3_3(float R[3][3], float M1[3][3], float M2[3][3]) ATTR_NONNULL(); +void _va_mul_serie_m3_4(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3]) ATTR_NONNULL(); +void _va_mul_serie_m3_5(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3]) ATTR_NONNULL(); +void _va_mul_serie_m3_6(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3], + float M5[3][3]) ATTR_NONNULL(); +void _va_mul_serie_m3_7(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3], + float M5[3][3], float M6[3][3]) ATTR_NONNULL(); +void _va_mul_serie_m3_8(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3], + float M5[3][3], float M6[3][3], float M7[3][3]) ATTR_NONNULL(); +void _va_mul_serie_m3_9(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3], + float M5[3][3], float M6[3][3], float M7[3][3], float M8[3][3]) ATTR_NONNULL(); +/* mul_serie_m4 */ +void _va_mul_serie_m4_3(float R[4][4], float M1[4][4], float M2[4][4]) ATTR_NONNULL(); +void _va_mul_serie_m4_4(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4]) ATTR_NONNULL(); +void _va_mul_serie_m4_5(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4]) ATTR_NONNULL(); +void _va_mul_serie_m4_6(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4], + float M5[4][4]) ATTR_NONNULL(); +void _va_mul_serie_m4_7(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4], + float M5[4][4], float M6[4][4]) ATTR_NONNULL(); +void _va_mul_serie_m4_8(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4], + float M5[4][4], float M6[4][4], float M7[4][4]) ATTR_NONNULL(); +void _va_mul_serie_m4_9(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4], + float M5[4][4], float M6[4][4], float M7[4][4], float M8[4][4]) ATTR_NONNULL(); + +#define mul_serie_m3(...) VA_NARGS_CALL_OVERLOAD(_va_mul_serie_m3_, __VA_ARGS__) +#define mul_serie_m4(...) VA_NARGS_CALL_OVERLOAD(_va_mul_serie_m4_, __VA_ARGS__) 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]); diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 7fc30e3112b..74b0df1c6c0 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -274,71 +274,148 @@ void mul_m4_m3m4(float m1[4][4], float m3_[3][3], float m2_[4][4]) m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2]; } -void mul_serie_m3(float answ[3][3], - float m1[3][3], float m2[3][3], float m3[3][3], - float m4[3][3], float m5[3][3], float m6[3][3], - float m7[3][3], float m8[3][3]) -{ - float temp[3][3]; - - if (m1 == NULL || m2 == NULL) return; - - mul_m3_m3m3(answ, m2, m1); - if (m3) { - mul_m3_m3m3(temp, m3, answ); - if (m4) { - mul_m3_m3m3(answ, m4, temp); - if (m5) { - mul_m3_m3m3(temp, m5, answ); - if (m6) { - mul_m3_m3m3(answ, m6, temp); - if (m7) { - mul_m3_m3m3(temp, m7, answ); - if (m8) { - mul_m3_m3m3(answ, m8, temp); - } - else copy_m3_m3(answ, temp); - } - } - else copy_m3_m3(answ, temp); - } - } - else copy_m3_m3(answ, temp); - } -} -void mul_serie_m4(float answ[4][4], float m1[4][4], - float m2[4][4], float m3[4][4], float m4[4][4], - float m5[4][4], float m6[4][4], float m7[4][4], - float m8[4][4]) -{ - float temp[4][4]; - - if (m1 == NULL || m2 == NULL) return; - - mul_m4_m4m4(answ, m1, m2); - if (m3) { - mul_m4_m4m4(temp, answ, m3); - if (m4) { - mul_m4_m4m4(answ, temp, m4); - if (m5) { - mul_m4_m4m4(temp, answ, m5); - if (m6) { - mul_m4_m4m4(answ, temp, m6); - if (m7) { - mul_m4_m4m4(temp, answ, m7); - if (m8) { - mul_m4_m4m4(answ, temp, m8); - } - else copy_m4_m4(answ, temp); - } - } - else copy_m4_m4(answ, temp); - } - } - else copy_m4_m4(answ, temp); - } -} +/** \name Macro helpers for: mul_serie_m3 + * \{ */ +void _va_mul_serie_m3_3( + float r[3][3], + float m1[3][3], float m2[3][3]) +{ + mul_m3_m3m3(r, m2, m1); +} +void _va_mul_serie_m3_4( + float r[3][3], + float m1[3][3], float m2[3][3], float m3[3][3]) +{ + mul_m3_m3m3(r, m2, m1); + mul_m3_m3m3(r, m3, r); +} +void _va_mul_serie_m3_5( + float r[3][3], + float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3]) +{ + mul_m3_m3m3(r, m2, m1); + mul_m3_m3m3(r, m3, r); + mul_m3_m3m3(r, m4, r); +} +void _va_mul_serie_m3_6( + float r[3][3], + float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3], + float m5[3][3]) +{ + mul_m3_m3m3(r, m2, m1); + mul_m3_m3m3(r, m3, r); + mul_m3_m3m3(r, m4, r); + mul_m3_m3m3(r, m5, r); +} +void _va_mul_serie_m3_7( + float r[3][3], + float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3], + float m5[3][3], float m6[3][3]) +{ + mul_m3_m3m3(r, m2, m1); + mul_m3_m3m3(r, m3, r); + mul_m3_m3m3(r, m4, r); + mul_m3_m3m3(r, m5, r); + mul_m3_m3m3(r, m6, r); +} +void _va_mul_serie_m3_8( + float r[3][3], + float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3], + float m5[3][3], float m6[3][3], float m7[3][3]) +{ + mul_m3_m3m3(r, m2, m1); + mul_m3_m3m3(r, m3, r); + mul_m3_m3m3(r, m4, r); + mul_m3_m3m3(r, m5, r); + mul_m3_m3m3(r, m6, r); + mul_m3_m3m3(r, m7, r); +} +void _va_mul_serie_m3_9( + float r[3][3], + float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3], + float m5[3][3], float m6[3][3], float m7[3][3], float m8[3][3]) +{ + mul_m3_m3m3(r, m2, m1); + mul_m3_m3m3(r, m3, r); + mul_m3_m3m3(r, m4, r); + mul_m3_m3m3(r, m5, r); + mul_m3_m3m3(r, m6, r); + mul_m3_m3m3(r, m7, r); + mul_m3_m3m3(r, m8, r); +} +/** \} */ + +/** \name Macro helpers for: mul_serie_m4 + * \{ */ +void _va_mul_serie_m4_3( + float r[4][4], + float m1[4][4], float m2[4][4]) +{ + mul_m4_m4m4(r, m2, m1); +} +void _va_mul_serie_m4_4( + float r[4][4], + float m1[4][4], float m2[4][4], float m3[4][4]) +{ + mul_m4_m4m4(r, m2, m1); + mul_m4_m4m4(r, m3, r); +} +void _va_mul_serie_m4_5( + float r[4][4], + float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4]) +{ + mul_m4_m4m4(r, m2, m1); + mul_m4_m4m4(r, m3, r); + mul_m4_m4m4(r, m4, r); +} +void _va_mul_serie_m4_6( + float r[4][4], + float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4], + float m5[4][4]) +{ + mul_m4_m4m4(r, m2, m1); + mul_m4_m4m4(r, m3, r); + mul_m4_m4m4(r, m4, r); + mul_m4_m4m4(r, m5, r); +} +void _va_mul_serie_m4_7( + float r[4][4], + float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4], + float m5[4][4], float m6[4][4]) +{ + mul_m4_m4m4(r, m2, m1); + mul_m4_m4m4(r, m3, r); + mul_m4_m4m4(r, m4, r); + mul_m4_m4m4(r, m5, r); + mul_m4_m4m4(r, m6, r); +} +void _va_mul_serie_m4_8( + float r[4][4], + float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4], + float m5[4][4], float m6[4][4], float m7[4][4]) +{ + mul_m4_m4m4(r, m2, m1); + mul_m4_m4m4(r, m3, r); + mul_m4_m4m4(r, m4, r); + mul_m4_m4m4(r, m5, r); + mul_m4_m4m4(r, m6, r); + mul_m4_m4m4(r, m7, r); +} +void _va_mul_serie_m4_9( + float r[4][4], + float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4], + float m5[4][4], float m6[4][4], float m7[4][4], float m8[4][4]) +{ + mul_m4_m4m4(r, m2, m1); + mul_m4_m4m4(r, m3, r); + mul_m4_m4m4(r, m4, r); + mul_m4_m4m4(r, m5, r); + mul_m4_m4m4(r, m6, r); + mul_m4_m4m4(r, m7, r); + mul_m4_m4m4(r, m8, r); +} +/** \} */ void mul_v2_m3v2(float r[2], float m[3][3], float v[2]) { @@ -2115,7 +2192,7 @@ void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon) transpose_m4(V); - mul_serie_m4(Ainv, U, Wm, V, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(Ainv, U, Wm, V); } void pseudoinverse_m3_m3(float Ainv[3][3], float A[3][3], float epsilon) diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index dce2e9d54e3..b1db6ef9f2b 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -1606,7 +1606,7 @@ void mat4_to_dquat(DualQuat *dq, float basemat[4][4], float mat[4][4]) mul_m4_m4m4(S, baseRinv, baseRS); /* set scaling part */ - mul_serie_m4(dq->scale, basemat, S, baseinv, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(dq->scale, basemat, S, baseinv); dq->scale_weight = 1.0f; } else { |