void CVehicleEntity::UpdateTargetRotation() { // Do we have a target rotation? if(HasTargetRotation()) { // Get our current rotation CVector3 vecCurrentRotation; GetRotation(vecCurrentRotation); // Get the factor of time spent from the interpolation start // to the current time. unsigned long ulCurrentTime = SharedUtility::GetTime(); float fAlpha = Math::Unlerp(m_interp.rot.ulStartTime, ulCurrentTime, m_interp.rot.ulFinishTime); // Don't let it to overcompensate the error fAlpha = Math::Clamp(0.0f, fAlpha, 1.0f); // Get the current error portion to compensate float fCurrentAlpha = (fAlpha - m_interp.rot.fLastAlpha); m_interp.rot.fLastAlpha = fAlpha; // Compensate the error CVector3 vecCompensation = Math::Lerp(CVector3(), fCurrentAlpha, m_interp.rot.vecError); // If we finished compensating the error, finish it for the next pulse if(fAlpha == 1.0f) m_interp.rot.ulFinishTime = 0; // Set the new rotation SetRotation((vecCurrentRotation + vecCompensation), false); } }
void CVehicleEntity::ResetInterpolation() { if(HasTargetPosition()) SetPosition(m_interp.pos.vecTarget, true); if(HasTargetRotation()) SetRotation(m_interp.rot.vecTarget); RemoveTargetPosition(); RemoveTargetRotation(); }
void CVehicleEntity::UpdateTargetPosition() { // Do we have a target position? if(HasTargetPosition()) { // Get our position CVector3 vecCurrentPosition; GetPosition(vecCurrentPosition); // Get the factor of time spent from the interpolation start // to the current time. unsigned long ulCurrentTime = SharedUtility::GetTime(); float fAlpha = Math::Unlerp(m_interp.pos.ulStartTime, ulCurrentTime, m_interp.pos.ulFinishTime); // Don't let it overcompensate the error too much fAlpha = Math::Clamp(0.0f, fAlpha, 1.5f); // Get the current error portion to compensate float fCurrentAlpha = (fAlpha - m_interp.pos.fLastAlpha); m_interp.pos.fLastAlpha = fAlpha; // Apply the error compensation CVector3 vecCompensation = Math::Lerp(CVector3(), fCurrentAlpha, m_interp.pos.vecError); // If we finished compensating the error, finish it for the next pulse if(fAlpha == 1.5f) m_interp.pos.ulFinishTime = 0; // Calculate the new position CVector3 vecNewPosition = (vecCurrentPosition + vecCompensation); // Check if the distance to interpolate is too far if ((vecCurrentPosition - m_interp.pos.vecTarget).Length() > 20) { // Abort position interpolation m_interp.pos.ulFinishTime = 0; vecNewPosition = m_interp.pos.vecTarget; // Abort target interpolation if (HasTargetRotation()) { SetRotation(m_interp.rot.vecTarget); m_interp.rot.ulFinishTime = 0; } g_pCore->GetGraphics()->GetChat()->Print(CString("Intepolate abort")); } // Set our new position SetPosition(vecNewPosition, true, false); } }