//------------------------------------------------------------------------------------ // TestSweptSphere //------------------------------------------------------------------------------------ bool Frustum::TestSweptSphere( Sphere& sphere, Vector& sweepDir ) const { // algorithm -- get all 12 intersection points of the swept sphere with the view frustum // for all points >0, displace sphere along the sweep driection. if the displaced sphere // is inside the frustum, return TRUE. else, return FALSE float displacements[12]; int cnt = 0; float a, b; bool inFrustum = true; for (int i=0; i<6; i++) { if (SweptSpherePlaneIntersect(a, b, m_pSides[i], sphere, sweepDir)) { if (a>=0.f) displacements[cnt++] = a; if (b>=0.f) displacements[cnt++] = b; } } for (int i=0; i<cnt; i++) { Sphere displacedSphere(sphere); displacedSphere.m_vCenter += sweepDir * displacements[i]; displacedSphere.m_fRadius *= 1.1f; if (Collision(&displacedSphere) != ECT_In) return false; } return inFrustum; } // TestSweptSphere
bool U2Culler::TestSweptSphere(const U2SphereBV *sphereBV, const D3DXVECTOR3 *sweepDir) const { // algorithm -- get all 12 intersection points of the swept sphere with the view frustum // for all points >0, displace sphere along the sweep driection. if the displaced sphere // is inside the frustum, return TRUE. else, return FALSE float displacements[12]; int cnt = 0; float a,b; bool inFrustum = false; for (int i = 0; i < 6; i++) { if ( SweptSpherePlaneIntersect(a, b, m_aPlanes[i], sphereBV, sweepDir)) { if (a >= 0.f) displacements[cnt++] = a; if (b >= 0.f) displacements[cnt++] = b; } } for (int i = 0; i < cnt; i++) { /* U2SphereBV displacedSphere(*sphereBV); displacedSphere.SetCenter( displacedSphere.GetCenter() + (*sweepDir) * displacements[i] ); displacedSphere.SetRadius( displacedSphere.GetRadius() * 1.1f ); inFrustum |= this->IsVisible(&displacedSphere);*/ } return inFrustum; }
bool Frustum::TestSweptSphere( const SVector3& pos, float radius, const SVector3& sweepDir ) const { // algorithm -- get all 12 intersection points of the swept sphere with the view frustum // for all points >0, displace sphere along the sweep direction. if the displaced sphere // is inside the frustum, return true. else, return false float displacements[12]; int cnt = 0; float a, b; bool inFrustum = false; for (int i=0; i<6; i++) { if (SweptSpherePlaneIntersect(a, b, camPlanes[i], pos, radius, sweepDir)) { if (a>=0.f) displacements[cnt++] = a; if (b>=0.f) displacements[cnt++] = b; } } for (int i=0; i<cnt; i++) { SVector3 displPos = pos + sweepDir * displacements[i]; float displRadius = radius * 1.1f; inFrustum |= TestSphere( displPos, displRadius ); } return inFrustum; }