summaryrefslogtreecommitdiff
path: root/3dmath.c
diff options
context:
space:
mode:
authorMorten Hustveit <morten.hustveit@gmail.com>2014-12-02 21:32:20 -0500
committerMorten Hustveit <morten.hustveit@gmail.com>2014-12-02 21:32:20 -0500
commit6cee50ceb0d153622b89fb813060419f5985857d (patch)
treea318e992398959fda8740a348bf5365a67827c27 /3dmath.c
parenta64a0186cdeee9189bd4db1303f82908cfe279a4 (diff)
Subtract the central sphere, and update the animation to match
Diffstat (limited to '3dmath.c')
-rw-r--r--3dmath.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/3dmath.c b/3dmath.c
index 9e7f7a1..5bc1861 100644
--- a/3dmath.c
+++ b/3dmath.c
@@ -2,8 +2,6 @@
#include <math.h>
-#define POW2(x) ((x) * (x))
-
float
dot(const float x[3], const float y[3]) {
return x[0] * y[0] + x[1] * y[1] + x[2] * y[2];
@@ -21,7 +19,7 @@ normalize(float x[3]) {
float
sphere_intersect(float* restrict y, float* restrict r,
const float* restrict s, const float* restrict d,
- const float* restrict c, float R) {
+ const float* restrict c, float R, int invert) {
int i;
float D, n[3], t, v[3];
@@ -33,7 +31,10 @@ sphere_intersect(float* restrict y, float* restrict r,
if(D < 0)
return -1;
- t = -dot(v, d) - D;
+ if (invert)
+ t = -dot(v, d) + D;
+ else
+ t = -dot(v, d) - D;
if (t <= 0)
return -1;