diff options
-rw-r--r-- | libdimension/dimension/object.h | 2 | ||||
-rw-r--r-- | libdimension/object.c | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h index ce57807..3b8768f 100644 --- a/libdimension/dimension/object.h +++ b/libdimension/dimension/object.h @@ -48,6 +48,7 @@ typedef struct dmnsn_object dmnsn_object; /* Object callback types */ +typedef void dmnsn_object_precompute_fn(dmnsn_object *object); typedef bool dmnsn_object_intersection_fn(const dmnsn_object *object, dmnsn_line line, dmnsn_intersection *intersection); @@ -69,6 +70,7 @@ struct dmnsn_object { dmnsn_bounding_box bounding_box; /* Callback functions */ + dmnsn_object_precompute_fn *precompute_fn; dmnsn_object_intersection_fn *intersection_fn; dmnsn_object_inside_fn *inside_fn; dmnsn_free_fn *free_fn; diff --git a/libdimension/object.c b/libdimension/object.c index 9074d60..acc0163 100644 --- a/libdimension/object.c +++ b/libdimension/object.c @@ -37,10 +37,11 @@ dmnsn_object * dmnsn_new_object() { dmnsn_object *object = dmnsn_malloc(sizeof(dmnsn_object)); - object->texture = NULL; - object->interior = NULL; - object->trans = dmnsn_identity_matrix(); - object->free_fn = NULL; + object->texture = NULL; + object->interior = NULL; + object->trans = dmnsn_identity_matrix(); + object->precompute_fn = NULL; + object->free_fn = NULL; return object; } @@ -62,9 +63,14 @@ dmnsn_delete_object(dmnsn_object *object) void dmnsn_object_precompute(dmnsn_object *object) { + if (object->precompute_fn) { + (*object->precompute_fn)(object); + } + object->bounding_box = dmnsn_transform_bounding_box(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); |