summaryrefslogtreecommitdiffstats
path: root/libdimension/texture.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-04-15 00:06:22 -0400
committerTavian Barnes <tavianator@gmail.com>2010-04-15 00:06:22 -0400
commit3037c067f2937b68bfd0c7f906f7e7ecadd4b8d5 (patch)
tree1372d1f823fa665ee29a102779627464dd49dabf /libdimension/texture.c
parent59dc3d29a1edf73cf54f10ee32d61815a437619f (diff)
downloaddimension-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/texture.c')
-rw-r--r--libdimension/texture.c21
1 files changed, 21 insertions, 0 deletions
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);
+ }
+}