void CDeathmatchObject::StartMovement ( const CPositionRotationAnimation& a_rMoveAnimation ) { if ( m_pMoveAnimation != NULL ) { _StopMovement ( true ); } if ( a_rMoveAnimation.IsRunning () ) { // Add us to the moving object's manager m_pMovingObjectsManager->Add ( this ); m_pMoveAnimation = new CPositionRotationAnimation ( a_rMoveAnimation ); } else { SPositionRotation positionRotation; a_rMoveAnimation.GetFinalValue ( positionRotation ); SetOrientation ( positionRotation.m_vecPosition, positionRotation.m_vecRotation ); } }
void CObject::Move ( const CPositionRotationAnimation& a_rMoveAnimation ) { // Are we already moving? if ( IsMoving () ) { // Stop our current movement StopMoving (); } if (a_rMoveAnimation.IsRunning() ) { m_pMoveAnimation = new CPositionRotationAnimation ( a_rMoveAnimation ); // Update the values since they might have changed since StopMoving () was called above m_pMoveAnimation->SetSourceValue( SPositionRotation ( m_vecPosition, m_vecRotation ) ); } // If we have a time of 0, move there now else { SPositionRotation positionRotation; a_rMoveAnimation.GetFinalValue ( positionRotation ); SetPosition ( positionRotation.m_vecPosition ); SetRotation ( positionRotation.m_vecRotation ); } }
CPositionRotationAnimation* CPositionRotationAnimation::FromBitStream ( NetBitStreamInterface& a_rBitStream ) { bool bResumeMode; if ( !a_rBitStream.ReadBit ( bResumeMode ) ) { return NULL; } CPositionRotationAnimation* pAnimation = new CPositionRotationAnimation (); //It's up to the caller do delete it if we return it if ( bResumeMode ) { unsigned long ulElaspedTime, ulTimeLeft; if ( !a_rBitStream.ReadCompressed ( ulElaspedTime ) || !a_rBitStream.ReadCompressed ( ulTimeLeft ) ) { delete pAnimation; return NULL; } pAnimation->SetDuration ( ulElaspedTime, ulTimeLeft ); } else { unsigned long ulDuration; if ( !a_rBitStream.ReadCompressed ( ulDuration) ) { delete pAnimation; return NULL; } pAnimation->SetDuration ( ulDuration ); } SPositionSync positionSync; SRotationRadiansSync rotationSync ( true ); if ( !a_rBitStream.Read ( &positionSync ) || !a_rBitStream.Read ( &rotationSync ) ) { delete pAnimation; return NULL; } pAnimation->SetSourceValue ( SPositionRotation ( positionSync.data.vecPosition, rotationSync.data.vecRotation ) ); bool bDeltaRotationMode; if ( !a_rBitStream.Read ( &positionSync ) || !a_rBitStream.ReadBit( bDeltaRotationMode ) || !a_rBitStream.Read ( &rotationSync ) ) { delete pAnimation; return NULL; } pAnimation->SetTargetValue ( SPositionRotation ( positionSync.data.vecPosition, rotationSync.data.vecRotation ), bDeltaRotationMode ); std::string strEasingType; double fEasingPeriod, fEasingAmplitude, fEasingOvershoot; if ( !a_rBitStream.ReadString ( strEasingType) || !a_rBitStream.Read ( fEasingPeriod) || !a_rBitStream.Read ( fEasingAmplitude) || !a_rBitStream.Read ( fEasingOvershoot) ) { delete pAnimation; return NULL; } CEasingCurve::eType easingType = CEasingCurve::GetEasingTypeFromString ( strEasingType ); if ( easingType == CEasingCurve::EASING_INVALID ) { // Server asks for a type I don't know, let's use oldschool linear then easingType = CEasingCurve::Linear; } pAnimation->SetEasing ( easingType, fEasingPeriod, fEasingAmplitude, fEasingOvershoot ); return pAnimation; }