From 1442cf02d5b24c63ff24b2fc860ea5e0c126d259 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 23 Sep 2009 14:48:57 +0200 Subject: [PATCH] Fixed sphere-ray collision --- geotypes.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/geotypes.cpp b/geotypes.cpp index 8afda26..79f0f7b 100644 --- a/geotypes.cpp +++ b/geotypes.cpp @@ -65,14 +65,13 @@ Punkt3D Sphere::getPos() const { int Sphere::getIntersectionParam(const Ray &ray, float *param1, float *param2) { int numerg; // ax^2 + bx + c = 0 - segl::Punkt3D ehv(1.0f, 1.0f, 1.0f); - float a = ray.dir*ehv; - float b = 2*(ray.pos*ehv + pos*ehv); - float c = ray.pos*ray.pos + pos*pos - 2*(ray.pos*pos) - radius*radius; + float a = ray.dir * ray.dir; + float b = 2 * ray.dir * (ray.pos - pos); + float c = ray.pos * ray.pos - 2 * ray.pos * pos + pos * pos - radius * radius; float p = b/a; float q = c/a; - + std::cout << p << " " << q << std::endl; if((p*p)/4.0f