diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-04-15 00:06:22 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-04-15 00:06:22 -0400 |
commit | 3037c067f2937b68bfd0c7f906f7e7ecadd4b8d5 (patch) | |
tree | 1372d1f823fa665ee29a102779627464dd49dabf /libdimension/object.c | |
parent | 59dc3d29a1edf73cf54f10ee32d61815a437619f (diff) | |
download | dimension-3037c067f2937b68bfd0c7f906f7e7ecadd4b8d5.tar.xz |
Add transformations to textures and pigments.
Also, object intersection callbacks are now responsible for handling their own
transformations.
Diffstat (limited to 'libdimension/object.c')
-rw-r--r-- | libdimension/object.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libdimension/object.c b/libdimension/object.c index 890d0e0..3cf68c7 100644 --- a/libdimension/object.c +++ b/libdimension/object.c @@ -20,6 +20,17 @@ #include "dimension.h" +dmnsn_vector +dmnsn_matrix_normal_mul(dmnsn_matrix trans, dmnsn_vector normal) +{ + return dmnsn_vector_normalize( + dmnsn_vector_sub( + dmnsn_matrix_vector_mul(trans, normal), + dmnsn_matrix_vector_mul(trans, dmnsn_zero) + ) + ); +} + /* Allocate a dummy object */ dmnsn_object * dmnsn_new_object() @@ -45,3 +56,17 @@ dmnsn_delete_object(dmnsn_object *object) free(object); } } + +/* Precompute object properties */ +void +dmnsn_object_precompute(dmnsn_object *object) +{ + object->bounding_box + = dmnsn_matrix_bounding_box_mul(object->trans, object->bounding_box); + object->trans_inv = dmnsn_matrix_inverse(object->trans); + if (object->texture) { + object->texture->trans + = dmnsn_matrix_mul(object->trans, object->texture->trans); + dmnsn_texture_precompute(object->texture); + } +} |