summaryrefslogtreecommitdiffstats
path: root/libdimension/bench
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-06-07 14:15:06 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-06-07 14:30:26 -0400
commita79085ab984979dbf4f78545f7592c8b47e4a794 (patch)
treee2518532db860db8ba59878ecd6d0d4b60f0b5c4 /libdimension/bench
parent708954192219feead526f84c0c8bdb29088aeae0 (diff)
downloaddimension-a79085ab984979dbf4f78545f7592c8b47e4a794.tar.xz
objects: Refactor how bounding and initialization work.
Diffstat (limited to 'libdimension/bench')
-rw-r--r--libdimension/bench/prtree.c20
-rw-r--r--libdimension/bench/triangle.c2
2 files changed, 12 insertions, 10 deletions
diff --git a/libdimension/bench/prtree.c b/libdimension/bench/prtree.c
index c09a701..dc5a90d 100644
--- a/libdimension/bench/prtree.c
+++ b/libdimension/bench/prtree.c
@@ -40,8 +40,8 @@ dmnsn_fake_inside_fn(const dmnsn_object *object, dmnsn_vector point)
return true;
}
-static void
-dmnsn_randomize_bounding_box(dmnsn_object *object)
+static dmnsn_bounding_box
+dmnsn_fake_bounding_fn(const dmnsn_object *object, dmnsn_matrix trans)
{
dmnsn_vector a, b;
@@ -53,18 +53,20 @@ dmnsn_randomize_bounding_box(dmnsn_object *object)
b.y = 2.0*((double)rand())/RAND_MAX - 1.0;
b.z = 2.0*((double)rand())/RAND_MAX - 1.0;
- object->bounding_box.min = dmnsn_vector_min(a, b);
- object->bounding_box.max = dmnsn_vector_max(a, b);
+ return dmnsn_new_bounding_box(dmnsn_vector_min(a, b), dmnsn_vector_max(a, b));
}
+static dmnsn_object_vtable dmnsn_fake_vtable = {
+ .intersection_fn = dmnsn_fake_intersection_fn,
+ .inside_fn = dmnsn_fake_inside_fn,
+ .bounding_fn = dmnsn_fake_bounding_fn,
+};
+
static dmnsn_object *
dmnsn_new_fake_object(dmnsn_pool *pool)
{
dmnsn_object *object = dmnsn_new_object(pool);
- /* Generate a bounding box in (-1, -1, -1), (1, 1, 1) */
- dmnsn_randomize_bounding_box(object);
- object->intersection_fn = dmnsn_fake_intersection_fn;
- object->inside_fn = dmnsn_fake_inside_fn;
+ object->vtable = &dmnsn_fake_vtable;
return object;
}
@@ -86,7 +88,7 @@ main(void)
for (size_t i = 0; i < nobjects; ++i) {
dmnsn_object *object = dmnsn_new_fake_object(pool);
object->texture = texture;
- dmnsn_object_initialize(object);
+ dmnsn_object_precompute(object);
dmnsn_array_push(objects, &object);
}
diff --git a/libdimension/bench/triangle.c b/libdimension/bench/triangle.c
index b149c27..05b8f47 100644
--- a/libdimension/bench/triangle.c
+++ b/libdimension/bench/triangle.c
@@ -40,7 +40,7 @@ main(void)
dmnsn_object *triangle = dmnsn_new_triangle(pool, vertices);
triangle->texture = dmnsn_new_texture(pool);
triangle->texture->pigment = dmnsn_new_pigment(pool);
- dmnsn_object_initialize(triangle);
+ dmnsn_object_precompute(triangle);
dmnsn_intersection intersection;
dmnsn_line line;