set linear/angular velocity to zero when objects are asleep
Thanks to http://code.google.com/p/bullet/issues/detail?id=73 improve performance of btConvexTriangleMeshShape::recalcLocalAabb Thanks to fullmetalcoder, http://code.google.com/p/bullet/issues/detail?id=67#makechanges
This commit is contained in:
@@ -19,9 +19,10 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
|
||||
|
||||
|
||||
btConvexTriangleMeshShape ::btConvexTriangleMeshShape (btStridingMeshInterface* meshInterface)
|
||||
btConvexTriangleMeshShape ::btConvexTriangleMeshShape (btStridingMeshInterface* meshInterface, bool calcAabb)
|
||||
:m_stridingMesh(meshInterface)
|
||||
{
|
||||
if ( calcAabb )
|
||||
recalcLocalAabb();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class btConvexTriangleMeshShape : public btPolyhedralConvexShape
|
||||
class btStridingMeshInterface* m_stridingMesh;
|
||||
|
||||
public:
|
||||
btConvexTriangleMeshShape(btStridingMeshInterface* meshInterface);
|
||||
btConvexTriangleMeshShape(btStridingMeshInterface* meshInterface, bool calcAabb = true);
|
||||
|
||||
class btStridingMeshInterface* getMeshInterface()
|
||||
{
|
||||
@@ -53,3 +53,4 @@ public:
|
||||
#endif //CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -133,6 +133,37 @@ void btPolyhedralConvexShape::recalcLocalAabb()
|
||||
{
|
||||
m_isLocalAabbValid = true;
|
||||
|
||||
#if 1
|
||||
static const btVector3 _directions[] =
|
||||
{
|
||||
btVector3( 1., 0., 0.),
|
||||
btVector3( 0., 1., 0.),
|
||||
btVector3( 0., 0., 1.),
|
||||
btVector3( -1., 0., 0.),
|
||||
btVector3( 0., -1., 0.),
|
||||
btVector3( 0., 0., -1.)
|
||||
};
|
||||
|
||||
btVector3 _supporting[] =
|
||||
{
|
||||
btVector3( 0., 0., 0.),
|
||||
btVector3( 0., 0., 0.),
|
||||
btVector3( 0., 0., 0.),
|
||||
btVector3( 0., 0., 0.),
|
||||
btVector3( 0., 0., 0.),
|
||||
btVector3( 0., 0., 0.)
|
||||
};
|
||||
|
||||
batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
|
||||
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
{
|
||||
m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
|
||||
m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
@@ -143,6 +174,8 @@ void btPolyhedralConvexShape::recalcLocalAabb()
|
||||
tmp = localGetSupportingVertex(vec);
|
||||
m_localAabbMin[i] = tmp[i]-m_collisionMargin;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -489,6 +489,12 @@ void btDiscreteDynamicsWorld::updateActivationState(btScalar timeStep)
|
||||
{
|
||||
if (body->getActivationState() == ACTIVE_TAG)
|
||||
body->setActivationState( WANTS_DEACTIVATION );
|
||||
if (body->getActivationState() == ISLAND_SLEEPING)
|
||||
{
|
||||
body->setAngularVelocity(btVector3(0,0,0));
|
||||
body->setLinearVelocity(btVector3(0,0,0));
|
||||
}
|
||||
|
||||
}
|
||||
} else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user