I have made a Dead reckoning scene node animator (simple). How does this check out:
Code: Select all
void CSceneNodeAnimatorDeadReckoning::animateNode(ISceneNode* node, u32 timeMs)
{
core::vector3df oldPos;
core::vector3df nodePos;
core::vector3df newPos;
f32 timeDiff = timeMs - LastTime;
//update actual pos with our actual vel...
oldPos = targetPos;
targetPos = targetPos + ((targetVel / 1000) * timeDiff);
nodePos = node->getPosition();
//... if the node has not converged on the target
if(oldPos != nodePos)
{
//...then interpolate between the node and the target at the speed 'SnapVel' ...
newPos = nodePos.getInterpolated(targetPos,SnapVel * timeDiff);
else
{
// ... otherwise just update position to target position.
newPos = targetPos;
}
node->setPosition(newPos);
//finaly update LastTime
LastTime = timeMs;
}
EDIT : targetPos and targetVel are user settable through a setter function