mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 08:39:45 +00:00
Unify interface for Actor and Projectile
This commit is contained in:
parent
5009b66ef5
commit
ad7a810a62
6 changed files with 50 additions and 68 deletions
|
@ -23,7 +23,7 @@ namespace MWPhysics
|
|||
Actor::Actor(const MWWorld::Ptr& ptr, const Resource::BulletShape* shape, PhysicsTaskScheduler* scheduler, bool canWaterWalk)
|
||||
: mStandingOnPtr(nullptr), mCanWaterWalk(canWaterWalk), mWalkingOnWater(false)
|
||||
, 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)
|
||||
, mInternalCollisionMode(true)
|
||||
, mExternalCollisionMode(true)
|
||||
|
@ -134,11 +134,6 @@ void Actor::setSimulationPosition(const osg::Vec3f& position)
|
|||
mSimulationPosition = position;
|
||||
}
|
||||
|
||||
osg::Vec3f Actor::getSimulationPosition() const
|
||||
{
|
||||
return mSimulationPosition;
|
||||
}
|
||||
|
||||
osg::Vec3f Actor::getScaledMeshTranslation() const
|
||||
{
|
||||
return mRotation * osg::componentMultiply(mMeshTranslation, mScale);
|
||||
|
@ -192,16 +187,6 @@ void Actor::applyOffsetChange()
|
|||
mWorldPositionChanged = true;
|
||||
}
|
||||
|
||||
osg::Vec3f Actor::getPosition() const
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
osg::Vec3f Actor::getPreviousPosition() const
|
||||
{
|
||||
return mPreviousPosition;
|
||||
}
|
||||
|
||||
void Actor::setRotation(osg::Quat quat)
|
||||
{
|
||||
std::scoped_lock lock(mPositionMutex);
|
||||
|
@ -294,16 +279,6 @@ bool Actor::skipCollisions()
|
|||
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
|
||||
{
|
||||
const float halfZ = getHalfExtents().z();
|
||||
|
|
|
@ -60,7 +60,6 @@ namespace MWPhysics
|
|||
* to account for e.g. scripted movements
|
||||
*/
|
||||
void setSimulationPosition(const osg::Vec3f& position);
|
||||
osg::Vec3f getSimulationPosition() const;
|
||||
|
||||
void updateCollisionObjectPosition();
|
||||
|
||||
|
@ -95,10 +94,6 @@ namespace MWPhysics
|
|||
// apply position offset. Can't be called during simulation
|
||||
void applyOffsetChange();
|
||||
|
||||
osg::Vec3f getPosition() const;
|
||||
|
||||
osg::Vec3f getPreviousPosition() const;
|
||||
|
||||
/**
|
||||
* 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,
|
||||
|
@ -163,9 +158,6 @@ namespace MWPhysics
|
|||
|
||||
bool skipCollisions();
|
||||
|
||||
void setVelocity(osg::Vec3f velocity);
|
||||
osg::Vec3f velocity();
|
||||
|
||||
bool canMoveToWaterSurface(float waterlevel, const btCollisionWorld* world) const;
|
||||
|
||||
private:
|
||||
|
@ -193,11 +185,7 @@ namespace MWPhysics
|
|||
osg::Quat mRotation;
|
||||
|
||||
osg::Vec3f mScale;
|
||||
osg::Vec3f mSimulationPosition;
|
||||
osg::Vec3f mPosition;
|
||||
osg::Vec3f mPreviousPosition;
|
||||
osg::Vec3f mPositionOffset;
|
||||
osg::Vec3f mVelocity;
|
||||
bool mWorldPositionChanged;
|
||||
bool mSkipCollisions;
|
||||
bool mSkipSimulation;
|
||||
|
|
|
@ -546,7 +546,7 @@ namespace MWPhysics
|
|||
}
|
||||
else if (const auto projectile = std::dynamic_pointer_cast<Projectile>(ptr))
|
||||
{
|
||||
projectile->commitPositionChange();
|
||||
projectile->updateCollisionObjectPosition();
|
||||
mCollisionWorld->updateSingleAabb(projectile->getCollisionObject());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,14 +31,15 @@ Projectile::Projectile(const MWWorld::Ptr& caster, const osg::Vec3f& position, f
|
|||
mCollisionObject->setCollisionShape(mShape.get());
|
||||
mCollisionObject->setUserPointer(this);
|
||||
|
||||
setPosition(position);
|
||||
mPosition = position;
|
||||
mPreviousPosition = position;
|
||||
setCaster(caster);
|
||||
|
||||
const int collisionMask = CollisionType_World | CollisionType_HeightMap |
|
||||
CollisionType_Actor | CollisionType_Door | CollisionType_Water | CollisionType_Projectile;
|
||||
mTaskScheduler->addCollisionObject(mCollisionObject.get(), CollisionType_Projectile, collisionMask);
|
||||
|
||||
commitPositionChange();
|
||||
updateCollisionObjectPosition();
|
||||
}
|
||||
|
||||
Projectile::~Projectile()
|
||||
|
@ -48,29 +49,12 @@ Projectile::~Projectile()
|
|||
mTaskScheduler->removeCollisionObject(mCollisionObject.get());
|
||||
}
|
||||
|
||||
void Projectile::commitPositionChange()
|
||||
void Projectile::updateCollisionObjectPosition()
|
||||
{
|
||||
std::scoped_lock lock(mMutex);
|
||||
if (mTransformUpdatePending)
|
||||
{
|
||||
auto& trans = mCollisionObject->getWorldTransform();
|
||||
trans.setOrigin(Misc::Convert::toBullet(mPosition));
|
||||
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;
|
||||
auto& trans = mCollisionObject->getWorldTransform();
|
||||
trans.setOrigin(Misc::Convert::toBullet(mPosition));
|
||||
mCollisionObject->setWorldTransform(trans);
|
||||
}
|
||||
|
||||
void Projectile::hit(const btCollisionObject* target, btVector3 pos, btVector3 normal)
|
||||
|
|
|
@ -36,10 +36,7 @@ namespace MWPhysics
|
|||
|
||||
btConvexShape* getConvexShape() const { return mConvexShape; }
|
||||
|
||||
void commitPositionChange();
|
||||
|
||||
void setPosition(const osg::Vec3f& position);
|
||||
osg::Vec3f getPosition() const;
|
||||
void updateCollisionObjectPosition();
|
||||
|
||||
bool isActive() const
|
||||
{
|
||||
|
@ -80,13 +77,11 @@ namespace MWPhysics
|
|||
std::unique_ptr<btCollisionShape> mShape;
|
||||
btConvexShape* mConvexShape;
|
||||
|
||||
bool mTransformUpdatePending;
|
||||
bool mHitWater;
|
||||
std::atomic<bool> mActive;
|
||||
MWWorld::Ptr mCaster;
|
||||
const btCollisionObject* mCasterColObj;
|
||||
const btCollisionObject* mHitTarget;
|
||||
osg::Vec3f mPosition;
|
||||
btVector3 mHitPosition;
|
||||
btVector3 mHitNormal;
|
||||
|
||||
|
|
|
@ -30,9 +30,49 @@ namespace MWPhysics
|
|||
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:
|
||||
MWWorld::Ptr mPtr;
|
||||
std::unique_ptr<btCollisionObject> mCollisionObject;
|
||||
osg::Vec3f mVelocity;
|
||||
osg::Vec3f mSimulationPosition;
|
||||
osg::Vec3f mPosition;
|
||||
osg::Vec3f mPreviousPosition;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue