summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-06-04 15:34:40 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-06-04 15:44:35 -0400
commit270a53ef8d4d009dd79605058b780dc6d1f2ed1a (patch)
tree20595f056d48b766ee5a58aaf5bb433af767beee /libdimension
parent09a16db937f37e2b25eb2745cfa2b5e0ff8fc5ad (diff)
downloaddimension-270a53ef8d4d009dd79605058b780dc6d1f2ed1a.tar.xz
object: Don't give every object a child array.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/csg.c4
-rw-r--r--libdimension/object.c28
2 files changed, 19 insertions, 13 deletions
diff --git a/libdimension/csg.c b/libdimension/csg.c
index b77b20e..5a7534b 100644
--- a/libdimension/csg.c
+++ b/libdimension/csg.c
@@ -83,6 +83,7 @@ dmnsn_new_csg_union(dmnsn_pool *pool, const dmnsn_array *objects)
dmnsn_object *object = &csg->object;
dmnsn_init_object(pool, object);
+ object->children = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *);
DMNSN_ARRAY_FOREACH (dmnsn_object **, child, objects) {
dmnsn_array_push(object->children, child);
}
@@ -209,6 +210,7 @@ dmnsn_new_csg_intersection(dmnsn_pool *pool, dmnsn_object *A, dmnsn_object *B)
{
dmnsn_object *csg = dmnsn_new_object(pool);
+ csg->children = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *);
dmnsn_array_push(csg->children, &A);
dmnsn_array_push(csg->children, &B);
@@ -256,6 +258,7 @@ dmnsn_new_csg_difference(dmnsn_pool *pool, dmnsn_object *A, dmnsn_object *B)
{
dmnsn_object *csg = dmnsn_new_object(pool);
+ csg->children = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *);
dmnsn_array_push(csg->children, &A);
dmnsn_array_push(csg->children, &B);
@@ -307,6 +310,7 @@ dmnsn_new_csg_merge(dmnsn_pool *pool, dmnsn_object *A, dmnsn_object *B)
{
dmnsn_object *csg = dmnsn_new_object(pool);
+ csg->children = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *);
dmnsn_array_push(csg->children, &A);
dmnsn_array_push(csg->children, &B);
diff --git a/libdimension/object.c b/libdimension/object.c
index 432e473..ed87ce6 100644
--- a/libdimension/object.c
+++ b/libdimension/object.c
@@ -43,7 +43,7 @@ dmnsn_init_object(dmnsn_pool *pool, dmnsn_object *object)
object->interior = NULL;
object->trans = dmnsn_identity_matrix();
object->intrinsic_trans = dmnsn_identity_matrix();
- object->children = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *);
+ object->children = NULL;
object->split_children = false;
object->intersection_fn = NULL;
object->inside_fn = NULL;
@@ -69,20 +69,22 @@ dmnsn_object_initialize_recursive(dmnsn_object *object,
object->trans = dmnsn_matrix_mul(object->trans, object->intrinsic_trans);
/* Initialize the object's children */
- DMNSN_ARRAY_FOREACH (dmnsn_object **, child, object->children) {
- (*child)->trans = dmnsn_matrix_mul(object->trans, (*child)->trans);
+ if (object->children) {
+ DMNSN_ARRAY_FOREACH (dmnsn_object **, child, object->children) {
+ (*child)->trans = dmnsn_matrix_mul(object->trans, (*child)->trans);
- dmnsn_matrix child_pigment_trans;
- if ((*child)->texture == NULL || (*child)->texture->pigment == NULL) {
- /* Don't transform cascaded pigments with the child object */
- child_pigment_trans = pigment_trans;
- } else {
- child_pigment_trans = dmnsn_matrix_inverse((*child)->trans);
- }
+ dmnsn_matrix child_pigment_trans;
+ if ((*child)->texture == NULL || (*child)->texture->pigment == NULL) {
+ /* Don't transform cascaded pigments with the child object */
+ child_pigment_trans = pigment_trans;
+ } else {
+ child_pigment_trans = dmnsn_matrix_inverse((*child)->trans);
+ }
- dmnsn_texture_cascade(object->texture, &(*child)->texture);
- dmnsn_interior_cascade(object->interior, &(*child)->interior);
- dmnsn_object_initialize_recursive(*child, child_pigment_trans);
+ dmnsn_texture_cascade(object->texture, &(*child)->texture);
+ dmnsn_interior_cascade(object->interior, &(*child)->interior);
+ dmnsn_object_initialize_recursive(*child, child_pigment_trans);
+ }
}
/* Initialization callback */