diff options
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/dimension/object.h | 3 | ||||
-rw-r--r-- | libdimension/object.c | 6 | ||||
-rw-r--r-- | libdimension/raytrace.c | 10 |
3 files changed, 15 insertions, 4 deletions
diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h index bd660a0..589ac29 100644 --- a/libdimension/dimension/object.h +++ b/libdimension/dimension/object.h @@ -38,6 +38,9 @@ struct dmnsn_object { /* Generic pointer for object info */ void *ptr; + /* Transformation matrix */ + dmnsn_matrix trans; + /* Callback functions */ dmnsn_object_intersections_fn *intersections_fn; dmnsn_object_inside_fn *inside_fn; diff --git a/libdimension/object.c b/libdimension/object.c index 39064f3..75a82b6 100644 --- a/libdimension/object.c +++ b/libdimension/object.c @@ -24,7 +24,11 @@ dmnsn_object * dmnsn_new_object() { - return malloc(sizeof(dmnsn_object)); + dmnsn_object *object = malloc(sizeof(dmnsn_object)); + if (object) { + object->trans = dmnsn_identity_matrix(); + } + return object; } void diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 469ac66..316157a 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -68,7 +68,7 @@ dmnsn_raytrace_scene_thread(void *arg) { unsigned int i, j, k; dmnsn_object *object; - dmnsn_line ray; + dmnsn_line ray, ray_trans; dmnsn_raytrace_thread_payload *payload = (dmnsn_raytrace_thread_payload *)arg; dmnsn_scene *scene = payload->scene; dmnsn_array *intersections; @@ -83,11 +83,15 @@ dmnsn_raytrace_scene_thread(void *arg) /* Get the ray corresponding to the (i,j)th pixel */ ray = (*scene->camera->ray_fn)(scene->camera, scene->canvas, i, j); - + for (k = 0; k < scene->objects->length; ++k) { dmnsn_array_get(scene->objects, k, &object); + + /* Transform the ray according to the object */ + ray_trans = dmnsn_matrix_line_mul(object->trans, ray); + /* Test for an intersection with an object */ - intersections = (*object->intersections_fn)(object, ray); + intersections = (*object->intersections_fn)(object, ray_trans); if (intersections->length > 0) { /* Mark intersections white */ dmnsn_set_pixel(scene->canvas, i, j, |