summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-11-09 10:53:41 -0500
committerTavian Barnes <tavianator@gmail.com>2009-11-09 10:53:41 -0500
commite7c3459f8eba5db5704632f927a4168467521b88 (patch)
treefd18c4f8349e1b7dbe12f934c763e81b4e9ba266
parent69501590eec9c1bc6c7640d17b01ad4d2ce007a5 (diff)
downloaddimension-e7c3459f8eba5db5704632f927a4168467521b88.tar.xz
Add support for lights.
-rw-r--r--libdimension/Makefile.am6
-rw-r--r--libdimension/dimension.h2
-rw-r--r--libdimension/dimension/light.h47
-rw-r--r--libdimension/dimension/lights.h30
-rw-r--r--libdimension/light.c47
-rw-r--r--libdimension/lights.c52
6 files changed, 183 insertions, 1 deletions
diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am
index f11f119..15151d6 100644
--- a/libdimension/Makefile.am
+++ b/libdimension/Makefile.am
@@ -26,6 +26,8 @@ nobase_include_HEADERS = dimension.h \
dimension/error.h \
dimension/geometry.h \
dimension/gl.h \
+ dimension/light.h \
+ dimension/lights.h \
dimension/object.h \
dimension/objects.h \
dimension/pigments.h \
@@ -38,17 +40,19 @@ nobase_include_HEADERS = dimension.h \
lib_LTLIBRARIES = libdimension.la
libdimension_la_SOURCES = $(nobase_include_HEADERS) \
- dimension_impl.h \
camera.c \
cameras.c \
canvas.c \
color.c \
+ dimension_impl.h \
error.c \
geometry.c \
gl.c \
inlines.c \
kD_splay_tree.c \
kD_splay_tree.h \
+ light.c \
+ lights.c \
object.c \
objects.c \
pigments.c \
diff --git a/libdimension/dimension.h b/libdimension/dimension.h
index 4cc29ab..7fc25c5 100644
--- a/libdimension/dimension.h
+++ b/libdimension/dimension.h
@@ -72,6 +72,8 @@ typedef void dmnsn_free_fn(void *ptr);
#include <dimension/pigments.h>
#include <dimension/object.h>
#include <dimension/objects.h>
+#include <dimension/light.h>
+#include <dimension/lights.h>
#include <dimension/camera.h>
#include <dimension/cameras.h>
#include <dimension/scene.h>
diff --git a/libdimension/dimension/light.h b/libdimension/dimension/light.h
new file mode 100644
index 0000000..089af89
--- /dev/null
+++ b/libdimension/dimension/light.h
@@ -0,0 +1,47 @@
+/*************************************************************************
+ * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.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/>. *
+ *************************************************************************/
+
+/*
+ * Lights.
+ */
+
+#ifndef DIMENSION_LIGHT_H
+#define DIMENSION_LIGHT_H
+
+typedef struct dmnsn_light dmnsn_light;
+
+typedef dmnsn_color dmnsn_light_fn(const dmnsn_light *light, dmnsn_vector v);
+
+struct dmnsn_light {
+ /* Origin of light rays */
+ dmnsn_vector x0;
+
+ /* Callbacks */
+ dmnsn_light_fn *light_fn;
+ dmnsn_free_fn *free_fn;
+
+ /* Generic pointer for light info */
+ void *ptr;
+};
+
+dmnsn_light *dmnsn_new_light();
+void dmnsn_delete_light(dmnsn_light *light);
+
+#endif /* DIMENSION_LIGHT_H */
diff --git a/libdimension/dimension/lights.h b/libdimension/dimension/lights.h
new file mode 100644
index 0000000..d12179a
--- /dev/null
+++ b/libdimension/dimension/lights.h
@@ -0,0 +1,30 @@
+/*************************************************************************
+ * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.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/>. *
+ *************************************************************************/
+
+/*
+ * Types of lights.
+ */
+
+#ifndef DIMENSION_LIGHTS_H
+#define DIMENSION_LIGHTS_H
+
+dmnsn_light *dmnsn_new_point_light(dmnsn_vector x0, dmnsn_color color);
+
+#endif /* DIMENSION_LIGHTS_H */
diff --git a/libdimension/light.c b/libdimension/light.c
new file mode 100644
index 0000000..5f0bcfb
--- /dev/null
+++ b/libdimension/light.c
@@ -0,0 +1,47 @@
+/*************************************************************************
+ * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.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/>. *
+ *************************************************************************/
+
+#include "dimension.h"
+#include <stdlib.h> /* For malloc */
+
+/* Allocate a new dummy light */
+dmnsn_light *
+dmnsn_new_light()
+{
+ dmnsn_light *light = malloc(sizeof(dmnsn_light));
+ if (light) {
+ light->light_fn = NULL;
+ light->free_fn = NULL;
+ light->ptr = NULL;
+ }
+ return light;
+}
+
+/* Free a dummy light */
+void
+dmnsn_delete_light(dmnsn_light *light)
+{
+ if (light) {
+ if (light->free_fn) {
+ (*light->free_fn)(light->ptr);
+ }
+ free(light);
+ }
+}
diff --git a/libdimension/lights.c b/libdimension/lights.c
new file mode 100644
index 0000000..9862506
--- /dev/null
+++ b/libdimension/lights.c
@@ -0,0 +1,52 @@
+/*************************************************************************
+ * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.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/>. *
+ *************************************************************************/
+
+#include "dimension.h"
+
+/*
+ * Point light source
+ */
+
+static dmnsn_color
+dmnsn_point_light_fn(const dmnsn_light *light, dmnsn_vector v)
+{
+ return *(dmnsn_color *)light->ptr;
+}
+
+dmnsn_light *
+dmnsn_new_point_light(dmnsn_vector x0, dmnsn_color color)
+{
+ dmnsn_light *light = dmnsn_new_light();
+ if (light) {
+ /* Allocate room for the transformation matrix */
+ dmnsn_color *ptr = malloc(sizeof(dmnsn_color));
+ if (!ptr) {
+ dmnsn_delete_light(light);
+ return NULL;
+ }
+ *ptr = color;
+
+ light->x0 = x0;
+ light->light_fn = &dmnsn_point_light_fn;
+ light->free_fn = &free;
+ light->ptr = ptr;
+ }
+ return light;
+}