Logo Search packages:      
Sourcecode: 3depict version File versions  Download package

void CameraPerspLookAt::ensureVisible ( const BoundCube b,
unsigned int  face = 3 
) [virtual]

Ensure that the box is visible.

Face is set by cube net 1 2 3 4 5 6 3 is the face directed to the +ve x axis, with the "up"" vector on the 3 aligned to z, so "1" is perpendicular to the Z axis and is "visible"

Reimplemented from CameraPerspective.

Definition at line 635 of file cameras.cpp.

References CameraPerspective::fovAngle, BoundCube::getCentroid(), BoundCube::getSize(), CameraPerspective::nearPlane, Camera::origin, CameraPerspective::recomputeUpDirection(), target, and Camera::upDirection.

{
      //Face is defined by the following net
      //    1
      //  2   3   4
      //    5
      //    6
      //3 is the face directed to the +ve x axis,
      //with the "up"" vector on the 3 aligned to z,
      //so "1" is parallel to the Z axis and is "visible"
      //from the top +ve side of the z axis (at sufficient distance)
      
      //To make the camera visible, we must place the camera
      //outside the box, on the correct face,
      //at sufficient distance to ensure that the face closest
      //to the box is visible at the current FOV.
      
            //Box centroid
      Point3D boxCentroid = boundCube.getCentroid();

      //Vector from box face to camera
      Point3D faceOutVector, tmpUpVec;

      //I labelled a physical box to work this table out.
      float boxToFrontDist,faceSize[2];
      switch(face)
      {
            case 0:
                  faceOutVector = Point3D(0,0,1); 
                  boxToFrontDist=boundCube.getSize(2);
                  tmpUpVec = Point3D(0,1,0);
                  faceSize[0]=boundCube.getSize(0);
                  faceSize[1]=boundCube.getSize(1);
                  break;
            case 1:
                  faceOutVector = Point3D(0,-1,0); 
                  boxToFrontDist=boundCube.getSize(1);
                  tmpUpVec = Point3D(1,0,0);
                  faceSize[0]=boundCube.getSize(1);
                  faceSize[1]=boundCube.getSize(0);
                  break;
            case 2:
                  faceOutVector = Point3D(0,1,0); 
                  boxToFrontDist=boundCube.getSize(1);
                  tmpUpVec = Point3D(0,0,1);
                  faceSize[0]=boundCube.getSize(0);
                  faceSize[1]=boundCube.getSize(2);
                  break;
            case 3:
                  faceOutVector = Point3D(1,0,0); 
                  boxToFrontDist=boundCube.getSize(0);
                  tmpUpVec = Point3D(0,0,1);
                  faceSize[0]=boundCube.getSize(1);
                  faceSize[1]=boundCube.getSize(2);
                  break;
            case 4:
                  faceOutVector = Point3D(0,0,-1); 
                  boxToFrontDist=boundCube.getSize(2);
                  tmpUpVec = Point3D(0,1,0);
                  faceSize[0]=boundCube.getSize(0);
                  faceSize[1]=boundCube.getSize(1);
                  break;
            case 5:
                  faceOutVector = Point3D(-1,0,0); 
                  boxToFrontDist=boundCube.getSize(0);
                  tmpUpVec = Point3D(0,0,1);
                  faceSize[0]=boundCube.getSize(1);
                  faceSize[1]=boundCube.getSize(2);
                  break;
      }     


      //Convert box to front distance to vector from
      //centroid to front face.
      boxToFrontDist/=2.0f;
      float halfMaxFaceDim=std::max(faceSize[0],faceSize[1])/2.0;


      ASSERT(fovAngle > 0);

      //Set camera target to inside box
      target=boxCentroid;

      float outDistance;
      outDistance=boxToFrontDist+halfMaxFaceDim/tan((fovAngle*M_PI/180)/2.0f);
      //Minimal camera distance is given trigonometrically. Add aditional 1 to ensure that nearplane does not clip object
      //then multiply by 1.4 to give a bit of border.
      origin=boxCentroid+faceOutVector*1.4*(1.0+outDistance);


      //Set the default up direction
      upDirection=tmpUpVec;

      //Reset the view direction
      recomputeViewDirection();
      //Ensure up direction orthogonal
      recomputeUpDirection();
      nearPlane = 1;
}


Generated by  Doxygen 1.6.0   Back to index