summaryrefslogtreecommitdiffstats
path: root/libdimension/objects.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-11-09 15:01:22 -0500
committerTavian Barnes <tavianator@gmail.com>2009-11-09 15:01:22 -0500
commit319491781c1389d82897075b6d890e74d82a08a9 (patch)
tree048b36a0fc9451db499f4f6c1d828814130a67fa /libdimension/objects.c
parent1044badd2e625c73eae616f6a0d10479dde54db5 (diff)
downloaddimension-319491781c1389d82897075b6d890e74d82a08a9.tar.xz
Calculate surface normals in intersection callbacks.
Diffstat (limited to 'libdimension/objects.c')
-rw-r--r--libdimension/objects.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/libdimension/objects.c b/libdimension/objects.c
index 721d04d..b5e4a32 100644
--- a/libdimension/objects.c
+++ b/libdimension/objects.c
@@ -71,6 +71,7 @@ dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line)
intersection = dmnsn_new_intersection();
intersection->ray = line;
intersection->t = t;
+ intersection->normal = dmnsn_line_point(line, t);
intersection->texture = sphere->texture;
}
}
@@ -114,7 +115,7 @@ static dmnsn_intersection *
dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
{
double t = -1.0, t_temp;
- dmnsn_vector p;
+ dmnsn_vector p, normal;
dmnsn_intersection *intersection = NULL;
/* Six ray-plane intersection tests (x, y, z) = +/- 1.0 */
@@ -127,6 +128,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
+ normal = dmnsn_vector_construct(-1.0, 0.0, 0.0);
}
/* x = 1.0 */
@@ -136,6 +138,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
+ normal = dmnsn_vector_construct(1.0, 0.0, 0.0);
}
}
@@ -147,6 +150,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
+ normal = dmnsn_vector_construct(0.0, -1.0, 0.0);
}
/* y = 1.0 */
@@ -156,6 +160,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
+ normal = dmnsn_vector_construct(0.0, 1.0, 0.0);
}
}
@@ -167,6 +172,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
+ normal = dmnsn_vector_construct(0.0, 0.0, -1.0);
}
/* z = 1.0 */
@@ -176,6 +182,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
&& t_temp >= 0.0 && (t < 0.0 || t_temp < t))
{
t = t_temp;
+ normal = dmnsn_vector_construct(0.0, 0.0, 1.0);
}
}
@@ -183,6 +190,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line)
intersection = dmnsn_new_intersection();
intersection->ray = line;
intersection->t = t;
+ intersection->normal = normal;
intersection->texture = cube->texture;
}