summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--maths.c23
-rw-r--r--maths.h3
2 files changed, 26 insertions, 0 deletions
diff --git a/maths.c b/maths.c
index 70b354e..a0c9ed5 100644
--- a/maths.c
+++ b/maths.c
@@ -282,6 +282,29 @@ int* vec_nrm(int* d, const int* a, int c) {
return d;
}
+int* vec_sub(int* d, const int* a, const int* b, int c) {
+ int i;
+ for (i = 0; i < c; i++) {
+ d[i] = a[i] - b[i];
+ }
+ return d;
+}
+
+int* vec_add(int* d, const int* a, const int* b, int c) {
+ int i;
+ for (i = 0; i < c; i++) {
+ d[i] = a[i] + b[i];
+ }
+ return d;
+}
+
+int vec_dist(int* w, const int* a, const int* b, int c) {
+ int dot;
+ vec_sub(w, a, b, c);
+ dot = vec_dot(w, w, c);
+ return fsqrt(dot);
+}
+
int* persp(int* v, int asp) {
v[2] += !v[2];
v[0] = ((v[0] << fbits) / v[2]);
diff --git a/maths.h b/maths.h
index e72f8fd..725e401 100644
--- a/maths.h
+++ b/maths.h
@@ -44,6 +44,9 @@ int* vec_ref(int* d, const int* i, const int* n, int c);
int vec_dot(const int* a, const int* b, int d);
int* vec_nrm(int* d, const int* a, int c);
int* vec_minise(int* d, const int* a, int c);
+int* vec_sub(int* d, const int* a, const int* b, int c);
+int* vec_add(int* d, const int* a, const int* b, int c);
+int vec_dist(int* w, const int* a, const int* b, int c);
int* persp(int* v, int asp);
int* ndc2clip(const int* c, int* p);