From 708954192219feead526f84c0c8bdb29088aeae0 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 6 Jun 2014 14:14:00 -0400 Subject: objects: Use a vtable to shrink object structs. --- libdimension/sphere.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libdimension/sphere.c') diff --git a/libdimension/sphere.c b/libdimension/sphere.c index 821113d..105d8d6 100644 --- a/libdimension/sphere.c +++ b/libdimension/sphere.c @@ -58,13 +58,17 @@ dmnsn_sphere_inside_fn(const dmnsn_object *sphere, dmnsn_vector point) return point.x*point.x + point.y*point.y + point.z*point.z < 1.0; } -/* Allocate a new sphere */ +/** Torus vtable. */ +static const dmnsn_object_vtable dmnsn_sphere_vtable = { + .intersection_fn = dmnsn_sphere_intersection_fn, + .inside_fn = dmnsn_sphere_inside_fn, +}; + dmnsn_object * dmnsn_new_sphere(dmnsn_pool *pool) { dmnsn_object *sphere = dmnsn_new_object(pool); - sphere->intersection_fn = dmnsn_sphere_intersection_fn; - sphere->inside_fn = dmnsn_sphere_inside_fn; + sphere->vtable = &dmnsn_sphere_vtable; sphere->bounding_box.min = dmnsn_new_vector(-1.0, -1.0, -1.0); sphere->bounding_box.max = dmnsn_new_vector(1.0, 1.0, 1.0); return sphere; -- cgit v1.2.3