[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24881] branches/sculpt25/source/blender/ blenlib: Sculpt: math lib functions
Brecht Van Lommel
brecht at blender.org
Wed Nov 25 13:04:11 CET 2009
Revision: 24881
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24881
Author: blendix
Date: 2009-11-25 13:04:11 +0100 (Wed, 25 Nov 2009)
Log Message:
-----------
Sculpt: math lib functions
* swap v2/v3
* multiply-and-add (madd) v3
* inline v3 short/float conversion
Modified Paths:
--------------
branches/sculpt25/source/blender/blenlib/BLI_math_matrix.h
branches/sculpt25/source/blender/blenlib/BLI_math_vector.h
branches/sculpt25/source/blender/blenlib/intern/math_matrix.c
branches/sculpt25/source/blender/blenlib/intern/math_vector.c
branches/sculpt25/source/blender/blenlib/intern/math_vector_inline.c
Modified: branches/sculpt25/source/blender/blenlib/BLI_math_matrix.h
===================================================================
--- branches/sculpt25/source/blender/blenlib/BLI_math_matrix.h 2009-11-25 12:00:31 UTC (rev 24880)
+++ branches/sculpt25/source/blender/blenlib/BLI_math_matrix.h 2009-11-25 12:04:11 UTC (rev 24881)
@@ -82,6 +82,7 @@
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]);
Modified: branches/sculpt25/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- branches/sculpt25/source/blender/blenlib/BLI_math_vector.h 2009-11-25 12:00:31 UTC (rev 24880)
+++ branches/sculpt25/source/blender/blenlib/BLI_math_vector.h 2009-11-25 12:04:11 UTC (rev 24881)
@@ -54,6 +54,9 @@
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_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_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]);
Modified: branches/sculpt25/source/blender/blenlib/intern/math_matrix.c
===================================================================
--- branches/sculpt25/source/blender/blenlib/intern/math_matrix.c 2009-11-25 12:00:31 UTC (rev 24880)
+++ branches/sculpt25/source/blender/blenlib/intern/math_matrix.c 2009-11-25 12:04:11 UTC (rev 24881)
@@ -338,15 +338,19 @@
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)
Modified: branches/sculpt25/source/blender/blenlib/intern/math_vector.c
===================================================================
--- branches/sculpt25/source/blender/blenlib/intern/math_vector.c 2009-11-25 12:00:31 UTC (rev 24880)
+++ branches/sculpt25/source/blender/blenlib/intern/math_vector.c 2009-11-25 12:04:11 UTC (rev 24881)
@@ -283,20 +283,6 @@
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];
Modified: branches/sculpt25/source/blender/blenlib/intern/math_vector_inline.c
===================================================================
--- branches/sculpt25/source/blender/blenlib/intern/math_vector_inline.c 2009-11-25 12:00:31 UTC (rev 24880)
+++ branches/sculpt25/source/blender/blenlib/intern/math_vector_inline.c 2009-11-25 12:04:11 UTC (rev 24881)
@@ -58,6 +58,19 @@
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 @@
{
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 @@
{
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 @@
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 @@
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 */
More information about the Bf-blender-cvs
mailing list