1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 19:49:56 +00:00

Merge branch 'slimfast47' into 'openmw-47'

Like !1024 but targeted at 0.47

See merge request OpenMW/openmw!1045
This commit is contained in:
psi29a 2021-07-23 20:03:07 +00:00
commit 196497a992
7 changed files with 39 additions and 32 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;

View file

@ -27,8 +27,8 @@ namespace MWPhysics
mCollisionObject->setUserPointer(this); mCollisionObject->setUserPointer(this);
setScale(ptr.getCellRef().getScale()); setScale(ptr.getCellRef().getScale());
setRotation(Misc::Convert::toBullet(ptr.getRefData().getBaseNode()->getAttitude())); setRotation(ptr.getRefData().getBaseNode()->getAttitude());
setOrigin(Misc::Convert::toBullet(ptr.getRefData().getPosition().asVec3())); updatePosition();
commitPositionChange(); commitPositionChange();
mTaskScheduler->addCollisionObject(mCollisionObject.get(), collisionType, CollisionType_Actor|CollisionType_HeightMap|CollisionType_Projectile); mTaskScheduler->addCollisionObject(mCollisionObject.get(), collisionType, CollisionType_Actor|CollisionType_HeightMap|CollisionType_Projectile);
@ -51,17 +51,17 @@ namespace MWPhysics
mScaleUpdatePending = true; mScaleUpdatePending = true;
} }
void Object::setRotation(const btQuaternion& quat) void Object::setRotation(const osg::Quat& quat)
{ {
std::unique_lock<std::mutex> lock(mPositionMutex); std::unique_lock<std::mutex> lock(mPositionMutex);
mLocalTransform.setRotation(quat); mRotation = quat;
mTransformUpdatePending = true; mTransformUpdatePending = true;
} }
void Object::setOrigin(const btVector3& vec) void Object::updatePosition()
{ {
std::unique_lock<std::mutex> lock(mPositionMutex); std::unique_lock<std::mutex> lock(mPositionMutex);
mLocalTransform.setOrigin(vec); mPosition = mPtr.getRefData().getPosition().asVec3();
mTransformUpdatePending = true; mTransformUpdatePending = true;
} }
@ -75,7 +75,10 @@ namespace MWPhysics
} }
if (mTransformUpdatePending) if (mTransformUpdatePending)
{ {
mCollisionObject->setWorldTransform(mLocalTransform); btTransform trans;
trans.setOrigin(Misc::Convert::toBullet(mPosition));
trans.setRotation(Misc::Convert::toBullet(mRotation));
mCollisionObject->setWorldTransform(trans);
mTransformUpdatePending = false; mTransformUpdatePending = false;
} }
} }
@ -93,7 +96,10 @@ namespace MWPhysics
btTransform Object::getTransform() const btTransform Object::getTransform() const
{ {
std::unique_lock<std::mutex> lock(mPositionMutex); std::unique_lock<std::mutex> lock(mPositionMutex);
return mLocalTransform; btTransform trans;
trans.setOrigin(Misc::Convert::toBullet(mPosition));
trans.setRotation(Misc::Convert::toBullet(mRotation));
return trans;
} }
bool Object::isSolid() const bool Object::isSolid() const

View file

@ -16,7 +16,6 @@ namespace Resource
} }
class btCollisionObject; class btCollisionObject;
class btQuaternion;
class btVector3; class btVector3;
namespace MWPhysics namespace MWPhysics
@ -31,8 +30,8 @@ namespace MWPhysics
const Resource::BulletShapeInstance* getShapeInstance() const; const Resource::BulletShapeInstance* getShapeInstance() const;
void setScale(float scale); void setScale(float scale);
void setRotation(const btQuaternion& quat); void setRotation(const osg::Quat& quat);
void setOrigin(const btVector3& vec); void updatePosition();
void commitPositionChange(); void commitPositionChange();
btCollisionObject* getCollisionObject(); btCollisionObject* getCollisionObject();
const btCollisionObject* getCollisionObject() const; const btCollisionObject* getCollisionObject() const;
@ -51,7 +50,8 @@ namespace MWPhysics
std::map<int, osg::NodePath> mRecIndexToNodePath; std::map<int, osg::NodePath> mRecIndexToNodePath;
bool mSolid; bool mSolid;
btVector3 mScale; btVector3 mScale;
btTransform mLocalTransform; osg::Vec3f mPosition;
osg::Quat mRotation;
bool mScaleUpdatePending; bool mScaleUpdatePending;
bool mTransformUpdatePending; bool mTransformUpdatePending;
mutable std::mutex mPositionMutex; mutable std::mutex mPositionMutex;

View file

@ -630,7 +630,7 @@ namespace MWPhysics
ObjectMap::iterator found = mObjects.find(ptr); ObjectMap::iterator found = mObjects.find(ptr);
if (found != mObjects.end()) if (found != mObjects.end())
{ {
found->second->setRotation(Misc::Convert::toBullet(ptr.getRefData().getBaseNode()->getAttitude())); found->second->setRotation(ptr.getRefData().getBaseNode()->getAttitude());
mTaskScheduler->updateSingleAabb(found->second); mTaskScheduler->updateSingleAabb(found->second);
return; return;
} }
@ -651,7 +651,7 @@ namespace MWPhysics
ObjectMap::iterator found = mObjects.find(ptr); ObjectMap::iterator found = mObjects.find(ptr);
if (found != mObjects.end()) if (found != mObjects.end())
{ {
found->second->setOrigin(Misc::Convert::toBullet(ptr.getRefData().getPosition().asVec3())); found->second->updatePosition();
mTaskScheduler->updateSingleAabb(found->second); mTaskScheduler->updateSingleAabb(found->second);
return; return;
} }

View file

@ -3,14 +3,11 @@
#include <BulletCollision/CollisionShapes/btSphereShape.h> #include <BulletCollision/CollisionShapes/btSphereShape.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h> #include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <LinearMath/btVector3.h>
#include <components/misc/convert.hpp> #include <components/misc/convert.hpp>
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "collisiontype.hpp" #include "collisiontype.hpp"
#include "memory"
#include "mtphysics.hpp" #include "mtphysics.hpp"
#include "projectile.hpp" #include "projectile.hpp"
@ -55,7 +52,9 @@ void Projectile::commitPositionChange()
std::scoped_lock lock(mMutex); std::scoped_lock lock(mMutex);
if (mTransformUpdatePending) if (mTransformUpdatePending)
{ {
mCollisionObject->setWorldTransform(mLocalTransform); auto& trans = mCollisionObject->getWorldTransform();
trans.setOrigin(Misc::Convert::toBullet(mPosition));
mCollisionObject->setWorldTransform(trans);
mTransformUpdatePending = false; mTransformUpdatePending = false;
} }
} }
@ -63,14 +62,14 @@ void Projectile::commitPositionChange()
void Projectile::setPosition(const osg::Vec3f &position) void Projectile::setPosition(const osg::Vec3f &position)
{ {
std::scoped_lock lock(mMutex); std::scoped_lock lock(mMutex);
mLocalTransform.setOrigin(Misc::Convert::toBullet(position)); mPosition = position;
mTransformUpdatePending = true; mTransformUpdatePending = true;
} }
osg::Vec3f Projectile::getPosition() const osg::Vec3f Projectile::getPosition() const
{ {
std::scoped_lock lock(mMutex); std::scoped_lock lock(mMutex);
return Misc::Convert::toOsg(mLocalTransform.getOrigin()); return mPosition;
} }
bool Projectile::canTraverseWater() const bool Projectile::canTraverseWater() const

View file

@ -6,12 +6,13 @@
#include <mutex> #include <mutex>
#include <optional> #include <optional>
#include <LinearMath/btVector3.h>
#include "ptrholder.hpp" #include "ptrholder.hpp"
class btCollisionObject; class btCollisionObject;
class btCollisionShape; class btCollisionShape;
class btConvexShape; class btConvexShape;
class btVector3;
namespace osg namespace osg
{ {
@ -76,7 +77,6 @@ namespace MWPhysics
btConvexShape* mConvexShape; btConvexShape* mConvexShape;
std::unique_ptr<btCollisionObject> mCollisionObject; std::unique_ptr<btCollisionObject> mCollisionObject;
btTransform mLocalTransform;
bool mTransformUpdatePending; bool mTransformUpdatePending;
bool mCanCrossWaterSurface; bool mCanCrossWaterSurface;
bool mCrossedWaterSurface; bool mCrossedWaterSurface;
@ -84,6 +84,7 @@ namespace MWPhysics
MWWorld::Ptr mCaster; MWWorld::Ptr mCaster;
MWWorld::Ptr mHitTarget; MWWorld::Ptr mHitTarget;
std::optional<btVector3> mWaterHitPosition; std::optional<btVector3> mWaterHitPosition;
osg::Vec3f mPosition;
btVector3 mHitPosition; btVector3 mHitPosition;
btVector3 mHitNormal; btVector3 mHitNormal;