Original Post
Hey guys, i've been developing a simple 3d engine, at the current moment in time i have my client and server networking systems and i send and recieve player coordinates through packets. I am trying to implement a simple linear interpolation to smooth off "warping" look caused by lag but i am having some trouble with it. This is my linear interpolation functions:
float GetGradient ( float fStartCoord, int iStartTime, float fEndCoord, int iEndTime )
{
if ( ( iStartTime - iEndTime ) == 0 ) return 0.0f;
return ( fEndCoord - fStartCoord ) / ( iEndTime - iStartTime );
}
float Interpolate ( float fStartCoord, int iStartTime, float fEndCoord, int iEndTime, int iCurrentTime, float& fMultiplier )
{
float fResult, fGradient, fIntercept;
fGradient = GetGradient ( fStartCoord, iStartTime, fEndCoord, iEndTime );
fMultiplier = fGradient;
fIntercept = ( fEndCoord - fStartCoord ) - fGradient * ( iEndTime - iStartTime );
fResult = fGradient * ( iCurrentTime - iStartTime) + fIntercept;
return fResult;
}
In my render frame loop i have a while loop which interpolates the X Y Z coordinates based on the last recieved X Y Z coordinates and the time it took to send the packets to the recieving client. At this moment in time, this is all i require. I've looked into Cublic and Quadratic Interpolation but both seem to advance for me at the moment. In my While loop in the render frame, i check if the distance between the Interpolated XYZ coordinates equals to 0 if so it breaks the loop. This is my code for the while loop:
Vector3 vOutput;
float f;
while ( GetDistanceBetween ( vOrigin, vOutput ) != 0.0f )
{
vOutput.fX = Interpolate ( vOriginOld.fX, iStartTime, vOrigin.fX, iEndTime, GetTickCount (), f );
vOutput.fY = Interpolate ( vOriginOld.fY, iStartTime, vOrigin.fY, iEndTime, GetTickCount (), f );
vOutput.fZ = Interpolate ( vOriginOld.fZ, iStartTime, vOrigin.fZ, iEndTime, GetTickCount (), f );
SetOrigin ( vOutput );
}
vOriginOld = vOrigin;
The server does get relative time correctly etc. iEndTime equals to iStartTime plus how long it took to send the packet from client one to client two. The result is the whole game just freezes up and i cannot see the interpolation. Any help you could give me would be greatly appreciated. Thanks.