in SphereMode::Hit added a check on the sphere intersection, if no intersection, calculating distance could generate a NAN exception

This commit is contained in:
Marco Callieri 2005-07-15 16:39:30 +00:00
parent 8ca165bb98
commit bf23eca7be
1 changed files with 13 additions and 7 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.13 2005/06/29 15:22:26 callieri
changed the name of some intersection functions to avoid ambiguity
Revision 1.12 2005/02/11 11:44:07 tommyfranken Revision 1.12 2005/02/11 11:44:07 tommyfranken
Trackball translation corrected Trackball translation corrected
@ -225,16 +228,19 @@ Point3f SphereMode::Hit(Trackball *tb, const Point3f &p) {
IntersectionLinePlane<float>(vp, ln, hitPlane); IntersectionLinePlane<float>(vp, ln, hitPlane);
Sphere3f sphere(tb->center,tb->radius); Sphere3f sphere(tb->center,tb->radius);
bool resSp = IntersectionLineSphere<float>(sphere, ln, hitSphere1, hitSphere2); bool resSp = IntersectionLineSphere<float>(sphere, ln, hitSphere1, hitSphere2);
if(Distance(viewpoint,hitSphere1)<Distance(viewpoint,hitSphere2)) if(resSp == true)
hitSphere=hitSphere1; {
else hitSphere=hitSphere2; if(Distance(viewpoint,hitSphere1)<Distance(viewpoint,hitSphere2))
hitSphere=hitSphere1;
else hitSphere=hitSphere2;
}
/*float dl=*/Distance(ln,tb->center); /*float dl=*/Distance(ln,tb->center);
bool resHp = HitHyper(tb->center, tb->radius, viewpoint, vp, hitPlane, hitHyper) ; bool resHp = HitHyper(tb->center, tb->radius, viewpoint, vp, hitPlane, hitHyper) ;
// four cases // four cases
// 1) Degenerate line tangent to both sphere and hyperboloid! // 1) Degenerate line tangent to both sphere and hyperboloid!
if((!resSp && !resHp) ) if((!resSp && !resHp) )
{ {
hit=ClosestPoint(ln,tb->center); hit=ClosestPoint(ln,tb->center);
@ -250,7 +256,7 @@ Point3f SphereMode::Hit(Trackball *tb, const Point3f &p) {
if(angleDeg<45) return hitSphere; if(angleDeg<45) return hitSphere;
else return hitHyper; else return hitHyper;
// //
// Codice ORIGINALE PONCHIO // Codice ORIGINALE PONCHIO
//vp.SetOffset(vp.Offset() + Thr); //vp.SetOffset(vp.Offset() + Thr);