mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 22:45:33 +00:00
Apply the position offset even if the simulation is not performed
because we're too fast.
This commit is contained in:
parent
f388de861d
commit
03b86c232b
4 changed files with 23 additions and 0 deletions
|
@ -190,6 +190,17 @@ void Actor::adjustPosition(const osg::Vec3f& offset)
|
|||
mPositionOffset += offset;
|
||||
}
|
||||
|
||||
void Actor::applyOffsetChange()
|
||||
{
|
||||
if (mPositionOffset.length() == 0)
|
||||
return;
|
||||
mWorldPosition += mPositionOffset;
|
||||
mPosition += mPositionOffset;
|
||||
mPreviousPosition += mPositionOffset;
|
||||
mPositionOffset = osg::Vec3f();
|
||||
mWorldPositionChanged = true;
|
||||
}
|
||||
|
||||
osg::Vec3f Actor::getPosition() const
|
||||
{
|
||||
return mPosition;
|
||||
|
|
|
@ -96,9 +96,16 @@ namespace MWPhysics
|
|||
* Returns true if the new position is different.
|
||||
*/
|
||||
bool setPosition(const osg::Vec3f& position);
|
||||
|
||||
// force set actor position to be as in Ptr::RefData
|
||||
void updatePosition();
|
||||
|
||||
// register a position offset that will be applied during simulation.
|
||||
void adjustPosition(const osg::Vec3f& offset);
|
||||
|
||||
// apply position offset. Can't be called during simulation
|
||||
void applyOffsetChange();
|
||||
|
||||
osg::Vec3f getPosition() const;
|
||||
|
||||
osg::Vec3f getPreviousPosition() const;
|
||||
|
|
|
@ -492,6 +492,7 @@ namespace MWPhysics
|
|||
if (actor->setPosition(actorData.mPosition))
|
||||
{
|
||||
std::scoped_lock lock(mCollisionWorldMutex);
|
||||
actorData.mPosition = actor->getPosition(); // account for potential position change made by script
|
||||
actor->updateCollisionObjectPosition();
|
||||
mCollisionWorld->updateSingleAabb(actor->getCollisionObject());
|
||||
}
|
||||
|
|
|
@ -961,6 +961,10 @@ namespace MWPhysics
|
|||
void ActorFrameData::updatePosition()
|
||||
{
|
||||
mActorRaw->updateWorldPosition();
|
||||
// If physics runs "fast enough", position are interpolated without simulation
|
||||
// By calling this here, we are sure that offsets are applied at least once per frame,
|
||||
// regardless of simulation speed.
|
||||
mActorRaw->applyOffsetChange();
|
||||
mPosition = mActorRaw->getPosition();
|
||||
if (mMoveToWaterSurface)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue