diff options
-rw-r--r-- | source/blender/blenlib/BLI_math_matrix.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 12 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 18 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 14 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 59 |
5 files changed, 79 insertions, 25 deletions
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 53476e4d03c..5667fb79332 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -82,6 +82,7 @@ void mul_m4_v4(float M[4][4], float r[3]); void mul_project_m4_v4(float M[4][4], float r[3]); void mul_m3_v3(float M[3][3], float r[3]); +void mul_v3_m3v3(float r[3], float M[3][3], float a[3]); void mul_transposed_m3_v3(float M[3][3], float r[3]); void mul_m3_v3_double(float M[3][3], double r[3]); diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 26602353425..d1d88b29630 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -54,6 +54,9 @@ MINLINE void zero_v3(float r[3]); MINLINE void copy_v2_v2(float r[2], float a[2]); MINLINE void copy_v3_v3(float r[3], float a[3]); +MINLINE void swap_v2_v2(float a[2], float b[2]); +MINLINE void swap_v3_v3(float a[3], float b[3]); + /********************************* Arithmetic ********************************/ MINLINE void add_v2_v2(float r[2], float a[2]); @@ -72,6 +75,11 @@ MINLINE void mul_v3_v3fl(float r[3], float a[3], float f); MINLINE void mul_v3_v3(float r[3], float a[3]); MINLINE void mul_v3_v3v3(float r[3], float a[3], float b[3]); +MINLINE void madd_v3_v3fl(float r[3], float a[3], float f); +MINLINE void madd_v3_v3v3(float r[3], float a[3], float b[3]); +MINLINE void madd_v3_v3v3fl(float r[3], float a[3], float b[3], float f); +MINLINE void madd_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]); + MINLINE void negate_v3(float r[3]); MINLINE void negate_v3_v3(float r[3], float a[3]); @@ -136,8 +144,8 @@ void print_v2(char *str, float a[2]); void print_v3(char *str, float a[3]); void print_v4(char *str, float a[4]); -void normal_short_to_float_v3(float r[3], short n[3]); -void normal_float_to_short_v3(short r[3], float n[3]); +MINLINE void normal_short_to_float_v3(float r[3], short n[3]); +MINLINE void normal_float_to_short_v3(short r[3], float n[3]); void minmax_v3_v3v3(float r[3], float min[3], float max[3]); diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index edab1cc2440..47b99bce8ab 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -338,15 +338,19 @@ void mul_m4_v4(float mat[][4], float *vec) vec[3]=x*mat[0][3] + y*mat[1][3] + z*mat[2][3] + mat[3][3]*vec[3]; } -void mul_m3_v3(float mat[][3], float *vec) +void mul_v3_m3v3(float r[3], float M[3][3], float a[3]) { - float x,y; + r[0]= M[0][0]*a[0] + M[1][0]*a[1] + M[2][0]*a[2]; + r[1]= M[0][1]*a[0] + M[1][1]*a[1] + M[2][1]*a[2]; + r[2]= M[0][2]*a[0] + M[1][2]*a[1] + M[2][2]*a[2]; +} - x=vec[0]; - y=vec[1]; - vec[0]= x*mat[0][0] + y*mat[1][0] + mat[2][0]*vec[2]; - vec[1]= x*mat[0][1] + y*mat[1][1] + mat[2][1]*vec[2]; - vec[2]= x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2]; +void mul_m3_v3(float M[3][3], float r[3]) +{ + float tmp[3]; + + mul_v3_m3v3(tmp, M, r); + copy_v3_v3(r, tmp); } void mul_transposed_m3_v3(float mat[][3], float *vec) diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 8d36c3ac524..366380b5276 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -283,20 +283,6 @@ void print_v4(char *str, float v[4]) printf("%s: %.3f %.3f %.3f %.3f\n", str, v[0], v[1], v[2], v[3]); } -void normal_short_to_float_v3(float *out, short *in) -{ - out[0] = in[0]*(1.0f/32767.0f); - out[1] = in[1]*(1.0f/32767.0f); - out[2] = in[2]*(1.0f/32767.0f); -} - -void normal_float_to_short_v3(short *out, float *in) -{ - out[0] = (short)(in[0]*32767.0f); - out[1] = (short)(in[1]*32767.0f); - out[2] = (short)(in[2]*32767.0f); -} - void minmax_v3_v3v3(float *min, float *max, float *vec) { if(min[0]>vec[0]) min[0]= vec[0]; diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 6830f44ae1b..cb629312712 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -58,6 +58,19 @@ MINLINE void copy_v3_v3(float r[3], float a[3]) r[2]= a[2]; } +MINLINE void swap_v2_v2(float a[2], float b[2]) +{ + SWAP(float, a[0], b[0]); + SWAP(float, a[1], b[1]); +} + +MINLINE void swap_v3_v3(float a[3], float b[3]) +{ + SWAP(float, a[0], b[0]); + SWAP(float, a[1], b[1]); + SWAP(float, a[2], b[2]); +} + /********************************* Arithmetic ********************************/ MINLINE void add_v2_v2(float *r, float *a) @@ -76,7 +89,7 @@ MINLINE void add_v3_v3(float *r, float *a) { r[0] += a[0]; r[1] += a[1]; - r[1] += a[1]; + r[2] += a[2]; } MINLINE void add_v3_v3v3(float *r, float *a, float *b) @@ -102,7 +115,7 @@ MINLINE void sub_v3_v3(float *r, float *a) { r[0] -= a[0]; r[1] -= a[1]; - r[1] -= a[1]; + r[2] -= a[2]; } MINLINE void sub_v3_v3v3(float *r, float *a, float *b) @@ -139,6 +152,34 @@ MINLINE void mul_v3_v3(float r[3], float a[3]) r[2] *= a[2]; } +MINLINE void madd_v3_v3fl(float r[3], float a[3], float f) +{ + r[0] += a[0]*f; + r[1] += a[1]*f; + r[2] += a[2]*f; +} + +MINLINE void madd_v3_v3v3(float r[3], float a[3], float b[3]) +{ + r[0] += a[0]*b[0]; + r[1] += a[1]*b[1]; + r[2] += a[2]*b[2]; +} + +MINLINE void madd_v3_v3v3fl(float r[3], float a[3], float b[3], float f) +{ + r[0] = a[0] + b[0]*f; + r[1] = a[1] + b[1]*f; + r[2] = a[2] + b[2]*f; +} + +MINLINE void madd_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]) +{ + r[0] = a[0] + b[0]*c[0]; + r[1] = a[1] + b[1]*c[1]; + r[2] = a[2] + b[2]*c[2]; +} + MINLINE void mul_v3_v3v3(float *v, float *v1, float *v2) { v[0] = v1[0] * v2[0]; @@ -254,5 +295,19 @@ MINLINE float normalize_v3(float n[3]) return d; } +MINLINE void normal_short_to_float_v3(float *out, short *in) +{ + out[0] = in[0]*(1.0f/32767.0f); + out[1] = in[1]*(1.0f/32767.0f); + out[2] = in[2]*(1.0f/32767.0f); +} + +MINLINE void normal_float_to_short_v3(short *out, float *in) +{ + out[0] = (short)(in[0]*32767.0f); + out[1] = (short)(in[1]*32767.0f); + out[2] = (short)(in[2]*32767.0f); +} + #endif /* BLI_MATH_VECTOR_INLINE */ |