diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-11-18 23:30:38 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-11-18 23:30:38 -0500 |
commit | 5038d1f96af332e474a1e0a076bf5dead6855727 (patch) | |
tree | 128921e3bbdc29046695ac4d9c9fb8d7535bc49a /libdimension/objects.c | |
parent | c576229cc54c0fb963967751281e6a42fc9230ea (diff) | |
download | dimension-5038d1f96af332e474a1e0a076bf5dead6855727.tar.xz |
Translucency support.
Diffstat (limited to 'libdimension/objects.c')
-rw-r--r-- | libdimension/objects.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libdimension/objects.c b/libdimension/objects.c index b5e4a32..845edfa 100644 --- a/libdimension/objects.c +++ b/libdimension/objects.c @@ -73,6 +73,10 @@ dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line) intersection->t = t; intersection->normal = dmnsn_line_point(line, t); intersection->texture = sphere->texture; + + /* Flip the normal if we're inside the sphere */ + if (dmnsn_vector_dot(line.n, intersection->normal) > 0.0) + intersection->normal = dmnsn_vector_negate(intersection->normal); } } @@ -128,7 +132,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); + normal = dmnsn_vector_construct(-copysign(line.n.x, 1.0), 0.0, 0.0); } /* x = 1.0 */ @@ -138,7 +142,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); + normal = dmnsn_vector_construct(-copysign(line.n.x, 1.0), 0.0, 0.0); } } @@ -150,7 +154,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); + normal = dmnsn_vector_construct(0.0, -copysign(line.n.y, 1.0), 0.0); } /* y = 1.0 */ @@ -160,7 +164,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); + normal = dmnsn_vector_construct(0.0, -copysign(line.n.y, 1.0), 0.0); } } @@ -172,7 +176,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); + normal = dmnsn_vector_construct(0.0, 0.0, -copysign(line.n.z, 1.0)); } /* z = 1.0 */ @@ -182,7 +186,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); + normal = dmnsn_vector_construct(0.0, 0.0, -copysign(line.n.z, 1.0)); } } |