From 3a4da35d5c52d13a5353c6779213505aa862b371 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 3 May 2010 22:24:35 -0600 Subject: Don't apply the transformations which create an object to its textures. For example, sphere { 0, 2 } would scale the texture by a factor of 2. --- dimension/realize.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'dimension') diff --git a/dimension/realize.c b/dimension/realize.c index aa019ed..6771782 100644 --- a/dimension/realize.c +++ b/dimension/realize.c @@ -684,6 +684,9 @@ dmnsn_realize_object_modifiers(dmnsn_astnode astnode, dmnsn_object *object) dmnsn_assert(astnode.type == DMNSN_AST_OBJECT_MODIFIERS, "Expected object modifiers."); + /* Save the pre-existing transformations */ + dmnsn_matrix existing_trans = dmnsn_matrix_inverse(object->trans); + unsigned int i; for (i = 0; i < dmnsn_array_size(astnode.children); ++i) { dmnsn_astnode modifier; @@ -725,6 +728,16 @@ dmnsn_realize_object_modifiers(dmnsn_astnode astnode, dmnsn_object *object) dmnsn_assert(false, "Invalid object modifier."); } } + + if (object->texture) { + /* Right-multiply to counteract any pre-existing transformations -- this + means, for example, that the transformation that makes a sphere have + radius 2 doesn't scale the texture by a factor of 2 */ + object->texture->trans = dmnsn_matrix_mul( + object->texture->trans, + existing_trans + ); + } } static void -- cgit v1.2.3