summaryrefslogtreecommitdiff
path: root/3dmath.c
diff options
context:
space:
mode:
authorMorten Hustveit <morten.hustveit@gmail.com>2014-12-02 15:53:29 -0500
committerMorten Hustveit <morten.hustveit@gmail.com>2014-12-02 15:53:29 -0500
commit4ddcfc0bb65d82d4e3fd2d424912086a4b454fdf (patch)
tree36df67d3c86055707d14bb037d1b2de342e31b68 /3dmath.c
parent64a24eff5995c44d21e42d0bc654739030eca76c (diff)
3dmath.c: Remove sqrt from sphere_intersect
Interestingly, this seems to only save 1ms/frame on yelena. But that's still 16% of a 60fps frame.
Diffstat (limited to '3dmath.c')
-rw-r--r--3dmath.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/3dmath.c b/3dmath.c
index 866af09..9e7f7a1 100644
--- a/3dmath.c
+++ b/3dmath.c
@@ -43,10 +43,10 @@ sphere_intersect(float* restrict y, float* restrict r,
n[i] = y[i] - c[i];
}
- normalize(n);
+ float two_dot_nd_div_sq_n_mag = 2.0f * dot(n, d) / dot(n, n);
- for(i = 0; i < 3; ++i)
- r[i] = d[i] - 2 * dot(n, d) * n[i];
+ for (i = 0; i < 3; ++i)
+ r[i] = d[i] - two_dot_nd_div_sq_n_mag * n[i];
return t;
}