X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/0e3446ceb6fd6db0cb292671f37b46daaa2aed5b..9fa235f6c621a9737be66359dc6bed473f1823d9:/Sphere.cxx?ds=sidebyside diff --git a/Sphere.cxx b/Sphere.cxx index 3c19afa..6b8d943 100644 --- a/Sphere.cxx +++ b/Sphere.cxx @@ -26,18 +26,25 @@ Sphere::Intersect(Ray& ray) if(t > ray.t()) return false; - if( t < 1e-6 ) + if( t < Epsilon ) { t = (-B+root)/(2.0f*A); - if( t < 1e-6 || t > ray.t()) + if( t < Epsilon || t > ray.t()) return false; } + ray.setT(t); + ray.setHit(this); + return true; } Vec3f Sphere::GetNormal(Ray& ray) { - return Vec3f(); + Vec3f p = ray.origin()+ray.direction()*ray.t(); + Vec3f N = (p-m_center); + N.normalize(); + + return N; }