mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-22 12:39:59 +00:00
Avoid unnecessary AABB update for rotationally invariant collision shapes
This commit is contained in:
parent
5198fc897d
commit
fb073e5c14
@ -32,9 +32,14 @@ Actor::Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<const Resource::BulletShape>
|
|||||||
if (std::abs(mHalfExtents.x()-mHalfExtents.y())<mHalfExtents.x()*0.05 && mHalfExtents.z() >= mHalfExtents.x())
|
if (std::abs(mHalfExtents.x()-mHalfExtents.y())<mHalfExtents.x()*0.05 && mHalfExtents.z() >= mHalfExtents.x())
|
||||||
{
|
{
|
||||||
mShape.reset(new btCapsuleShapeZ(mHalfExtents.x(), 2*mHalfExtents.z() - 2*mHalfExtents.x()));
|
mShape.reset(new btCapsuleShapeZ(mHalfExtents.x(), 2*mHalfExtents.z() - 2*mHalfExtents.x()));
|
||||||
|
mRotationallyInvariant = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mShape.reset(new btBoxShape(toBullet(mHalfExtents)));
|
mShape.reset(new btBoxShape(toBullet(mHalfExtents)));
|
||||||
|
mRotationallyInvariant = false;
|
||||||
|
}
|
||||||
|
|
||||||
mConvexShape = static_cast<btConvexShape*>(mShape.get());
|
mConvexShape = static_cast<btConvexShape*>(mShape.get());
|
||||||
|
|
||||||
mCollisionObject.reset(new btCollisionObject);
|
mCollisionObject.reset(new btCollisionObject);
|
||||||
@ -144,6 +149,11 @@ void Actor::updateRotation ()
|
|||||||
updateCollisionObjectPosition();
|
updateCollisionObjectPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Actor::isRotationallyInvariant() const
|
||||||
|
{
|
||||||
|
return mRotationallyInvariant;
|
||||||
|
}
|
||||||
|
|
||||||
void Actor::updateScale()
|
void Actor::updateScale()
|
||||||
{
|
{
|
||||||
float scale = mPtr.getCellRef().getScale();
|
float scale = mPtr.getCellRef().getScale();
|
||||||
|
@ -72,6 +72,11 @@ namespace MWPhysics
|
|||||||
void updateScale();
|
void updateScale();
|
||||||
void updateRotation();
|
void updateRotation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the collision shape looks the same no matter how its Z rotated.
|
||||||
|
*/
|
||||||
|
bool isRotationallyInvariant() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set mPosition and mPreviousPosition to the position in the Ptr's RefData. This should be used
|
* Set mPosition and mPreviousPosition to the position in the Ptr's RefData. This should be used
|
||||||
* when an object is "instantly" moved/teleported as opposed to being moved by the physics simulation.
|
* when an object is "instantly" moved/teleported as opposed to being moved by the physics simulation.
|
||||||
@ -155,6 +160,8 @@ namespace MWPhysics
|
|||||||
bool mCanWaterWalk;
|
bool mCanWaterWalk;
|
||||||
bool mWalkingOnWater;
|
bool mWalkingOnWater;
|
||||||
|
|
||||||
|
bool mRotationallyInvariant;
|
||||||
|
|
||||||
std::auto_ptr<btCollisionShape> mShape;
|
std::auto_ptr<btCollisionShape> mShape;
|
||||||
btConvexShape* mConvexShape;
|
btConvexShape* mConvexShape;
|
||||||
|
|
||||||
|
@ -1294,8 +1294,11 @@ namespace MWPhysics
|
|||||||
ActorMap::iterator foundActor = mActors.find(ptr);
|
ActorMap::iterator foundActor = mActors.find(ptr);
|
||||||
if (foundActor != mActors.end())
|
if (foundActor != mActors.end())
|
||||||
{
|
{
|
||||||
foundActor->second->updateRotation();
|
if (!foundActor->second->isRotationallyInvariant())
|
||||||
mCollisionWorld->updateSingleAabb(foundActor->second->getCollisionObject());
|
{
|
||||||
|
foundActor->second->updateRotation();
|
||||||
|
mCollisionWorld->updateSingleAabb(foundActor->second->getCollisionObject());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user