Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-11-10 22:13:05 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-11-10 22:13:05 +0300
commit385875632d7953080375ef4bf74f894c1053fc4b (patch)
tree8f7d69622d67953cfc413f0d5b2e87ef013042d7 /source/blender/blenlib/intern/math_vector.c
parentd611dd373558814ea2fc21bcd5418404f1c77a4d (diff)
Math Lib
* Fix remaining issues before conversion. * Inline various vector functions, currently enabled for all platforms. I expect this to work in GCC/MSVC at least, if other platforms don't support it, #ifdef's can be added.
Diffstat (limited to 'source/blender/blenlib/intern/math_vector.c')
-rw-r--r--source/blender/blenlib/intern/math_vector.c245
1 files changed, 10 insertions, 235 deletions
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 8336b529da3..8d36c3ac524 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -32,234 +32,11 @@
#include "BLI_math.h"
-/********************************** Init *************************************/
+//******************************* Interpolation *******************************/
-void zero_v2(float r[2])
+void interp_v2_v2v2(float *target, float *a, float *b, float t)
{
- r[0]= 0.0f;
- r[1]= 0.0f;
-}
-
-void zero_v3(float r[3])
-{
- r[0]= 0.0f;
- r[1]= 0.0f;
- r[2]= 0.0f;
-}
-
-void copy_v2_v2(float r[2], float a[2])
-{
- r[0]= a[0];
- r[1]= a[1];
-}
-
-void copy_v3_v3(float r[3], float a[3])
-{
- r[0]= a[0];
- r[1]= a[1];
- r[2]= a[2];
-}
-
-/********************************* Arithmetic ********************************/
-
-void add_v2_v2(float *r, float *a)
-{
- r[0] += a[0];
- r[1] += a[1];
-}
-
-void add_v2_v2v2(float *r, float *a, float *b)
-{
- r[0]= a[0] + b[0];
- r[1]= a[1] + b[1];
-}
-
-void add_v3_v3(float *r, float *a)
-{
- r[0] += a[0];
- r[1] += a[1];
- r[1] += a[1];
-}
-
-void add_v3_v3v3(float *r, float *a, float *b)
-{
- r[0]= a[0] + b[0];
- r[1]= a[1] + b[1];
- r[2]= a[2] + b[2];
-}
-
-void sub_v2_v2(float *r, float *a)
-{
- r[0] -= a[0];
- r[1] -= a[1];
-}
-
-void sub_v2_v2v2(float *r, float *a, float *b)
-{
- r[0]= a[0] - b[0];
- r[1]= a[1] - b[1];
-}
-
-void sub_v3_v3(float *r, float *a)
-{
- r[0] -= a[0];
- r[1] -= a[1];
- r[1] -= a[1];
-}
-
-void sub_v3_v3v3(float *r, float *a, float *b)
-{
- r[0]= a[0] - b[0];
- r[1]= a[1] - b[1];
- r[2]= a[2] - b[2];
-}
-
-void mul_v2_fl(float *v1, float f)
-{
- v1[0]*= f;
- v1[1]*= f;
-}
-
-void mul_v3_fl(float r[3], float f)
-{
- r[0] *= f;
- r[1] *= f;
- r[2] *= f;
-}
-
-void mul_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;
-}
-
-void mul_v3_v3(float r[3], float a[3])
-{
- r[0] *= a[0];
- r[1] *= a[1];
- r[2] *= a[2];
-}
-
-void mul_v3_v3v3(float *v, float *v1, float *v2)
-{
- v[0] = v1[0] * v2[0];
- v[1] = v1[1] * v2[1];
- v[2] = v1[2] * v2[2];
-}
-
-void negate_v3(float r[3])
-{
- r[0]= -r[0];
- r[1]= -r[1];
- r[2]= -r[2];
-}
-
-void negate_v3_v3(float r[3], float a[3])
-{
- r[0]= -a[0];
- r[1]= -a[1];
- r[2]= -a[2];
-}
-
-float dot_v2v2(float *a, float *b)
-{
- return a[0]*b[0] + a[1]*b[1];
-}
-
-float dot_v3v3(float a[3], float b[3])
-{
- return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
-}
-
-void cross_v3_v3v3(float r[3], float a[3], float b[3])
-{
- r[0]= a[1]*b[2] - a[2]*b[1];
- r[1]= a[2]*b[0] - a[0]*b[2];
- r[2]= a[0]*b[1] - a[1]*b[0];
-}
-
-void star_m3_v3(float mat[][3], float *vec)
-{
- mat[0][0]= mat[1][1]= mat[2][2]= 0.0;
- mat[0][1]= -vec[2];
- mat[0][2]= vec[1];
- mat[1][0]= vec[2];
- mat[1][2]= -vec[0];
- mat[2][0]= -vec[1];
- mat[2][1]= vec[0];
-
-}
-
-/*********************************** Length **********************************/
-
-float len_v2(float *v)
-{
- return (float)sqrt(v[0]*v[0] + v[1]*v[1]);
-}
-
-float len_v2v2(float *v1, float *v2)
-{
- float x, y;
-
- x = v1[0]-v2[0];
- y = v1[1]-v2[1];
- return (float)sqrt(x*x+y*y);
-}
-
-float len_v3(float a[3])
-{
- return sqrtf(dot_v3v3(a, a));
-}
-
-float len_v3v3(float a[3], float b[3])
-{
- float d[3];
-
- sub_v3_v3v3(d, b, a);
- return len_v3(d);
-}
-
-float normalize_v2(float n[2])
-{
- float d;
-
- d= n[0]*n[0]+n[1]*n[1];
-
- if(d>1.0e-35f) {
- d= (float)sqrt(d);
- n[0]/=d;
- n[1]/=d;
- } else {
- n[0]=n[1]= 0.0f;
- d= 0.0f;
- }
- return d;
-}
-
-float normalize_v3(float n[3])
-{
- float d= dot_v3v3(n, n);
-
- /* a larger value causes normalize errors in a
- scaled down models with camera xtreme close */
- if(d > 1.0e-35f) {
- d= sqrtf(d);
- mul_v3_fl(n, 1.0f/d);
- }
- else {
- zero_v3(n);
- d= 0.0f;
- }
-
- return d;
-}
-
-/******************************* Interpolation *******************************/
-
-void interp_v2_v2v2(float *target, const float *a, const float *b, const float t)
-{
- const float s = 1.0f-t;
+ float s = 1.0f-t;
target[0]= s*a[0] + t*b[0];
target[1]= s*a[1] + t*b[1];
@@ -267,17 +44,15 @@ void interp_v2_v2v2(float *target, const float *a, const float *b, const float t
/* weight 3 2D vectors,
* 'w' must be unit length but is not a vector, just 3 weights */
-void interp_v2_v2v2v2(float p[2], const float v1[2], const float v2[2], const float v3[2], const float w[3])
+void interp_v2_v2v2v2(float p[2], float v1[2], float v2[2], float v3[2], float w[3])
{
p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
}
-
-
-void interp_v3_v3v3(float *target, const float *a, const float *b, const float t)
+void interp_v3_v3v3(float *target, float *a, float *b, float t)
{
- const float s = 1.0f-t;
+ float s = 1.0f-t;
target[0]= s*a[0] + t*b[0];
target[1]= s*a[1] + t*b[1];
@@ -286,7 +61,7 @@ void interp_v3_v3v3(float *target, const float *a, const float *b, const float t
/* weight 3 vectors,
* 'w' must be unit length but is not a vector, just 3 weights */
-void interp_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3])
+void interp_v3_v3v3v3(float p[3], float v1[3], float v2[3], float v3[3], float w[3])
{
p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
@@ -295,9 +70,9 @@ void interp_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const fl
void mid_v3_v3v3(float *v, float *v1, float *v2)
{
- v[0]= 0.5f*(v1[0]+ v2[0]);
- v[1]= 0.5f*(v1[1]+ v2[1]);
- v[2]= 0.5f*(v1[2]+ v2[2]);
+ v[0]= 0.5f*(v1[0] + v2[0]);
+ v[1]= 0.5f*(v1[1] + v2[1]);
+ v[2]= 0.5f*(v1[2] + v2[2]);
}
/********************************* Comparison ********************************/