diff options
author | jacopo grandi <jak.sk8@hotmail.it> | 2021-02-18 14:14:23 +0100 |
---|---|---|
committer | jacopo grandi <jak.sk8@hotmail.it> | 2021-02-18 14:14:23 +0100 |
commit | 5f0fce4191309e9526b7109a0d87c092ce6a4193 (patch) | |
tree | 105257f876551814aa74a0760ec116bd1bf307a5 /umath | |
parent | ead78d51e662057467b79d3a65b20c4ba83cbf07 (diff) |
main
Diffstat (limited to 'umath')
-rw-r--r-- | umath/intersect.c | 7 | ||||
-rw-r--r-- | umath/intersect.h | 7 | ||||
-rw-r--r-- | umath/vec.c | 42 | ||||
-rw-r--r-- | umath/vec.h | 22 |
4 files changed, 78 insertions, 0 deletions
diff --git a/umath/intersect.c b/umath/intersect.c new file mode 100644 index 0000000..2d21389 --- /dev/null +++ b/umath/intersect.c @@ -0,0 +1,7 @@ +#include <intersect.h> + +int pt_rect (float p[], float a[], float b[]) { + if (p[0]>a[0] && p[0]<a[0]+b[0] && p[1]>a[1] && p[1]<a[1]+b[1]) + return 1; + return 0; +}
\ No newline at end of file diff --git a/umath/intersect.h b/umath/intersect.h new file mode 100644 index 0000000..d3e24ec --- /dev/null +++ b/umath/intersect.h @@ -0,0 +1,7 @@ +#ifndef INTERSECT_H +#define INTERSECT_H + +// rect is [a, b] = [pos, size] +int pt_rect (float p[], float a[], float b[]); + +#endif
\ No newline at end of file diff --git a/umath/vec.c b/umath/vec.c new file mode 100644 index 0000000..fe82f58 --- /dev/null +++ b/umath/vec.c @@ -0,0 +1,42 @@ +#include <vec.h> + +float vec2_add (float c[], float a[], float b[]) { + c[0]=a[0]+b[0]; c[1]=a[1]+b[1]; +} +float vec2_sub (float c[], float a[], float b[]) { + c[0]=a[0]-b[0]; c[1]=a[1]-b[1]; +} +float vec2_mul (float c[], float a[], float b) { + c[0]=a[0]*b; c[1]=a[1]*b; +} +float vec2_div (float c[], float a[], float b) { + c[0]=a[0]/b; c[1]=a[1]/b; +} + +float vec2_mag (float v[]) { return sqrt(v[0]*v[0]+v[1]*v[1]); } +float vec2_mag2 (float v[]) { return v[0]*v[0]+v[1]*v[1]; } + +void vec2_norm (float v[]) { + float m=vec2_mag(v); v[0]/=m; v[1]/=m; +} + + +float vec3_add (float c[], float a[], float b[]) { + c[0]=a[0]+b[0]; c[1]=a[1]+b[1]; c[2]=a[2]+b[2]; +} +float vec3_sub (float c[], float a[], float b[]) { + c[0]=a[0]-b[0]; c[1]=a[1]-b[1]; c[2]=a[2]-b[2]; +} +float vec3_mul (float c[], float a[], float b) { + c[0]=a[0]*b; c[1]=a[1]*b; c[2]=a[2]*b; +} +float vec3_div (float c[], float a[], float b) { + c[0]=a[0]/b; c[1]=a[1]/b; c[2]=a[2]/b; +} + +float vec3_mag (float v[]) { return sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]); } +float vec3_mag2 (float v[]) { return v[0]*v[0]+v[1]*v[1]+v[2]*v[2]; } + +void vec3_norm (float v[]) { + float m=vec3_mag(v); v[0]/=m; v[1]/=m; v[2]/=m; +}
\ No newline at end of file diff --git a/umath/vec.h b/umath/vec.h new file mode 100644 index 0000000..b87cae1 --- /dev/null +++ b/umath/vec.h @@ -0,0 +1,22 @@ +#ifndef VEC_H +#define VEC_H + +#include <math.h> + +float vec2_add (float c[], float a[], float b[]); +float vec2_sub (float c[], float a[], float b[]); +float vec2_mul (float c[], float a[], float b); +float vec2_div (float c[], float a[], float b); +float vec2_mag (float v[]); +float vec2_mag2 (float v[]); +void vec2_norm (float v[]); + +float vec3_add (float c[], float a[], float b[]); +float vec3_sub (float c[], float a[], float b[]); +float vec3_mul (float c[], float a[], float b); +float vec3_div (float c[], float a[], float b); +float vec3_mag (float v[]); +float vec3_mag2 (float v[]); +void vec3_norm (float v[]); + +#endif
\ No newline at end of file |