Avoid unnecessary AABB update for rotationally invariant collision shapes

pull/167/head
scrawl 8 years ago
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())
{
mShape.reset(new btCapsuleShapeZ(mHalfExtents.x(), 2*mHalfExtents.z() - 2*mHalfExtents.x()));
mRotationallyInvariant = true;
}
else
{
mShape.reset(new btBoxShape(toBullet(mHalfExtents)));
mRotationallyInvariant = false;
}
mConvexShape = static_cast<btConvexShape*>(mShape.get());
mCollisionObject.reset(new btCollisionObject);
@ -144,6 +149,11 @@ void Actor::updateRotation ()
updateCollisionObjectPosition();
}
bool Actor::isRotationallyInvariant() const
{
return mRotationallyInvariant;
}
void Actor::updateScale()
{
float scale = mPtr.getCellRef().getScale();

@ -72,6 +72,11 @@ namespace MWPhysics
void updateScale();
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
* 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 mWalkingOnWater;
bool mRotationallyInvariant;
std::auto_ptr<btCollisionShape> mShape;
btConvexShape* mConvexShape;

@ -1293,9 +1293,12 @@ namespace MWPhysics
}
ActorMap::iterator foundActor = mActors.find(ptr);
if (foundActor != mActors.end())
{
if (!foundActor->second->isRotationallyInvariant())
{
foundActor->second->updateRotation();
mCollisionWorld->updateSingleAabb(foundActor->second->getCollisionObject());
}
return;
}
}

Loading…
Cancel
Save