summaryrefslogtreecommitdiffstats
path: root/libdimension/texture.c
diff options
context:
space:
mode:
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);
+ }
+}