1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-31 14:36:39 +00:00

Do not store a btTransform into Actor class: reduce its size by 128 bytes

This commit is contained in:
fredzio 2021-07-17 08:54:20 +02:00
parent d30f0f11b4
commit 62ef708910
2 changed files with 11 additions and 10 deletions

View file

@ -147,18 +147,20 @@ void Actor::updateCollisionObjectPosition()
{ {
std::scoped_lock lock(mPositionMutex); std::scoped_lock lock(mPositionMutex);
mShape->setLocalScaling(Misc::Convert::toBullet(mScale)); mShape->setLocalScaling(Misc::Convert::toBullet(mScale));
osg::Vec3f scaledTranslation = mRotation * osg::componentMultiply(mMeshTranslation, mScale); osg::Vec3f newPosition = getScaledMeshTranslation() + mPosition;
osg::Vec3f newPosition = scaledTranslation + mPosition;
mLocalTransform.setOrigin(Misc::Convert::toBullet(newPosition)); auto& trans = mCollisionObject->getWorldTransform();
mLocalTransform.setRotation(Misc::Convert::toBullet(mRotation)); trans.setOrigin(Misc::Convert::toBullet(newPosition));
mCollisionObject->setWorldTransform(mLocalTransform); trans.setRotation(Misc::Convert::toBullet(mRotation));
mCollisionObject->setWorldTransform(trans);
mWorldPositionChanged = false; mWorldPositionChanged = false;
} }
osg::Vec3f Actor::getCollisionObjectPosition() const osg::Vec3f Actor::getCollisionObjectPosition() const
{ {
std::scoped_lock lock(mPositionMutex); std::scoped_lock lock(mPositionMutex);
return Misc::Convert::toOsg(mLocalTransform.getOrigin()); return getScaledMeshTranslation() + mPosition;
} }
bool Actor::setPosition(const osg::Vec3f& position) bool Actor::setPosition(const osg::Vec3f& position)

View file

@ -74,9 +74,6 @@ namespace MWPhysics
*/ */
osg::Vec3f getOriginalHalfExtents() const; osg::Vec3f getOriginalHalfExtents() const;
/// Returns the mesh translation, scaled and rotated as necessary
osg::Vec3f getScaledMeshTranslation() const;
/** /**
* Returns the position of the collision body * Returns the position of the collision body
* @note The collision shape's origin is in its center, so the position returned can be described as center of the actor collision box in world space. * @note The collision shape's origin is in its center, so the position returned can be described as center of the actor collision box in world space.
@ -181,6 +178,9 @@ namespace MWPhysics
void addCollisionMask(int collisionMask); void addCollisionMask(int collisionMask);
int getCollisionMask() const; int getCollisionMask() const;
/// Returns the mesh translation, scaled and rotated as necessary
osg::Vec3f getScaledMeshTranslation() const;
bool mCanWaterWalk; bool mCanWaterWalk;
std::atomic<bool> mWalkingOnWater; std::atomic<bool> mWalkingOnWater;
@ -205,7 +205,6 @@ namespace MWPhysics
bool mWorldPositionChanged; bool mWorldPositionChanged;
bool mSkipCollisions; bool mSkipCollisions;
bool mSkipSimulation; bool mSkipSimulation;
btTransform mLocalTransform;
mutable std::mutex mPositionMutex; mutable std::mutex mPositionMutex;
unsigned int mStuckFrames; unsigned int mStuckFrames;