diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-11-09 14:18:38 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-11-09 14:19:25 -0500 |
commit | 89da144e4095ecece603a5d7adf29b7a8e493bb1 (patch) | |
tree | 55f90aa73e5edc540837e2dfa3bf0c08d3dcee3d /libdimension | |
parent | ecf8117d5d77e5ad9ebc2f987af7f07f75a30c45 (diff) | |
download | dimension-89da144e4095ecece603a5d7adf29b7a8e493bb1.tar.xz |
Store inverse object transformation in a separate field.
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/dimension/object.h | 2 | ||||
-rw-r--r-- | libdimension/kD_splay_tree.c | 25 |
2 files changed, 14 insertions, 13 deletions
diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h index fd0eba1..0f53406 100644 --- a/libdimension/dimension/object.h +++ b/libdimension/dimension/object.h @@ -56,7 +56,7 @@ struct dmnsn_object { dmnsn_texture *texture; /* Transformation matrix */ - dmnsn_matrix trans; + dmnsn_matrix trans, trans_inv; /* Bounding box */ dmnsn_vector min, max; diff --git a/libdimension/kD_splay_tree.c b/libdimension/kD_splay_tree.c index 44fae7b..5c6289d 100644 --- a/libdimension/kD_splay_tree.c +++ b/libdimension/kD_splay_tree.c @@ -98,10 +98,11 @@ static void dmnsn_kD_splay_node_swallow(dmnsn_kD_splay_node *node, void dmnsn_kD_splay_insert(dmnsn_kD_splay_tree *tree, dmnsn_object *object) { - dmnsn_vector corner; - dmnsn_matrix trans_inv; dmnsn_kD_splay_node *node = dmnsn_new_kD_splay_node(), *parent = tree->root; + /* Store the inverse of the transformation matrix */ + object->trans_inv = dmnsn_matrix_inverse(object->trans); + node->contains = NULL; node->container = NULL; node->parent = NULL; @@ -110,36 +111,36 @@ dmnsn_kD_splay_insert(dmnsn_kD_splay_tree *tree, dmnsn_object *object) /* Calculate the new bounding box by finding the minimum coordinate of the transformed corners of the object's original bounding box */ - trans_inv = dmnsn_matrix_inverse(object->trans); - node->min = dmnsn_matrix_vector_mul(trans_inv, object->min); + node->min = dmnsn_matrix_vector_mul(object->trans, object->min); node->max = node->min; + dmnsn_vector corner; corner = dmnsn_vector_construct(object->min.x, object->min.y, object->max.z); - corner = dmnsn_matrix_vector_mul(trans_inv, corner); + corner = dmnsn_matrix_vector_mul(object->trans, corner); dmnsn_kD_splay_node_swallow(node, corner, corner); corner = dmnsn_vector_construct(object->min.x, object->max.y, object->min.z); - corner = dmnsn_matrix_vector_mul(trans_inv, corner); + corner = dmnsn_matrix_vector_mul(object->trans, corner); dmnsn_kD_splay_node_swallow(node, corner, corner); corner = dmnsn_vector_construct(object->min.x, object->max.y, object->max.z); - corner = dmnsn_matrix_vector_mul(trans_inv, corner); + corner = dmnsn_matrix_vector_mul(object->trans, corner); dmnsn_kD_splay_node_swallow(node, corner, corner); corner = dmnsn_vector_construct(object->max.x, object->min.y, object->min.z); - corner = dmnsn_matrix_vector_mul(trans_inv, corner); + corner = dmnsn_matrix_vector_mul(object->trans, corner); dmnsn_kD_splay_node_swallow(node, corner, corner); corner = dmnsn_vector_construct(object->max.x, object->min.y, object->max.z); - corner = dmnsn_matrix_vector_mul(trans_inv, corner); + corner = dmnsn_matrix_vector_mul(object->trans, corner); dmnsn_kD_splay_node_swallow(node, corner, corner); corner = dmnsn_vector_construct(object->max.x, object->max.y, object->min.z); - corner = dmnsn_matrix_vector_mul(trans_inv, corner); + corner = dmnsn_matrix_vector_mul(object->trans, corner); dmnsn_kD_splay_node_swallow(node, corner, corner); corner = dmnsn_vector_construct(object->max.x, object->max.y, object->max.z); - corner = dmnsn_matrix_vector_mul(trans_inv, corner); + corner = dmnsn_matrix_vector_mul(object->trans, corner); dmnsn_kD_splay_node_swallow(node, corner, corner); /* Now insert the node */ @@ -337,7 +338,7 @@ dmnsn_kD_splay_search_recursive(dmnsn_kD_splay_node *node, dmnsn_line ray, || dmnsn_ray_box_intersection(ray, node->min, node->max, t)) { /* Transform the ray according to the object */ - ray_trans = dmnsn_matrix_line_mul(node->object->trans, ray); + ray_trans = dmnsn_matrix_line_mul(node->object->trans_inv, ray); if (dmnsn_box_contains(ray_trans.x0, node->object->min, node->object->max) || dmnsn_ray_box_intersection(ray_trans, node->object->min, |