diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-07-28 12:47:10 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-07-28 12:47:10 -0600 |
commit | 275c2542c4e414ffe01558cfca2445dcad6bbd29 (patch) | |
tree | 62ef619a9e9577386f7805f7799784a2c03dcb0c /libdimension | |
parent | 2c6692e1fb0687ddd2898220286c7a3c7e8b6850 (diff) | |
download | dimension-275c2542c4e414ffe01558cfca2445dcad6bbd29.tar.xz |
Remove color_maps.
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/Makefile.am | 1 | ||||
-rw-r--r-- | libdimension/color_map.c | 98 | ||||
-rw-r--r-- | libdimension/dimension/map.h | 6 | ||||
-rw-r--r-- | libdimension/dimension/pigments.h | 28 | ||||
-rw-r--r-- | libdimension/pigment_map.c | 7 | ||||
-rw-r--r-- | libdimension/tests/render.c | 138 |
6 files changed, 109 insertions, 169 deletions
diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am index b042fc9..31db52a 100644 --- a/libdimension/Makefile.am +++ b/libdimension/Makefile.am @@ -68,7 +68,6 @@ libdimension_la_SOURCES = $(nobase_include_HEADERS) \ canvas_pigment.c \ checker.c \ color.c \ - color_map.c \ compiler.h \ cone.c \ cube.c \ diff --git a/libdimension/color_map.c b/libdimension/color_map.c deleted file mode 100644 index 654fe97..0000000 --- a/libdimension/color_map.c +++ /dev/null @@ -1,98 +0,0 @@ -/************************************************************************* - * Copyright (C) 2010 Tavian Barnes <tavianator@tavianator.com> * - * * - * This file is part of The Dimension Library. * - * * - * The Dimension Library is free software; you can redistribute it and/ * - * or modify it under the terms of the GNU Lesser General Public License * - * as published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * The Dimension Library is distributed in the hope that it will be * - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this program. If not, see * - * <http://www.gnu.org/licenses/>. * - *************************************************************************/ - -/** - * @file - * Color-mapped pigment patterns. - */ - -#include "dimension.h" - -dmnsn_map * -dmnsn_new_color_map(void) -{ - return dmnsn_new_map(sizeof(dmnsn_color)); -} - -/** Payload for a color_map pigment. */ -typedef struct dmnsn_color_map_payload { - dmnsn_pattern *pattern; - dmnsn_map *map; - dmnsn_pigment_map_flags flags; -} dmnsn_color_map_payload; - -/** Free a color_map payload. */ -static void -dmnsn_delete_color_map_payload(void *ptr) -{ - dmnsn_color_map_payload *payload = ptr; - dmnsn_delete_map(payload->map); - dmnsn_delete_pattern(payload->pattern); - dmnsn_free(payload); -} - -/** color_map pigment callback. */ -static dmnsn_color -dmnsn_color_map_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v) -{ - const dmnsn_color_map_payload *payload = pigment->ptr; - double n; - dmnsn_color color1, color2; - dmnsn_evaluate_map(payload->map, dmnsn_pattern_value(payload->pattern, v), - &n, &color1, &color2); - - if (payload->flags == DMNSN_PIGMENT_MAP_SRGB) { - color1 = dmnsn_color_to_sRGB(color1); - color2 = dmnsn_color_to_sRGB(color2); - } - dmnsn_color ret = dmnsn_color_gradient(color1, color2, n); - if (payload->flags == DMNSN_PIGMENT_MAP_SRGB) { - ret = dmnsn_color_from_sRGB(ret); - } - - return ret; -} - -/** color_map initialization callback. */ -static void -dmnsn_color_map_initialize_fn(dmnsn_pigment *pigment) -{ - dmnsn_color_map_payload *payload = pigment->ptr; - dmnsn_initialize_pattern(payload->pattern); -} - -dmnsn_pigment * -dmnsn_new_color_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map, - dmnsn_pigment_map_flags flags) -{ - dmnsn_pigment *pigment = dmnsn_new_pigment(); - - dmnsn_color_map_payload *payload - = dmnsn_malloc(sizeof(dmnsn_color_map_payload)); - payload->pattern = pattern; - payload->map = map; - payload->flags = flags; - - pigment->pigment_fn = dmnsn_color_map_pigment_fn; - pigment->initialize_fn = dmnsn_color_map_initialize_fn; - pigment->free_fn = dmnsn_delete_color_map_payload; - pigment->ptr = payload; - return pigment; -} diff --git a/libdimension/dimension/map.h b/libdimension/dimension/map.h index 80b48b6..b515518 100644 --- a/libdimension/dimension/map.h +++ b/libdimension/dimension/map.h @@ -20,7 +20,7 @@ /** * @file - * Generic maps (backend for color_maps, pigment_maps, etc.). + * Generic maps (backend for pigment_maps, etc.). */ /** A map. */ @@ -44,8 +44,8 @@ dmnsn_map *dmnsn_new_map(size_t size); void dmnsn_delete_map(dmnsn_map *map); /** - * Add an entry (a scalar-object pair) to a color map. - * @param[in,out] map The color map to add to. + * Add an entry (a scalar-object pair) to a map. + * @param[in,out] map The map to add to. * @param[in] n The index of the entry. * @param[in] obj The value of the entry. */ diff --git a/libdimension/dimension/pigments.h b/libdimension/dimension/pigments.h index 60dc658..56bba92 100644 --- a/libdimension/dimension/pigments.h +++ b/libdimension/dimension/pigments.h @@ -39,13 +39,7 @@ dmnsn_pigment *dmnsn_new_solid_pigment(dmnsn_color color); dmnsn_pigment *dmnsn_new_canvas_pigment(dmnsn_canvas *canvas); /** - * Construct a color map. - * @return An empty color map. - */ -dmnsn_map *dmnsn_new_color_map(void); - -/** - * pigment_map flags. + * Pigment map flags. */ typedef enum dmnsn_pigment_map_flags { DMNSN_PIGMENT_MAP_REGULAR, /**< Calculate linear color gradients. */ @@ -53,23 +47,21 @@ typedef enum dmnsn_pigment_map_flags { } dmnsn_pigment_map_flags; /** - * A color-mapped pigment. - * @param[in,out] pattern The pattern of the pigment. - * @param[in,out] map The color map to apply to the pattern. - * @param[in] flags Gradient flags - * @return A pigment mapping the pattern to color values. - */ -dmnsn_pigment *dmnsn_new_color_map_pigment(dmnsn_pattern *pattern, - dmnsn_map *map, - dmnsn_pigment_map_flags flags); - -/** * Construct a pigment map. * @return An empty pigment map. */ dmnsn_map *dmnsn_new_pigment_map(void); /** + * Add a raw color to a pigment map. + * Shorthand for creating a solid pigment and adding it manually. + * @param[in,out] map The pigment map to add to. + * @param[in] n The index of the entry. + * @param[in] color The value of the entry. + */ +void dmnsn_pigment_map_add_color(dmnsn_map *map, double n, dmnsn_color color); + +/** * A pigment-mapped pigment. * @param[in,out] pattern The pattern of the pigment. * @param[in,out] map The pigment map to apply to the pattern. diff --git a/libdimension/pigment_map.c b/libdimension/pigment_map.c index cf49649..4ffb129 100644 --- a/libdimension/pigment_map.c +++ b/libdimension/pigment_map.c @@ -56,6 +56,13 @@ typedef struct dmnsn_pigment_map_payload { dmnsn_pigment_map_flags flags; } dmnsn_pigment_map_payload; +void +dmnsn_pigment_map_add_color(dmnsn_map *map, double n, dmnsn_color color) +{ + dmnsn_pigment *pigment = dmnsn_new_solid_pigment(color); + dmnsn_add_map_entry(map, n, &pigment); +} + /** Free a pigment_map payload. */ static void dmnsn_delete_pigment_map_payload(void *ptr) diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c index a9d20d7..e9dff2a 100644 --- a/libdimension/tests/render.c +++ b/libdimension/tests/render.c @@ -22,15 +22,9 @@ #include <stdlib.h> #include <stdio.h> -/* - * Test scene - */ -static dmnsn_scene * -dmnsn_new_test_scene(void) +static void +dmnsn_test_scene_set_defaults(dmnsn_scene *scene) { - /* Allocate a new scene */ - dmnsn_scene *scene = dmnsn_new_scene(); - /* Default texture */ scene->default_texture->pigment = dmnsn_new_solid_pigment(dmnsn_black); dmnsn_finish *default_finish = &scene->default_texture->finish; @@ -43,9 +37,19 @@ dmnsn_new_test_scene(void) ) ); - /* Allocate a canvas */ + /* Background color */ + scene->background = dmnsn_clear; +} + +static void +dmnsn_test_scene_add_canvas(dmnsn_scene *scene) +{ scene->canvas = dmnsn_new_canvas(768, 480); +} +static void +dmnsn_test_scene_add_camera(dmnsn_scene *scene) +{ /* Set up the transformation matrix for the perspective camera */ dmnsn_matrix trans = dmnsn_scale_matrix( dmnsn_new_vector( @@ -68,33 +72,38 @@ dmnsn_new_test_scene(void) /* Create a perspective camera */ scene->camera = dmnsn_new_perspective_camera(); scene->camera->trans = trans; +} - /* Background color */ - scene->background = dmnsn_clear; - - /* Sky sphere */ +static void +dmnsn_test_scene_add_sky_sphere(dmnsn_scene *scene) +{ scene->sky_sphere = dmnsn_new_sky_sphere(); dmnsn_pattern *sky_gradient = dmnsn_new_gradient_pattern(dmnsn_y); - dmnsn_map *sky_gradient_color_map = dmnsn_new_color_map(); - dmnsn_add_map_entry(sky_gradient_color_map, 0.0, &dmnsn_orange); + dmnsn_map *sky_gradient_pigment_map = dmnsn_new_pigment_map(); + dmnsn_pigment_map_add_color(sky_gradient_pigment_map, 0.0, dmnsn_orange); dmnsn_color background = dmnsn_color_from_sRGB( dmnsn_new_color5(0.0, 0.1, 0.2, 0.1, 0.0) ); - dmnsn_add_map_entry(sky_gradient_color_map, 0.35, &background); - dmnsn_pigment *sky_pigment - = dmnsn_new_color_map_pigment(sky_gradient, sky_gradient_color_map, + dmnsn_pigment_map_add_color(sky_gradient_pigment_map, 0.35, background); + dmnsn_pigment *sky_pigment = + dmnsn_new_pigment_map_pigment(sky_gradient, sky_gradient_pigment_map, DMNSN_PIGMENT_MAP_SRGB); dmnsn_array_push(scene->sky_sphere->pigments, &sky_pigment); +} - /* Light source */ +static void +dmnsn_test_scene_add_lights(dmnsn_scene *scene) +{ dmnsn_light *light = dmnsn_new_point_light( dmnsn_new_vector(-15.0, 20.0, 10.0), dmnsn_white ); dmnsn_array_push(scene->lights, &light); +} - /* Now make our objects */ - +static void +dmnsn_test_scene_add_hollow_cube(dmnsn_scene *scene) +{ dmnsn_object *cube = dmnsn_new_cube(); cube->trans = dmnsn_rotation_matrix( dmnsn_new_vector(dmnsn_radians(45.0), 0.0, 0.0) @@ -121,9 +130,13 @@ dmnsn_new_test_scene(void) sphere->texture->finish.specular = dmnsn_new_phong(0.2, 40.0); sphere->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.25, 1.25, 1.25)); - dmnsn_object *csg = dmnsn_new_csg_difference(cube, sphere); - dmnsn_array_push(scene->objects, &csg); + dmnsn_object *hollow_cube = dmnsn_new_csg_difference(cube, sphere); + dmnsn_array_push(scene->objects, &hollow_cube); +} +static void +dmnsn_test_scene_add_spike(dmnsn_scene *scene) +{ dmnsn_array *arrow_array = dmnsn_new_array(sizeof(dmnsn_object *)); dmnsn_object *cylinder = dmnsn_new_cone(0.1, 0.1, false); @@ -141,17 +154,17 @@ dmnsn_new_test_scene(void) dmnsn_object *arrow = dmnsn_new_csg_union(arrow_array); dmnsn_delete_array(arrow_array); dmnsn_pattern *gradient = dmnsn_new_gradient_pattern(dmnsn_y); - dmnsn_map *gradient_color_map = dmnsn_new_color_map(); - dmnsn_add_map_entry(gradient_color_map, 0.0, &dmnsn_red); - dmnsn_add_map_entry(gradient_color_map, 1.0/6.0, &dmnsn_orange); - dmnsn_add_map_entry(gradient_color_map, 2.0/6.0, &dmnsn_yellow); - dmnsn_add_map_entry(gradient_color_map, 3.0/6.0, &dmnsn_green); - dmnsn_add_map_entry(gradient_color_map, 4.0/6.0, &dmnsn_blue); - dmnsn_add_map_entry(gradient_color_map, 5.0/6.0, &dmnsn_magenta); - dmnsn_add_map_entry(gradient_color_map, 1.0, &dmnsn_red); + dmnsn_map *gradient_pigment_map = dmnsn_new_pigment_map(); + dmnsn_pigment_map_add_color(gradient_pigment_map, 0.0, dmnsn_red); + dmnsn_pigment_map_add_color(gradient_pigment_map, 1.0/6.0, dmnsn_orange); + dmnsn_pigment_map_add_color(gradient_pigment_map, 2.0/6.0, dmnsn_yellow); + dmnsn_pigment_map_add_color(gradient_pigment_map, 3.0/6.0, dmnsn_green); + dmnsn_pigment_map_add_color(gradient_pigment_map, 4.0/6.0, dmnsn_blue); + dmnsn_pigment_map_add_color(gradient_pigment_map, 5.0/6.0, dmnsn_magenta); + dmnsn_pigment_map_add_color(gradient_pigment_map, 1.0, dmnsn_red); arrow->texture = dmnsn_new_texture(); - arrow->texture->pigment - = dmnsn_new_color_map_pigment(gradient, gradient_color_map, + arrow->texture->pigment = + dmnsn_new_pigment_map_pigment(gradient, gradient_pigment_map, DMNSN_PIGMENT_MAP_SRGB); arrow->texture->trans = @@ -189,9 +202,11 @@ dmnsn_new_test_scene(void) dmnsn_new_vector(dmnsn_radians(-45.0), 0.0, 0.0) ); dmnsn_array_push(scene->objects, &spike); +} - /* Triangle strip */ - +static void +dmnsn_test_scene_add_triangle_strip(dmnsn_scene *scene) +{ dmnsn_array *strip_array = dmnsn_new_array(sizeof(dmnsn_object *)); dmnsn_vector a = dmnsn_zero; dmnsn_vector b = dmnsn_new_vector(0.0, sqrt(3.0)/2.0, 0.5); @@ -222,32 +237,57 @@ dmnsn_new_test_scene(void) dmnsn_delete_array(strip_array); strip->trans = dmnsn_translation_matrix(dmnsn_new_vector(5.0, -2.0, -4.0)); dmnsn_array_push(scene->objects, &strip); +} +static void +dmnsn_test_scene_add_ground(dmnsn_scene *scene) +{ dmnsn_object *plane = dmnsn_new_plane(dmnsn_new_vector(0.0, 1.0, 0.0)); plane->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -2.0, 0.0)); dmnsn_pattern *checker1 = dmnsn_new_checker_pattern(); dmnsn_pattern *checker2 = dmnsn_new_checker_pattern(); - dmnsn_map *checker_color_map = dmnsn_new_color_map(); - dmnsn_add_map_entry(checker_color_map, 0.0, &dmnsn_black); - dmnsn_add_map_entry(checker_color_map, 1.0, &dmnsn_white); - dmnsn_pigment *pigment1 = dmnsn_new_solid_pigment(dmnsn_white); - dmnsn_pigment *pigment2 - = dmnsn_new_color_map_pigment(checker1, checker_color_map, + dmnsn_map *small_map = dmnsn_new_pigment_map(); + dmnsn_pigment_map_add_color(small_map, 0.0, dmnsn_black); + dmnsn_pigment_map_add_color(small_map, 1.0, dmnsn_white); + dmnsn_pigment *small_pigment = + dmnsn_new_pigment_map_pigment(checker1, small_map, DMNSN_PIGMENT_MAP_REGULAR); - pigment2->trans - = dmnsn_scale_matrix(dmnsn_new_vector(1.0/3.0, 1.0/3.0, 1.0/3.0)); - dmnsn_map *checker_pigment_map = dmnsn_new_pigment_map(); - dmnsn_add_map_entry(checker_pigment_map, 0.0, &pigment1); - dmnsn_add_map_entry(checker_pigment_map, 1.0, &pigment2); + small_pigment->trans = + dmnsn_scale_matrix(dmnsn_new_vector(1.0/3.0, 1.0/3.0, 1.0/3.0)); + dmnsn_map *big_map = dmnsn_new_pigment_map(); + dmnsn_pigment_map_add_color(big_map, 0.0, dmnsn_white); + dmnsn_add_map_entry(big_map, 1.0, &small_pigment); plane->texture = dmnsn_new_texture(); - plane->texture->pigment - = dmnsn_new_pigment_map_pigment(checker2, checker_pigment_map, - DMNSN_PIGMENT_MAP_REGULAR); + plane->texture->pigment = + dmnsn_new_pigment_map_pigment(checker2, big_map, DMNSN_PIGMENT_MAP_REGULAR); plane->texture->pigment->quick_color = dmnsn_color_from_sRGB( dmnsn_new_color(1.0, 0.5, 0.75) ); dmnsn_array_push(scene->objects, &plane); +} +static void +dmnsn_test_scene_add_objects(dmnsn_scene *scene) +{ + dmnsn_test_scene_add_hollow_cube(scene); + dmnsn_test_scene_add_spike(scene); + dmnsn_test_scene_add_triangle_strip(scene); + dmnsn_test_scene_add_ground(scene); +} + +/* + * Test scene + */ +static dmnsn_scene * +dmnsn_new_test_scene(void) +{ + dmnsn_scene *scene = dmnsn_new_scene(); + dmnsn_test_scene_set_defaults(scene); + dmnsn_test_scene_add_canvas(scene); + dmnsn_test_scene_add_camera(scene); + dmnsn_test_scene_add_sky_sphere(scene); + dmnsn_test_scene_add_lights(scene); + dmnsn_test_scene_add_objects(scene); return scene; } |