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); } }
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); if (!((vecCurrentPosition - m_interp.pos.vecTarget).Length() <= 3.0 /* maybe adjust this value a bit if we need earlier correction */)) { // Abort position interpolation m_interp.pos.ulFinishTime = 0; vecNewPosition = m_interp.pos.vecTarget; } // Set our new position SetPosition(vecNewPosition, true, false); } }