bool ContainedBySphere::Intersect(const Ray& ray, const TRANSFORM* pTrans, DBL& rDepth1, DBL& rDepth2, int& rSide1, int& rSide2) const { bool intersects = false; DBL len; BasicRay newRay; if(pTrans != NULL) { MInvTransRay(newRay, ray, pTrans); len = newRay.Direction.length(); newRay.Direction /= len; intersects = Sphere::Intersect(newRay, center, radius * radius, &rDepth1, &rDepth2); rDepth1 /= len; rDepth2 /= len; } else { intersects = Sphere::Intersect(ray, center, radius * radius, &rDepth1, &rDepth2); } return intersects; }
bool Sphere::All_Intersections(const Ray& ray, IStack& Depth_Stack, TraceThreadData *Thread) { Thread->Stats()[Ray_Sphere_Tests]++; if(Do_Ellipsoid) { register int Intersection_Found; DBL Depth1, Depth2, len; Vector3d IPoint; BasicRay New_Ray; // Transform the ray into the ellipsoid's space MInvTransRay(New_Ray, ray, Trans); len = New_Ray.Direction.length(); New_Ray.Direction /= len; Intersection_Found = false; if(Intersect(New_Ray, Center, Sqr(Radius), &Depth1, &Depth2)) { Thread->Stats()[Ray_Sphere_Tests_Succeeded]++; if((Depth1 > DEPTH_TOLERANCE) && (Depth1 < MAX_DISTANCE)) { IPoint = New_Ray.Evaluate(Depth1); MTransPoint(IPoint, IPoint, Trans); if(Clip.empty() || Point_In_Clip(IPoint, Clip, Thread)) { Depth_Stack->push(Intersection(Depth1 / len, IPoint, this)); Intersection_Found = true; } } if((Depth2 > DEPTH_TOLERANCE) && (Depth2 < MAX_DISTANCE)) { IPoint = New_Ray.Evaluate(Depth2); MTransPoint(IPoint, IPoint, Trans); if(Clip.empty() || Point_In_Clip(IPoint, Clip, Thread)) { Depth_Stack->push(Intersection(Depth2 / len, IPoint, this)); Intersection_Found = true; } } } return(Intersection_Found); } else { register int Intersection_Found; DBL Depth1, Depth2; Vector3d IPoint; Intersection_Found = false; if(Intersect(ray, Center, Sqr(Radius), &Depth1, &Depth2)) { Thread->Stats()[Ray_Sphere_Tests_Succeeded]++; if((Depth1 > DEPTH_TOLERANCE) && (Depth1 < MAX_DISTANCE)) { IPoint = ray.Evaluate(Depth1); if(Clip.empty() || Point_In_Clip(IPoint, Clip, Thread)) { Depth_Stack->push(Intersection(Depth1, IPoint, this)); Intersection_Found = true; } } if((Depth2 > DEPTH_TOLERANCE) && (Depth2 < MAX_DISTANCE)) { IPoint = ray.Evaluate(Depth2); if(Clip.empty() || Point_In_Clip(IPoint, Clip, Thread)) { Depth_Stack->push(Intersection(Depth2, IPoint, this)); Intersection_Found = true; } } } return(Intersection_Found); } }