summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-09-12 23:40:03 -0400
committerTavian Barnes <tavianator@gmail.com>2011-09-12 23:40:03 -0400
commit4bfa19e5a0b426ea6ec99dfebaeb35e507136b74 (patch)
treee12c243d430f146e1c405502295281839805444e /libdimension
parente77371bdbf6f9a14d0cf82b317ca6022f3b00bf7 (diff)
downloaddimension-4bfa19e5a0b426ea6ec99dfebaeb35e507136b74.tar.xz
Slight cone intersection code improvements.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/cone.c7
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;