mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-23 11:42:38 +00:00
Unify interface for Actor and Projectile
This commit is contained in:
parent
5009b66ef5
commit
ad7a810a62
@ -23,7 +23,7 @@ namespace MWPhysics
|
|||||||
Actor::Actor(const MWWorld::Ptr& ptr, const Resource::BulletShape* shape, PhysicsTaskScheduler* scheduler, bool canWaterWalk)
|
Actor::Actor(const MWWorld::Ptr& ptr, const Resource::BulletShape* shape, PhysicsTaskScheduler* scheduler, bool canWaterWalk)
|
||||||
: mStandingOnPtr(nullptr), mCanWaterWalk(canWaterWalk), mWalkingOnWater(false)
|
: mStandingOnPtr(nullptr), mCanWaterWalk(canWaterWalk), mWalkingOnWater(false)
|
||||||
, mMeshTranslation(shape->mCollisionBox.center), mOriginalHalfExtents(shape->mCollisionBox.extents)
|
, mMeshTranslation(shape->mCollisionBox.center), mOriginalHalfExtents(shape->mCollisionBox.extents)
|
||||||
, mVelocity(0,0,0), mStuckFrames(0), mLastStuckPosition{0, 0, 0}
|
, mStuckFrames(0), mLastStuckPosition{0, 0, 0}
|
||||||
, mForce(0.f, 0.f, 0.f), mOnGround(true), mOnSlope(false)
|
, mForce(0.f, 0.f, 0.f), mOnGround(true), mOnSlope(false)
|
||||||
, mInternalCollisionMode(true)
|
, mInternalCollisionMode(true)
|
||||||
, mExternalCollisionMode(true)
|
, mExternalCollisionMode(true)
|
||||||
@ -134,11 +134,6 @@ void Actor::setSimulationPosition(const osg::Vec3f& position)
|
|||||||
mSimulationPosition = position;
|
mSimulationPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Vec3f Actor::getSimulationPosition() const
|
|
||||||
{
|
|
||||||
return mSimulationPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::Vec3f Actor::getScaledMeshTranslation() const
|
osg::Vec3f Actor::getScaledMeshTranslation() const
|
||||||
{
|
{
|
||||||
return mRotation * osg::componentMultiply(mMeshTranslation, mScale);
|
return mRotation * osg::componentMultiply(mMeshTranslation, mScale);
|
||||||
@ -192,16 +187,6 @@ void Actor::applyOffsetChange()
|
|||||||
mWorldPositionChanged = true;
|
mWorldPositionChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Vec3f Actor::getPosition() const
|
|
||||||
{
|
|
||||||
return mPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::Vec3f Actor::getPreviousPosition() const
|
|
||||||
{
|
|
||||||
return mPreviousPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::setRotation(osg::Quat quat)
|
void Actor::setRotation(osg::Quat quat)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(mPositionMutex);
|
std::scoped_lock lock(mPositionMutex);
|
||||||
@ -294,16 +279,6 @@ bool Actor::skipCollisions()
|
|||||||
return std::exchange(mSkipCollisions, false);
|
return std::exchange(mSkipCollisions, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::setVelocity(osg::Vec3f velocity)
|
|
||||||
{
|
|
||||||
mVelocity = velocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::Vec3f Actor::velocity()
|
|
||||||
{
|
|
||||||
return std::exchange(mVelocity, osg::Vec3f());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Actor::canMoveToWaterSurface(float waterlevel, const btCollisionWorld* world) const
|
bool Actor::canMoveToWaterSurface(float waterlevel, const btCollisionWorld* world) const
|
||||||
{
|
{
|
||||||
const float halfZ = getHalfExtents().z();
|
const float halfZ = getHalfExtents().z();
|
||||||
|
@ -60,7 +60,6 @@ namespace MWPhysics
|
|||||||
* to account for e.g. scripted movements
|
* to account for e.g. scripted movements
|
||||||
*/
|
*/
|
||||||
void setSimulationPosition(const osg::Vec3f& position);
|
void setSimulationPosition(const osg::Vec3f& position);
|
||||||
osg::Vec3f getSimulationPosition() const;
|
|
||||||
|
|
||||||
void updateCollisionObjectPosition();
|
void updateCollisionObjectPosition();
|
||||||
|
|
||||||
@ -95,10 +94,6 @@ namespace MWPhysics
|
|||||||
// apply position offset. Can't be called during simulation
|
// apply position offset. Can't be called during simulation
|
||||||
void applyOffsetChange();
|
void applyOffsetChange();
|
||||||
|
|
||||||
osg::Vec3f getPosition() const;
|
|
||||||
|
|
||||||
osg::Vec3f getPreviousPosition() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the half extents of the collision body (scaled according to rendering scale)
|
* Returns the half extents of the collision body (scaled according to rendering scale)
|
||||||
* @note The reason we need this extra method is because of an inconsistency in MW - NPC race scales aren't applied to the collision shape,
|
* @note The reason we need this extra method is because of an inconsistency in MW - NPC race scales aren't applied to the collision shape,
|
||||||
@ -163,9 +158,6 @@ namespace MWPhysics
|
|||||||
|
|
||||||
bool skipCollisions();
|
bool skipCollisions();
|
||||||
|
|
||||||
void setVelocity(osg::Vec3f velocity);
|
|
||||||
osg::Vec3f velocity();
|
|
||||||
|
|
||||||
bool canMoveToWaterSurface(float waterlevel, const btCollisionWorld* world) const;
|
bool canMoveToWaterSurface(float waterlevel, const btCollisionWorld* world) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -193,11 +185,7 @@ namespace MWPhysics
|
|||||||
osg::Quat mRotation;
|
osg::Quat mRotation;
|
||||||
|
|
||||||
osg::Vec3f mScale;
|
osg::Vec3f mScale;
|
||||||
osg::Vec3f mSimulationPosition;
|
|
||||||
osg::Vec3f mPosition;
|
|
||||||
osg::Vec3f mPreviousPosition;
|
|
||||||
osg::Vec3f mPositionOffset;
|
osg::Vec3f mPositionOffset;
|
||||||
osg::Vec3f mVelocity;
|
|
||||||
bool mWorldPositionChanged;
|
bool mWorldPositionChanged;
|
||||||
bool mSkipCollisions;
|
bool mSkipCollisions;
|
||||||
bool mSkipSimulation;
|
bool mSkipSimulation;
|
||||||
|
@ -546,7 +546,7 @@ namespace MWPhysics
|
|||||||
}
|
}
|
||||||
else if (const auto projectile = std::dynamic_pointer_cast<Projectile>(ptr))
|
else if (const auto projectile = std::dynamic_pointer_cast<Projectile>(ptr))
|
||||||
{
|
{
|
||||||
projectile->commitPositionChange();
|
projectile->updateCollisionObjectPosition();
|
||||||
mCollisionWorld->updateSingleAabb(projectile->getCollisionObject());
|
mCollisionWorld->updateSingleAabb(projectile->getCollisionObject());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,14 +31,15 @@ Projectile::Projectile(const MWWorld::Ptr& caster, const osg::Vec3f& position, f
|
|||||||
mCollisionObject->setCollisionShape(mShape.get());
|
mCollisionObject->setCollisionShape(mShape.get());
|
||||||
mCollisionObject->setUserPointer(this);
|
mCollisionObject->setUserPointer(this);
|
||||||
|
|
||||||
setPosition(position);
|
mPosition = position;
|
||||||
|
mPreviousPosition = position;
|
||||||
setCaster(caster);
|
setCaster(caster);
|
||||||
|
|
||||||
const int collisionMask = CollisionType_World | CollisionType_HeightMap |
|
const int collisionMask = CollisionType_World | CollisionType_HeightMap |
|
||||||
CollisionType_Actor | CollisionType_Door | CollisionType_Water | CollisionType_Projectile;
|
CollisionType_Actor | CollisionType_Door | CollisionType_Water | CollisionType_Projectile;
|
||||||
mTaskScheduler->addCollisionObject(mCollisionObject.get(), CollisionType_Projectile, collisionMask);
|
mTaskScheduler->addCollisionObject(mCollisionObject.get(), CollisionType_Projectile, collisionMask);
|
||||||
|
|
||||||
commitPositionChange();
|
updateCollisionObjectPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
Projectile::~Projectile()
|
Projectile::~Projectile()
|
||||||
@ -48,29 +49,12 @@ Projectile::~Projectile()
|
|||||||
mTaskScheduler->removeCollisionObject(mCollisionObject.get());
|
mTaskScheduler->removeCollisionObject(mCollisionObject.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Projectile::commitPositionChange()
|
void Projectile::updateCollisionObjectPosition()
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(mMutex);
|
std::scoped_lock lock(mMutex);
|
||||||
if (mTransformUpdatePending)
|
|
||||||
{
|
|
||||||
auto& trans = mCollisionObject->getWorldTransform();
|
auto& trans = mCollisionObject->getWorldTransform();
|
||||||
trans.setOrigin(Misc::Convert::toBullet(mPosition));
|
trans.setOrigin(Misc::Convert::toBullet(mPosition));
|
||||||
mCollisionObject->setWorldTransform(trans);
|
mCollisionObject->setWorldTransform(trans);
|
||||||
mTransformUpdatePending = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Projectile::setPosition(const osg::Vec3f &position)
|
|
||||||
{
|
|
||||||
std::scoped_lock lock(mMutex);
|
|
||||||
mPosition = position;
|
|
||||||
mTransformUpdatePending = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::Vec3f Projectile::getPosition() const
|
|
||||||
{
|
|
||||||
std::scoped_lock lock(mMutex);
|
|
||||||
return mPosition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Projectile::hit(const btCollisionObject* target, btVector3 pos, btVector3 normal)
|
void Projectile::hit(const btCollisionObject* target, btVector3 pos, btVector3 normal)
|
||||||
|
@ -36,10 +36,7 @@ namespace MWPhysics
|
|||||||
|
|
||||||
btConvexShape* getConvexShape() const { return mConvexShape; }
|
btConvexShape* getConvexShape() const { return mConvexShape; }
|
||||||
|
|
||||||
void commitPositionChange();
|
void updateCollisionObjectPosition();
|
||||||
|
|
||||||
void setPosition(const osg::Vec3f& position);
|
|
||||||
osg::Vec3f getPosition() const;
|
|
||||||
|
|
||||||
bool isActive() const
|
bool isActive() const
|
||||||
{
|
{
|
||||||
@ -80,13 +77,11 @@ namespace MWPhysics
|
|||||||
std::unique_ptr<btCollisionShape> mShape;
|
std::unique_ptr<btCollisionShape> mShape;
|
||||||
btConvexShape* mConvexShape;
|
btConvexShape* mConvexShape;
|
||||||
|
|
||||||
bool mTransformUpdatePending;
|
|
||||||
bool mHitWater;
|
bool mHitWater;
|
||||||
std::atomic<bool> mActive;
|
std::atomic<bool> mActive;
|
||||||
MWWorld::Ptr mCaster;
|
MWWorld::Ptr mCaster;
|
||||||
const btCollisionObject* mCasterColObj;
|
const btCollisionObject* mCasterColObj;
|
||||||
const btCollisionObject* mHitTarget;
|
const btCollisionObject* mHitTarget;
|
||||||
osg::Vec3f mPosition;
|
|
||||||
btVector3 mHitPosition;
|
btVector3 mHitPosition;
|
||||||
btVector3 mHitNormal;
|
btVector3 mHitNormal;
|
||||||
|
|
||||||
|
@ -30,9 +30,49 @@ namespace MWPhysics
|
|||||||
return mCollisionObject.get();
|
return mCollisionObject.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setVelocity(osg::Vec3f velocity)
|
||||||
|
{
|
||||||
|
mVelocity = velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::Vec3f velocity()
|
||||||
|
{
|
||||||
|
return std::exchange(mVelocity, osg::Vec3f());
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSimulationPosition(const osg::Vec3f& position)
|
||||||
|
{
|
||||||
|
mSimulationPosition = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::Vec3f getSimulationPosition() const
|
||||||
|
{
|
||||||
|
return mSimulationPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPosition(const osg::Vec3f& position)
|
||||||
|
{
|
||||||
|
mPreviousPosition = mPosition;
|
||||||
|
mPosition = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::Vec3f getPosition() const
|
||||||
|
{
|
||||||
|
return mPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::Vec3f getPreviousPosition() const
|
||||||
|
{
|
||||||
|
return mPreviousPosition;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MWWorld::Ptr mPtr;
|
MWWorld::Ptr mPtr;
|
||||||
std::unique_ptr<btCollisionObject> mCollisionObject;
|
std::unique_ptr<btCollisionObject> mCollisionObject;
|
||||||
|
osg::Vec3f mVelocity;
|
||||||
|
osg::Vec3f mSimulationPosition;
|
||||||
|
osg::Vec3f mPosition;
|
||||||
|
osg::Vec3f mPreviousPosition;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user