//----------------------------------------------------------------------------- // Purpose: // GetLocalTime() is the objects local current time // Input : destTime - new time that is being moved to // moveTime - amount of time to be advanced this frame // Output : float - the actual amount of time to move (usually moveTime) //----------------------------------------------------------------------------- float CBaseMoveBehavior::SetObjectPhysicsVelocity( float moveTime ) { // make sure we have a valid set up if ( !m_pCurrentKeyFrame || !m_pTargetKeyFrame ) return moveTime; // if we're not moving, we're not moving if ( !IsMoving() ) return moveTime; float destTime = moveTime + GetLocalTime(); // work out where we want to be, using destTime m_flTimeIntoFrame = destTime - m_flAnimStartTime; float newTime = (destTime - m_flAnimStartTime) / (m_flAnimEndTime - m_flAnimStartTime); Vector newPos; QAngle newAngles; IPositionInterpolator *pInterp = GetPositionInterpolator( m_iPositionInterpolator ); if( pInterp ) { // setup key frames pInterp->SetKeyPosition( -1, m_pPreKeyFrame->m_Origin ); Motion_SetKeyAngles( -1, m_pPreKeyFrame->m_qAngle ); pInterp->SetKeyPosition( 0, m_pCurrentKeyFrame->m_Origin ); Motion_SetKeyAngles( 0, m_pCurrentKeyFrame->m_qAngle ); pInterp->SetKeyPosition( 1, m_pTargetKeyFrame->m_Origin ); Motion_SetKeyAngles( 1, m_pTargetKeyFrame->m_qAngle ); pInterp->SetKeyPosition( 2, m_pPostKeyFrame->m_Origin ); Motion_SetKeyAngles( 2, m_pPostKeyFrame->m_qAngle ); // find new interpolated position & rotation pInterp->InterpolatePosition( newTime, newPos ); } else { newPos.Init(); } Quaternion qRot; Motion_InterpolateRotation( newTime, m_iRotationInterpolator, qRot ); QuaternionAngles( qRot, newAngles ); // find our velocity vector (newPos - currentPos) and scale velocity vector according to the movetime float oneOnMoveTime = 1 / moveTime; SetAbsVelocity( (newPos - GetLocalOrigin()) * oneOnMoveTime ); SetLocalAngularVelocity( (newAngles - GetLocalAngles()) * oneOnMoveTime ); return moveTime; }
//----------------------------------------------------------------------------- // Purpose: calculates the position of the animating object between two keyframes // Input : currentKey - // pPrevKey - // partialTime - // newOrigin - // newAngles - // posInterpolator - // rotInterpolator - //----------------------------------------------------------------------------- void CMapAnimator::GetAnimationAtTime( CMapKeyFrame *currentKey, CMapKeyFrame *pPrevKey, float partialTime, Vector& newOrigin, Quaternion &newAngles, int posInterpolator, int rotInterpolator ) { // calculate the proportion of time to be spent on this keyframe float animTime; if ( currentKey->MoveTime() < 0.01 ) { animTime = 1.0f; } else { animTime = partialTime / currentKey->MoveTime(); } ASSERT( animTime >= 0.0f && animTime <= 1.0f ); IPositionInterpolator *pInterp = currentKey->SetupPositionInterpolator( posInterpolator ); // setup interpolation keyframes Vector keyOrigin; Quaternion keyAngles; pPrevKey->GetOrigin( keyOrigin ); pPrevKey->GetQuatAngles( keyAngles ); pInterp->SetKeyPosition( -1, keyOrigin ); Motion_SetKeyAngles ( -1, keyAngles ); currentKey->GetOrigin( keyOrigin ); currentKey->GetQuatAngles( keyAngles ); pInterp->SetKeyPosition( 0, keyOrigin ); Motion_SetKeyAngles ( 0, keyAngles ); currentKey->NextKeyFrame()->GetOrigin( keyOrigin ); currentKey->NextKeyFrame()->GetQuatAngles( keyAngles ); pInterp->SetKeyPosition( 1, keyOrigin ); Motion_SetKeyAngles ( 1, keyAngles ); currentKey->NextKeyFrame()->NextKeyFrame()->GetOrigin( keyOrigin ); currentKey->NextKeyFrame()->NextKeyFrame()->GetQuatAngles( keyAngles ); pInterp->SetKeyPosition( 2, keyOrigin ); Motion_SetKeyAngles ( 2, keyAngles ); // get our new interpolated position // HACK HACK - Hey Brian, look here!!!! Vector hackOrigin; pInterp->InterpolatePosition( animTime, hackOrigin ); newOrigin[0] = hackOrigin[0]; newOrigin[1] = hackOrigin[1]; newOrigin[2] = hackOrigin[2]; Motion_InterpolateRotation( animTime, rotInterpolator, newAngles ); }