diff options
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/dimension/scene.h | 6 | ||||
-rw-r--r-- | libdimension/raytrace.c | 4 | ||||
-rw-r--r-- | libdimension/scene.c | 11 |
3 files changed, 19 insertions, 2 deletions
diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h index 969fa45..41e2360 100644 --- a/libdimension/dimension/scene.h +++ b/libdimension/dimension/scene.h @@ -48,6 +48,12 @@ typedef struct dmnsn_scene { /** Canvas. */ dmnsn_canvas *canvas; + /* Support for rendering image subregions. */ + size_t region_x; /**< The x position of the canvas in the broader image. */ + size_t region_y; /**< The y position of the canvas in the broader image. */ + size_t outer_width; /**< Width of the broader image. */ + size_t outer_height; /**< Height of the broader image. */ + /** Objects. */ dmnsn_array *objects; diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 06878fd..cb5c8b6 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -184,8 +184,8 @@ dmnsn_raytrace_scene_concurrent(void *ptr, unsigned int thread, /* Get the ray corresponding to the (x,y)'th pixel */ dmnsn_line ray = dmnsn_camera_ray( scene->camera, - ((double)x)/(scene->canvas->width - 1), - ((double)y)/(scene->canvas->height - 1) + ((double)(x + scene->region_x))/(scene->outer_width - 1), + ((double)(y + scene->region_y))/(scene->outer_height - 1) ); /* Shoot a ray */ diff --git a/libdimension/scene.c b/libdimension/scene.c index ef597ee..f0ff451 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -37,6 +37,10 @@ dmnsn_new_scene(void) scene->default_texture = dmnsn_new_texture(); scene->default_interior = dmnsn_new_interior(); scene->canvas = NULL; + scene->region_x = 0; + scene->region_y = 0; + scene->outer_width = 0; + scene->outer_height = 0; scene->objects = dmnsn_new_array(sizeof(dmnsn_object *)); scene->lights = dmnsn_new_array(sizeof(dmnsn_light *)); scene->camera = NULL; @@ -83,6 +87,13 @@ dmnsn_initialize_scene(dmnsn_scene *scene) dmnsn_assert(!scene->initialized, "Texture double-initialized."); scene->initialized = true; + if (scene->outer_width == 0) { + scene->outer_width = scene->canvas->width; + } + if (scene->outer_height == 0) { + scene->outer_height = scene->canvas->height; + } + dmnsn_initialize_texture(scene->default_texture); if (scene->sky_sphere) { |