forked from teamnwah/openmw-tes3coop
[Client] Only apply interpolation when positions don't change too much
This commit is contained in:
parent
22e2135ce1
commit
1f747d4375
2 changed files with 12 additions and 1 deletions
|
@ -65,9 +65,12 @@ void DedicatedActor::move(float dt)
|
||||||
ESM::Position refPos = ptr.getRefData().getPosition();
|
ESM::Position refPos = ptr.getRefData().getPosition();
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
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
|
// 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
|
// the interpolated position will be invalid, causing a slight hopping glitch
|
||||||
if (!hasChangedCell)
|
if (shouldInterpolate && !hasChangedCell)
|
||||||
{
|
{
|
||||||
static const int timeMultiplier = 15;
|
static const int timeMultiplier = 15;
|
||||||
osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier);
|
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();
|
ESM::Position refPos = ptr.getRefData().getPosition();
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
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;
|
static const int timeMultiplier = 15;
|
||||||
osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier);
|
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]);
|
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);
|
MWMechanics::Movement *move = &ptr.getClass().getMovementSettings(ptr);
|
||||||
move->mPosition[0] = direction.pos[0];
|
move->mPosition[0] = direction.pos[0];
|
||||||
|
|
Loading…
Reference in a new issue