[Client] Only apply interpolation when positions don't change too much

0.6.1
David Cernat 8 years ago
parent 22e2135ce1
commit 1f747d4375

@ -65,9 +65,12 @@ void DedicatedActor::move(float dt)
ESM::Position refPos = ptr.getRefData().getPosition();
MWBase::World *world = MWBase::Environment::get().getWorld();
// Apply interpolation only if the position hasn't changed too much from last time
bool shouldInterpolate = abs(position.pos[0] - refPos.pos[0]) < 4 && abs(position.pos[1] - refPos.pos[1]) < 4 && abs(position.pos[2] - refPos.pos[2]) < 4;
// Don't apply linear interpolation if the DedicatedActor has just gone through a cell change, because
// the interpolated position will be invalid, causing a slight hopping glitch
if (!hasChangedCell)
if (shouldInterpolate && !hasChangedCell)
{
static const int timeMultiplier = 15;
osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier);

@ -94,6 +94,10 @@ void DedicatedPlayer::move(float dt)
ESM::Position refPos = ptr.getRefData().getPosition();
MWBase::World *world = MWBase::Environment::get().getWorld();
// Apply interpolation only if the position hasn't changed too much from last time
bool shouldInterpolate = abs(position.pos[0] - refPos.pos[0]) < 4 && abs(position.pos[1] - refPos.pos[1]) < 4 && abs(position.pos[2] - refPos.pos[2]) < 4;
if (shouldInterpolate)
{
static const int timeMultiplier = 15;
osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier);
@ -103,6 +107,10 @@ void DedicatedPlayer::move(float dt)
world->moveObject(ptr, refPos.pos[0], refPos.pos[1], refPos.pos[2]);
}
else
{
world->moveObject(ptr, position.pos[0], position.pos[1], position.pos[2]);
}
MWMechanics::Movement *move = &ptr.getClass().getMovementSettings(ptr);
move->mPosition[0] = direction.pos[0];

Loading…
Cancel
Save