void PxSingleActor::interpolateTick( F32 delta )
{
   Point3F interpPos;
   QuatF interpRot;

   // Interpolate the position based on the delta.
   interpPos.interpolate( mNextPos, mLastPos, delta );

   // Interpolate the rotation based on the delta.
   interpRot.interpolate( mNextRot, mLastRot, delta );

   // Set up the interpolated transform.
   MatrixF interpMat;

   // Set the interpolated position and rotation.
   interpRot.setMatrix( &interpMat );
   interpMat.setPosition( interpPos );

   // Set the transform to the interpolated transform.
   Parent::setTransform( interpMat );
}
Beispiel #2
0
bool ConvexShape::castRay( const Point3F &start, const Point3F &end, RayInfo *info )
{
   if ( mPlanes.empty() )
      return false;   

   const Vector< PlaneF > &planeList = mPlanes;
   const U32 planeCount = planeList.size();  

   F32 t;
   F32 tmin = F32_MAX;
   S32 hitFace = -1;
   Point3F hitPnt, pnt;
   VectorF rayDir( end - start );
   rayDir.normalizeSafe();

   if ( false )
   {
      PlaneF plane( Point3F(0,0,0), Point3F(0,0,1) );
      Point3F sp( 0,0,-1 );
      Point3F ep( 0,0,1 );

      F32 t = plane.intersect( sp, ep );
      Point3F hitPnt;
      hitPnt.interpolate( sp, ep, t );
   }

   for ( S32 i = 0; i < planeCount; i++ )
   {
      // Don't hit the back-side of planes.
      if ( mDot( rayDir, planeList[i] ) >= 0.0f )
         continue;

      t = planeList[i].intersect( start, end );

      if ( t >= 0.0f && t <= 1.0f && t < tmin )
      {
         pnt.interpolate( start, end, t );

         S32 j = 0;
         for ( ; j < planeCount; j++ )
         {
            if ( i == j )
               continue;

            F32 dist = planeList[j].distToPlane( pnt );
            if ( dist > 1.0e-004f )
               break;
         }

         if ( j == planeCount )
         {
            tmin = t;
            hitFace = i;
         }
      }
   }

   if ( hitFace == -1 )
      return false;

   info->face = hitFace;            
   info->material = mMaterialInst;
   info->normal = planeList[ hitFace ];
   info->object = this;
   info->t = tmin;

   //mObjToWorld.mulV( info->normal );

   return true;
}
void ShadowVolumeBSP::splitPoly(SVPoly * poly, const PlaneF & plane, SVPoly ** front, SVPoly ** back)
{
    PlaneF::Side sides[SVPoly::MaxWinding];

    U32 i;
    for(i = 0; i < poly->mWindingCount; i++)
        sides[i] = plane.whichSide(poly->mWinding[i]);

    // create the polys
    (*front) = createPoly();
    (*back) = createPoly();

    // copy the info
    (*front)->mWindingCount = (*back)->mWindingCount = 0;
    (*front)->mPlane = (*back)->mPlane = poly->mPlane;
    (*front)->mTarget = (*back)->mTarget = poly->mTarget;
    (*front)->mSurfaceInfo = (*back)->mSurfaceInfo = poly->mSurfaceInfo;
    (*front)->mShadowVolume = (*back)->mShadowVolume = poly->mShadowVolume;

    //
    for(i = 0; i < poly->mWindingCount; i++)
    {
        U32 j = (i+1) % poly->mWindingCount;

        if(sides[i] == PlaneF::On)
        {
            (*front)->mWinding[(*front)->mWindingCount++] = poly->mWinding[i];
            (*back)->mWinding[(*back)->mWindingCount++] = poly->mWinding[i];
        }
        else if(sides[i] == PlaneF::Front)
        {
            (*front)->mWinding[(*front)->mWindingCount++] = poly->mWinding[i];

            if(sides[j] == PlaneF::Back)
            {
                const Point3F & a = poly->mWinding[i];
                const Point3F & b = poly->mWinding[j];

                F32 t = plane.intersect(a, b);
                AssertFatal(t >=0 && t <= 1, "ShadowVolumeBSP::splitPoly - bad plane intersection");

                Point3F pos;
                pos.interpolate(a, b, t);

                //
                (*front)->mWinding[(*front)->mWindingCount++] =
                    (*back)->mWinding[(*back)->mWindingCount++] = pos;
            }
        }
        else if(sides[i] == PlaneF::Back)
        {
            (*back)->mWinding[(*back)->mWindingCount++] = poly->mWinding[i];

            if(sides[j] == PlaneF::Front)
            {
                const Point3F & a = poly->mWinding[i];
                const Point3F & b = poly->mWinding[j];

                F32 t = plane.intersect(a, b);
                AssertFatal(t >=0 && t <= 1, "ShadowVolumeBSP::splitPoly - bad plane intersection");

                Point3F pos;
                pos.interpolate(a, b, t);

                (*front)->mWinding[(*front)->mWindingCount++] =
                    (*back)->mWinding[(*back)->mWindingCount++] = pos;
            }
        }
    }

    AssertFatal((*front)->mWindingCount && (*back)->mWindingCount, "ShadowVolume::split - invalid split");
}