diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-04-15 15:15:39 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-04-15 15:15:39 -0400 |
commit | 1b1f00e70564d6acb2b1e09b0a5f430da4e4b8a3 (patch) | |
tree | ccf2628596a9ac7a1d2fed71f048d7427576a737 /libdimension | |
parent | 3037c067f2937b68bfd0c7f906f7e7ecadd4b8d5 (diff) | |
download | dimension-1b1f00e70564d6acb2b1e09b0a5f430da4e4b8a3.tar.xz |
Support infinitely large bounding boxes.
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/bvst.c | 18 | ||||
-rw-r--r-- | libdimension/geometry.c | 9 |
2 files changed, 17 insertions, 10 deletions
diff --git a/libdimension/bvst.c b/libdimension/bvst.c index c0888bb..7a57c76 100644 --- a/libdimension/bvst.c +++ b/libdimension/bvst.c @@ -105,12 +105,10 @@ dmnsn_bvst_insert(dmnsn_bvst *tree, dmnsn_object *object) dmnsn_bvst_node *node = dmnsn_new_bvst_node(), *parent = tree->root; - node->contains = NULL; - node->container = NULL; - node->parent = NULL; - node->object = object; - - /* Calculate the new bounding box */ + node->contains = NULL; + node->container = NULL; + node->parent = NULL; + node->object = object; node->bounding_box = object->bounding_box; /* Now insert the node */ @@ -122,9 +120,9 @@ dmnsn_bvst_insert(dmnsn_bvst *tree, dmnsn_object *object) node->bounding_box.max)) { /* parent fully contains node */ - if (parent->contains) + if (parent->contains) { parent = parent->contains; - else { + } else { /* We found our parent; insert node into the tree */ parent->contains = node; node->parent = parent; @@ -135,9 +133,9 @@ dmnsn_bvst_insert(dmnsn_bvst *tree, dmnsn_object *object) already */ dmnsn_bvst_node_swallow(node, parent->bounding_box); /* node now fully contains parent */ - if (parent->container) + if (parent->container) { parent = parent->container; - else { + } else { /* We found our parent; insert node into the tree */ parent->container = node; node->parent = parent; diff --git a/libdimension/geometry.c b/libdimension/geometry.c index 7dc6725..304f21d 100644 --- a/libdimension/geometry.c +++ b/libdimension/geometry.c @@ -363,6 +363,15 @@ dmnsn_matrix_vector_mul(dmnsn_matrix lhs, dmnsn_vector rhs) dmnsn_bounding_box dmnsn_matrix_bounding_box_mul(dmnsn_matrix trans, dmnsn_bounding_box box) { + /* Infinite bounding box support */ + if (isinf(box.min.x) || isinf(box.min.y) || isinf(box.min.z) + || isinf(box.max.x) || isinf(box.max.y) || isinf(box.max.z)) + { + box.min = dmnsn_new_vector(-INFINITY, -INFINITY, -INFINITY); + box.max = dmnsn_new_vector(INFINITY, INFINITY, INFINITY); + return box; + } + dmnsn_vector corner; dmnsn_bounding_box ret; ret.min = dmnsn_matrix_vector_mul(trans, box.min); |