Math Lib: merging over some changes from the sculpt branch:

* swap v2/v3
* multiply-and-add (madd) v3
* inline v3 short/float conversion
* mul_v3_m3v3
This commit is contained in:
Brecht Van Lommel 2009-11-28 13:11:41 +00:00
parent 9094f2072e
commit b83751d8c2
6 changed files with 80 additions and 26 deletions

@ -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]);

@ -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]);
@ -137,8 +145,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]);

@ -1602,7 +1602,7 @@ void tangent_from_uv(float *uv1, float *uv2, float *uv3, float *co1, float *co2,
/* vector clouds */
/* void vcloud_estimate_transform(int list_size, float (*pos)[3], float *weight,float (*rpos)[3], float *rweight,
float lloc[3],float rloc[3],float lrot[3][3],float lscale[3][3])
/*
input
(
int list_size

@ -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)

@ -292,20 +292,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];

@ -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 */