diff --git a/apps/openmw/mwphysics/actor.cpp b/apps/openmw/mwphysics/actor.cpp index 70a718223c..6c7345c031 100644 --- a/apps/openmw/mwphysics/actor.cpp +++ b/apps/openmw/mwphysics/actor.cpp @@ -93,13 +93,13 @@ Actor::Actor(const MWWorld::Ptr& ptr, const Resource::BulletShape* shape, Physic mCollisionObject->setCollisionShape(mShape.get()); mCollisionObject->setUserPointer(this); - updateScale(); + updateScaleUnsafe(); if(!mRotationallyInvariant) - setRotation(mPtr.getRefData().getBaseNode()->getAttitude()); + mRotation = mPtr.getRefData().getBaseNode()->getAttitude(); addCollisionMask(getCollisionMask()); - updateCollisionObjectPosition(); + updateCollisionObjectPositionUnsafe(); } Actor::~Actor() @@ -167,6 +167,11 @@ osg::Vec3f Actor::getScaledMeshTranslation() const void Actor::updateCollisionObjectPosition() { std::scoped_lock lock(mPositionMutex); + updateCollisionObjectPositionUnsafe(); +} + +void Actor::updateCollisionObjectPositionUnsafe() +{ mShape->setLocalScaling(Misc::Convert::toBullet(mScale)); osg::Vec3f newPosition = getScaledMeshTranslation() + mPosition; @@ -228,6 +233,11 @@ bool Actor::isRotationallyInvariant() const void Actor::updateScale() { std::scoped_lock lock(mPositionMutex); + updateScaleUnsafe(); +} + +void Actor::updateScaleUnsafe() +{ float scale = mPtr.getCellRef().getScale(); osg::Vec3f scaleVec(scale,scale,scale); diff --git a/apps/openmw/mwphysics/actor.hpp b/apps/openmw/mwphysics/actor.hpp index f7c3ce1872..1f79729d74 100644 --- a/apps/openmw/mwphysics/actor.hpp +++ b/apps/openmw/mwphysics/actor.hpp @@ -189,7 +189,7 @@ namespace MWPhysics osg::Vec3f mScale; osg::Vec3f mPositionOffset; - bool mWorldPositionChanged; + bool mWorldPositionChanged = false; bool mSkipSimulation = true; mutable std::mutex mPositionMutex; @@ -207,6 +207,10 @@ namespace MWPhysics Actor(const Actor&); Actor& operator=(const Actor&); + + inline void updateScaleUnsafe(); + + inline void updateCollisionObjectPositionUnsafe(); }; }