//----------------------------------------------------------------// bool USSurface2D::GetTouch ( ZLVec2D& sphereLoc, ZLSurfaceTouch2D& touch ) { // The usual stuff... float dist = ZLDist::PointToPlane2D ( sphereLoc, *this ); if ( dist <= 0.0f ) return false; if ( dist > 1.001f ) return false; // Get the point of first contact on the polygon... ZLVec2D pofcop = this->mNorm; pofcop.Reverse (); pofcop.Add ( sphereLoc ); this->ClampPoint ( pofcop ); ZLVec2D ray = pofcop; ray.Sub ( sphereLoc ); dist = ray.NormSafe (); if ( dist >= touch.mDist ) return false; float dot = ray.Dot ( touch.mFinger ); if ( dot < 0.85f ) return false; // we have a touch... touch.mDist = dist; touch.mPoint = pofcop; touch.mTouch = true; touch.mHit = !touch.mPrevTouch; //touch.mNorm = this->GetNorm (); return true; }
//----------------------------------------------------------------// bool USSurface2D::GetContact ( ZLVec2D& sphereLoc, ZLVec2D& contact, ZLVec2D& norm ) { // The usual stuff... float dist = ZLDist::PointToPlane2D ( sphereLoc, *this ); if ( dist <= 0.0f ) return false; if ( dist > 1.001f ) return false; // Get the point of first contact on the polygon... contact = this->mNorm; contact.Reverse (); contact.Add ( sphereLoc ); this->ClampPoint ( contact ); norm = sphereLoc; norm.Sub ( contact ); dist = norm.NormSafe (); if ( dist > 1.001f ) return false; return true; }