I'm implementing interpolation for my orientation class, but I'm not getting good results.
I have an Orientation class which contains 2 vectors for positions, the previous and the next one.
My code for checking for updates and getting the interpolation is:
void Game::Update()
{
_currentTime = GetRealTimeInMicroSeconds();
if(_currentTime - _previousTime > _timeToUpdate) //also has a max frameskip here, omitted
{
_elapsedTime += _timeToUpdate;
_previousTime += _timeToUpdate;
}
}
float Time::GetInterpolation()
{
_interpolation = (GetRealTimeInMicroSeconds() - _previousTime) / _timeToUpdate;
return _interpolation; //might need to normalize it
}
And in my engine's update function, I'm just doing this:
myModel->Position->x += 0.002f;
for(unsigned int i = 0; i < _allObjects.size(); i++)
{
_allObjects[i]->_Update();
//This swaps the addresses for the current/previous positions for all objects, and call their regular update function
}
Debugging, I can check the values are being calculated perfectly:
Matrix4x4 Orientation::GetTransformationMatrix(float interpolation)
{
if(interpolationStatus == true) //if true, A is next
{
positionX = positionB.x - ((positionA.x - positionB.x) * interpolation);
}
else //else, B is next
{
positionX = positionA.x - ((positionB.x - positionA.x) * interpolation);
}
//use these values, get the matrix done, return it
}
So at the first update tick, I can see the values being calculated:
positionX = 0 - ((0.002 - 0) * 0.207);
positionX = 0.000414;
But on screen, the effect is noticeably lagging, almost as if it didn't had interpolation at all.
Without interpolation, is bad as well, with this interpolation code it's slightly better, but it's still far worse than having this:
void Game::Render()
{
myModel->Position.x += 0.00001f; //way lower value since this is being called more often
}
The speed is nearly identical from these two values, but the movement is much smoother in the Render() one.
Am I doing something wrong with this interpolation? Is there anything I can do to get it better, smoother movements?