diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-06-13 20:47:24 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-06-13 20:47:24 +0000 |
commit | 5c8f366a3b5d7303bf73bd6d5d0af0459bac72a2 (patch) | |
tree | adef78e07d9d9fa739d3fd661e959eb9ac023458 /libdimension/scene.c | |
parent | 4ef467adcb69fecadf9e8410fc8b33e1bb307365 (diff) | |
download | dimension-5c8f366a3b5d7303bf73bd6d5d0af0459bac72a2.tar.xz |
Add camera type.
Diffstat (limited to 'libdimension/scene.c')
-rw-r--r-- | libdimension/scene.c | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/libdimension/scene.c b/libdimension/scene.c index 541e3ba..780f8c6 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -22,19 +22,11 @@ #include <stdlib.h> /* For malloc */ dmnsn_scene * -dmnsn_new_scene(unsigned int x, unsigned int y) +dmnsn_new_scene() { dmnsn_scene *scene = malloc(sizeof(dmnsn_scene)); - if (scene) { + if (scene) scene->objects = dmnsn_new_array(sizeof(dmnsn_object*)); - - scene->canvas = dmnsn_new_canvas(x, y); - if (!scene->canvas) { - dmnsn_delete_array(scene->objects); - return NULL; - } - } - return scene; } @@ -52,18 +44,14 @@ dmnsn_raytrace_scene(dmnsn_scene *scene) { unsigned int i, j; dmnsn_object *object; - dmnsn_line l; + dmnsn_line ray; - l.x0 = dmnsn_vector_construct(0.0, 0.0, -3.0); dmnsn_array_get(scene->objects, 0, &object); for (i = 0; i < scene->canvas->x; ++i) { for (j = 0; j < scene->canvas->y; ++j) { - l.n.x = 1.6*(((double)i)/(scene->canvas->x - 1) - 0.5); - l.n.y = ((double)j)/(scene->canvas->y - 1) - 0.5; - l.n.z = 1.0; - - if ((*object->intersections_fn)(l)->length > 0) { + ray = (*scene->camera->ray_fn)(scene->canvas, i, j); + if ((*object->intersections_fn)(ray)->length > 0) { dmnsn_set_pixel(scene->canvas, i, j, dmnsn_color_from_XYZ(dmnsn_whitepoint)); } else { |