summaryrefslogtreecommitdiffstats
path: root/libdimension/sphere.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-04-07 15:59:49 -0400
committerTavian Barnes <tavianator@gmail.com>2010-04-07 16:09:22 -0400
commit7b08644490cc1f897f4c327af839f0b2448351c0 (patch)
tree7d4fe3dbb0d2dbe8fef27a46f320eac40ecf7298 /libdimension/sphere.c
parent03c4f1bb394e6d0bee61a438937e068ccf57e09d (diff)
downloaddimension-7b08644490cc1f897f4c327af839f0b2448351c0.tar.xz
Don't use dynamic memory for dmnsn_intersection's.
Drops us from ~400,000 allocs to ~1000. Oops ><.
Diffstat (limited to 'libdimension/sphere.c')
-rw-r--r--libdimension/sphere.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/libdimension/sphere.c b/libdimension/sphere.c
index 77fd1d4..09b6767 100644
--- a/libdimension/sphere.c
+++ b/libdimension/sphere.c
@@ -27,9 +27,9 @@
/* Sphere object callbacks */
-static dmnsn_intersection *
-dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line);
-
+static bool dmnsn_sphere_intersection_fn(const dmnsn_object *sphere,
+ dmnsn_line line,
+ dmnsn_intersection *intersection);
static bool dmnsn_sphere_inside_fn(const dmnsn_object *sphere,
dmnsn_vector point);
@@ -46,11 +46,11 @@ dmnsn_new_sphere()
}
/* Returns the closest intersection of `line' with `sphere' */
-static dmnsn_intersection *
-dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line)
+static bool
+dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line,
+ dmnsn_intersection *intersection)
{
double a, b, c, t;
- dmnsn_intersection *intersection = NULL;
/* Solve (x0 + nx*t)^2 + (y0 + ny*t)^2 + (z0 + nz*t)^2 == 1 */
@@ -65,16 +65,16 @@ dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line)
}
if (t >= 0.0) {
- intersection = dmnsn_new_intersection();
intersection->ray = line;
intersection->t = t;
intersection->normal = dmnsn_line_point(line, t);
intersection->texture = sphere->texture;
intersection->interior = sphere->interior;
+ return true;
}
}
- return intersection;
+ return false;
}
/* Return whether a point is inside a sphere (x**2 + y**2 + z**2 < 1.0) */