diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-09-12 23:40:03 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-09-12 23:40:03 -0400 |
commit | 4bfa19e5a0b426ea6ec99dfebaeb35e507136b74 (patch) | |
tree | e12c243d430f146e1c405502295281839805444e | |
parent | e77371bdbf6f9a14d0cf82b317ca6022f3b00bf7 (diff) | |
download | dimension-4bfa19e5a0b426ea6ec99dfebaeb35e507136b74.tar.xz |
Slight cone intersection code improvements.
-rw-r--r-- | libdimension/cone.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/libdimension/cone.c b/libdimension/cone.c index 2cd5c8a..4d4e2cb 100644 --- a/libdimension/cone.c +++ b/libdimension/cone.c @@ -46,7 +46,7 @@ dmnsn_cone_intersection_fn(const dmnsn_object *cone, dmnsn_line l, poly[1] = 2.0*(l.n.x*l.x0.x + l.n.z*l.x0.z) - l.n.y*(r2 - r1)*(l.x0.y*(r2 - r1) + r2 + r1)/2.0; poly[0] = l.x0.x*l.x0.x + l.x0.z*l.x0.z - - (l.x0.y*(r2 - r1) + r2 + r1)*(l.x0.y*(r2 - r1) + r2 + r1)/4; + - (l.x0.y*(r2 - r1) + r2 + r1)*(l.x0.y*(r2 - r1) + r2 + r1)/4.0; size_t n = dmnsn_solve_polynomial(poly, 2, x); @@ -65,9 +65,10 @@ dmnsn_cone_intersection_fn(const dmnsn_object *cone, dmnsn_line l, p = dmnsn_line_point(l, t); } - if (t >= 0.0 && p.y > -1.0 && p.y < 1.0) { + if (t >= 0.0 && p.y >= -1.0 && p.y <= 1.0) { + double r = ((r2 - r1)*p.y + r1 + r2)/2.0; dmnsn_vector norm = dmnsn_vector_normalized( - dmnsn_new_vector(p.x, -(r2 - r1)*sqrt(p.x*p.x + p.z*p.z)/2.0, p.z) + dmnsn_new_vector(p.x, -r*(r2 - r1)/2.0, p.z) ); intersection->t = t; intersection->normal = norm; |