int FrustumContainsSphere( CD3DCamera * pCamera, Sphere3f pSphere) { // various distances float fDistance; //$$$TEMP get the frustum planes from the camera's CULLINFO Plane3f plane[6]; CULLINFO *cInfo = pCamera->GetCullInfo(); for (int j=0; j<6; j++) { plane[j] = Plane3f( Vector3f(cInfo->planeFrustum[j].a, cInfo->planeFrustum[j].b, cInfo->planeFrustum[j].c), cInfo->planeFrustum[j].d); } // calculate our distances to each of the planes for(int i = 0; i < 6; ++i) { // find the distance to this plane //fDistance = plane[i].GetNormal().Dot(pSphere.Center()) + plane[i].GetNormal().Length(); //fDistance = plane[i].GetNormal().Dot(pSphere.Center()) + plane[i].DistanceTo(pSphere.Center()); fDistance = plane[i].GetNormal().Dot(pSphere.Center()) + plane[i][3]; // if this distance is < -sphere.radius, we are outside if(fDistance < -pSphere.Radius()) return(OUTSIDE); // else if the distance is between +- radius, then we intersect if((float)fabs(fDistance) < pSphere.Radius()) return(INTERSECT); } // otherwise we are fully in view return (INSIDE); }