diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-10-07 18:39:13 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-10-07 18:39:13 +0000 |
commit | 4bd6e26bf3442a1e94bc8d689c258c0b22b85c0f (patch) | |
tree | 3ab19e24a7c0e8925ea2ad02afa6d3fa8726b0ea /libdimension | |
parent | 98571f18529c4f746b5beb02f5d83848af1759c4 (diff) | |
download | dimension-4bd6e26bf3442a1e94bc8d689c258c0b22b85c0f.tar.xz |
Test object's bounding boxes too in dmnsn_kD_splay_search().
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/kD_splay_tree.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/libdimension/kD_splay_tree.c b/libdimension/kD_splay_tree.c index 1d099d5..25ed1c4 100644 --- a/libdimension/kD_splay_tree.c +++ b/libdimension/kD_splay_tree.c @@ -303,7 +303,8 @@ dmnsn_kD_splay_search_recursive(dmnsn_kD_splay_node *node, dmnsn_line ray, double t_temp; dmnsn_line ray_trans; dmnsn_kD_splay_search_result result = { NULL, NULL }, result_temp; - int search_left = 0; /* Whether to search the left branch */ + int search_left; /* Whether to search the left branch */ + int test_object; /* Whether to test for an intersection with the object */ if (!node) return result; @@ -325,24 +326,40 @@ dmnsn_kD_splay_search_recursive(dmnsn_kD_splay_node *node, dmnsn_line ray, * closer than `t'. */ t_temp = dmnsn_ray_box_intersection(ray, node->min, node->max); - search_left = t_temp >= 0.0 && (t < 0.0 || t_temp < t) } if (search_left) { /* Transform the ray according to the object */ ray_trans = dmnsn_matrix_line_mul(node->object->trans, ray); - /* Test for an intersection with the current object */ - result.intersection = - (*node->object->intersection_fn)(node->object, ray_trans); - - if (result.intersection) { - if (t < 0.0 || result.intersection->t < t) { - result.node = node; - t = result.intersection->t; - } else { - dmnsn_delete_intersection(result.intersection); - result.intersection = NULL; + + if ((ray_trans.x0.x >= node->object->min.x + && ray_trans.x0.y >= node->object->min.y + && ray_trans.x0.z >= node->object->min.z) + && (ray_trans.x0.x <= node->object->max.x + && ray_trans.x0.y <= node->object->max.y + && ray_trans.x0.z <= node->object->max.z)) + { + /* Our line's origin is inside the object's true bounding box */ + test_object = 1; + } else { + t_temp = dmnsn_ray_box_intersection(ray, node->min, node->max); + test_object = t_temp >= 0.0 && (t < 0.0 || t_temp < t) + } + + if (test_object) { + /* Test for an intersection with the current object */ + result.intersection = + (*node->object->intersection_fn)(node->object, ray_trans); + + if (result.intersection) { + if (t < 0.0 || result.intersection->t < t) { + result.node = node; + t = result.intersection->t; + } else { + dmnsn_delete_intersection(result.intersection); + result.intersection = NULL; + } } } |