summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-16 01:16:33 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-16 01:16:33 +0000
commit6b4dc860466ce4794b346533162291046a6ee96c (patch)
tree2ce3f61711ea6a5688462f605a4e5913e1cb7a4e /libdimension
parentc3619e541564d5133a3ccdaeb79588d37d46a3db (diff)
downloaddimension-6b4dc860466ce4794b346533162291046a6ee96c.tar.xz
New C++ wrapper for dmnsn_texture*.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/dimension/object.h1
-rw-r--r--libdimension/object.c18
-rw-r--r--libdimension/objects.c20
-rw-r--r--libdimension/raytrace.c3
4 files changed, 32 insertions, 10 deletions
diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h
index fefb061..c70452d 100644
--- a/libdimension/dimension/object.h
+++ b/libdimension/dimension/object.h
@@ -35,6 +35,7 @@ typedef struct {
const dmnsn_texture *texture;
} dmnsn_intersection;
+/* Intersection allocation cannot fail */
dmnsn_intersection *dmnsn_new_intersection();
void dmnsn_delete_intersection(dmnsn_intersection *intersection);
diff --git a/libdimension/object.c b/libdimension/object.c
index 6b248ff..f10d53d 100644
--- a/libdimension/object.c
+++ b/libdimension/object.c
@@ -21,6 +21,24 @@
#include "dimension.h"
#include <stdlib.h> /* For malloc */
+/* Allocate an intersection - cannot fail */
+dmnsn_intersection *
+dmnsn_new_intersection()
+{
+ dmnsn_intersection *intersection = malloc(sizeof(dmnsn_intersection));
+ if (!intersection) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't allocate an intersection object.");
+ }
+ return intersection;
+}
+
+/* Free an intersection */
+void
+dmnsn_delete_intersection(dmnsn_intersection *intersection)
+{
+ free(intersection);
+}
+
/* Allocate a dummy object */
dmnsn_object *
dmnsn_new_object()
diff --git a/libdimension/objects.c b/libdimension/objects.c
index 780c06b..3c772d1 100644
--- a/libdimension/objects.c
+++ b/libdimension/objects.c
@@ -100,7 +100,7 @@ dmnsn_new_cube()
dmnsn_object *cube = dmnsn_new_object();
if (cube) {
cube->intersection_fn = &dmnsn_cube_intersection_fn;
- cube->inside_fn = &dmnsn_cube_inside_fn;
+ cube->inside_fn = &dmnsn_cube_inside_fn;
}
return cube;
}
@@ -126,7 +126,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
/* x = 1.0 */
t_temp = (1.0 - line.x0.x)/line.n.x;
- p = dmnsn_line_point(line, t);
+ p = dmnsn_line_point(line, t_temp);
if (p.y >= -1.0 && p.y <= 1.0 && p.z >= -1.0 && p.z <= 1.0
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t)) {
t = t_temp;
@@ -136,16 +136,16 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
if (line.n.y != 0.0) {
/* y = -1.0 */
t_temp = (-1.0 - line.x0.y)/line.n.y;
- p = dmnsn_line_point(line, t);
- if (p.y >= -1.0 && p.y <= 1.0 && p.z >= -1.0 && p.z <= 1.0
+ p = dmnsn_line_point(line, t_temp);
+ if (p.x >= -1.0 && p.x <= 1.0 && p.z >= -1.0 && p.z <= 1.0
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t)) {
t = t_temp;
}
/* y = 1.0 */
t_temp = (1.0 - line.x0.y)/line.n.y;
- p = dmnsn_line_point(line, t);
- if (p.y >= -1.0 && p.y <= 1.0 && p.z >= -1.0 && p.z <= 1.0
+ p = dmnsn_line_point(line, t_temp);
+ if (p.x >= -1.0 && p.x <= 1.0 && p.z >= -1.0 && p.z <= 1.0
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t)) {
t = t_temp;
}
@@ -154,16 +154,16 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
if (line.n.z != 0.0) {
/* z = -1.0 */
t_temp = (-1.0 - line.x0.z)/line.n.z;
- p = dmnsn_line_point(line, t);
- if (p.y >= -1.0 && p.y <= 1.0 && p.z >= -1.0 && p.z <= 1.0
+ p = dmnsn_line_point(line, t_temp);
+ if (p.x >= -1.0 && p.x <= 1.0 && p.y >= -1.0 && p.y <= 1.0
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t)) {
t = t_temp;
}
/* z = 1.0 */
t_temp = (1.0 - line.x0.z)/line.n.z;
- p = dmnsn_line_point(line, t);
- if (p.y >= -1.0 && p.y <= 1.0 && p.z >= -1.0 && p.z <= 1.0
+ p = dmnsn_line_point(line, t_temp);
+ if (p.x >= -1.0 && p.x <= 1.0 && p.y >= -1.0 && p.y <= 1.0
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t)) {
t = t_temp;
}
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 75e857c..10f400d 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -248,6 +248,9 @@ dmnsn_raytrace_shoot(dmnsn_scene *scene, dmnsn_color color,
if (intersection) {
color = dmnsn_color_from_XYZ(dmnsn_whitepoint);
}
+
+ /* Delete the intersection */
+ dmnsn_delete_intersection(intersection);
}
return color;