Example #1
0
 bool cull(const Sphere& sphere) const
 {
   // null spheres are always visible
   if (sphere.isNull())
     return false;
   for(unsigned i=0; i<planes().size(); ++i)
   {
     if ( plane(i).distance(sphere.center()) > sphere.radius() )
       return true;
   }
   return false;
 }
 /** Returns true if a sphere contains the specified sphere. */
 bool includes(const Sphere& other) const
 {
   if (isNull())
     return false;
   else
   if (other.isNull())
     return true;
   else
   {
     real distance = (center() - other.center()).length();
     return radius() >= distance + other.radius();
   }
 }
//-----------------------------------------------------------------------------
void Camera::computeNearFarOptimizedProjMatrix(const Sphere& scene_bounding_sphere)
{
  // near/far clipping planes optimization
  if (!scene_bounding_sphere.isNull())
  {
    // compute the sphere in camera coordinates
    Sphere camera_sphere;
    scene_bounding_sphere.transformed(camera_sphere, viewMatrix());
    mNearPlane = -(camera_sphere.center().z() + camera_sphere.radius() * (Real)1.01);
    mFarPlane  = -(camera_sphere.center().z() - camera_sphere.radius() * (Real)1.01);
    #if 0
      far  = max(far,  (Real)1.0e-5);
      near = max(near, (Real)1.0e-6);
    #else
      // prevents z-thrashing when very large objects are zoomed a lot
      Real ratio = camera_sphere.radius() * (Real)2.01 / (Real)2000.0;
      mNearPlane = max(mNearPlane, ratio*1);
      mFarPlane  = max(mFarPlane,  ratio*2);
    #endif
    // supports only perspective projection matrices
    setProjectionAsPerspective();
  }
}