Beispiel #1
0
  //---------------------------------------------------------------------------------------------------
  //
  //  Private: CheckAxis
  //
  //  Return true if the axis perpendicular to u = v2 - v1 is a separating axis  (i.e., no overlap)
  //  Therefore, we project to this perpendicular axis
  //
  //  Currently only works with 2D objects on the x-y plane
  //
  //
  //---------------------------------------------------------------------------------------------------
  bool CXDMVoxel::CheckSeparatingAxis( const CXDMVoxel & oVoxel, const CXDMVoxel & oTestVoxel,
                                       const SVector3 &oV1, const SVector3 &oV2) const
  {
    SVector3 oDir = oV2 - oV1;
    oDir.Normalize();

    // rotate 90 degress y <- x, x <- -y
    Float tmp = oDir.m_fY;
    oDir.m_fY = oDir.m_fX;
    oDir.m_fX = - tmp;

    Float fMin = MAX_FLOAT;
    Float fMax = MIN_FLOAT;

    for ( int i = 0; i < 3; i ++ )
    {
      Float fAxisProjection = Dot( oTestVoxel.pVertex[i], oDir );

      if ( fAxisProjection < fMin )
        fMin = fAxisProjection;
      if ( fAxisProjection > fMax )
        fMax = fAxisProjection;
    }
  
    for ( int i = 0; i < 3; i ++ )
    {
      Float fVertex = Dot( oVoxel.pVertex[i], oDir );  
      if( fVertex <= fMax  && fVertex >= fMin )   // if intersecting
      {
        return false;
      }
    }
    return true;
  }
  //--------------------------------------------------------------------------------------------------------
  //
  //  GetAlignRotation
  //  -- Given *UNIT vector* oRef, oVec, return a matrix that rotates oVec -> oRef
  //
  //--------------------------------------------------------------------------------------------------------
  SMatrix3x3 GetAlignmentRotation( const SVector3 &oVecDir, const SVector3 &oRefDir )
  {
    
    SVector3 oAxis  = Cross( oVecDir, oRefDir );
    Float    fAngle = acos( Dot( oVecDir, oRefDir ) );

    oAxis.Normalize();
    SMatrix3x3 oRes;
    oRes.BuildRotationAboutAxis( oAxis, fAngle );
    return oRes;
  }