From 3037c067f2937b68bfd0c7f906f7e7ecadd4b8d5 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 15 Apr 2010 00:06:22 -0400 Subject: Add transformations to textures and pigments. Also, object intersection callbacks are now responsible for handling their own transformations. --- libdimension/texture.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libdimension/texture.c') diff --git a/libdimension/texture.c b/libdimension/texture.c index e08d595..d1047b7 100644 --- a/libdimension/texture.c +++ b/libdimension/texture.c @@ -26,6 +26,7 @@ dmnsn_new_pigment() { dmnsn_pigment *pigment = dmnsn_malloc(sizeof(dmnsn_pigment)); pigment->free_fn = NULL; + pigment->trans = dmnsn_identity_matrix(); return pigment; } @@ -41,6 +42,13 @@ dmnsn_delete_pigment(dmnsn_pigment *pigment) } } +/* Precompute pigment properties */ +void +dmnsn_pigment_precompute(dmnsn_pigment *pigment) +{ + pigment->trans_inv = dmnsn_matrix_inverse(pigment->trans); +} + /* Allocate a dummy finish */ dmnsn_finish * dmnsn_new_finish() @@ -73,6 +81,7 @@ dmnsn_new_texture() dmnsn_texture *texture = dmnsn_malloc(sizeof(dmnsn_texture)); texture->pigment = NULL; texture->finish = NULL; + texture->trans = dmnsn_identity_matrix(); return texture; } @@ -86,3 +95,15 @@ dmnsn_delete_texture(dmnsn_texture *texture) free(texture); } } + +/* Calculate matrix inverses */ +void +dmnsn_texture_precompute(dmnsn_texture *texture) +{ + texture->trans_inv = dmnsn_matrix_inverse(texture->trans); + if (texture->pigment) { + texture->pigment->trans + = dmnsn_matrix_mul(texture->trans, texture->pigment->trans); + dmnsn_pigment_precompute(texture->pigment); + } +} -- cgit v1.2.3