Iterate only over non-static rigid bodies, instead of all collision objects
http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=18&t=3625 http://code.google.com/p/bullet/issues/detail?id=128 Attempt to fix issue in mesh striding, multiple-mesh-parts were broken.
This commit is contained in:
@@ -23,127 +23,123 @@ btStridingMeshInterface::~btStridingMeshInterface()
|
|||||||
|
|
||||||
void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||||
{
|
{
|
||||||
(void)aabbMin;
|
(void)aabbMin;
|
||||||
(void)aabbMax;
|
(void)aabbMax;
|
||||||
int numtotalphysicsverts = 0;
|
int numtotalphysicsverts = 0;
|
||||||
int part,graphicssubparts = getNumSubParts();
|
int part,graphicssubparts = getNumSubParts();
|
||||||
const unsigned char * vertexbase;
|
const unsigned char * vertexbase;
|
||||||
const unsigned char * indexbase;
|
const unsigned char * indexbase;
|
||||||
int indexstride;
|
int indexstride;
|
||||||
PHY_ScalarType type;
|
PHY_ScalarType type;
|
||||||
PHY_ScalarType gfxindextype;
|
PHY_ScalarType gfxindextype;
|
||||||
int stride,numverts,numtriangles;
|
int stride,numverts,numtriangles;
|
||||||
int gfxindex;
|
int gfxindex;
|
||||||
btVector3 triangle[3];
|
btVector3 triangle[3];
|
||||||
|
|
||||||
btVector3 meshScaling = getScaling();
|
btVector3 meshScaling = getScaling();
|
||||||
|
|
||||||
///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
|
///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
|
||||||
for (part=0;part<graphicssubparts ;part++)
|
for (part=0;part<graphicssubparts ;part++)
|
||||||
{
|
{
|
||||||
getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part);
|
getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part);
|
||||||
numtotalphysicsverts+=numtriangles*3; //upper bound
|
numtotalphysicsverts+=numtriangles*3; //upper bound
|
||||||
|
|
||||||
///unlike that developers want to pass in double-precision meshes in single-precision Bullet build
|
///unlike that developers want to pass in double-precision meshes in single-precision Bullet build
|
||||||
///so disable this feature by default
|
///so disable this feature by default
|
||||||
///see patch http://code.google.com/p/bullet/issues/detail?id=213
|
///see patch http://code.google.com/p/bullet/issues/detail?id=213
|
||||||
|
|
||||||
#ifdef BT_USE_DOUBLE_PRECISION
|
switch (type)
|
||||||
switch (type)
|
{
|
||||||
{
|
case PHY_FLOAT:
|
||||||
case PHY_FLOAT:
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
|
|
||||||
float* graphicsbase;
|
float* graphicsbase;
|
||||||
|
|
||||||
switch (gfxindextype)
|
|
||||||
{
|
|
||||||
case PHY_INTEGER:
|
|
||||||
{
|
|
||||||
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
|
||||||
{
|
|
||||||
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
|
|
||||||
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
|
|
||||||
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
|
|
||||||
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
|
|
||||||
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
|
||||||
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
|
|
||||||
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
|
||||||
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PHY_SHORT:
|
|
||||||
{
|
|
||||||
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
|
||||||
{
|
|
||||||
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
|
|
||||||
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
|
|
||||||
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
|
|
||||||
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
|
|
||||||
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
|
||||||
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
|
|
||||||
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
|
||||||
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef BT_USE_DOUBLE_PRECISION
|
switch (gfxindextype)
|
||||||
case PHY_DOUBLE:
|
{
|
||||||
{
|
case PHY_INTEGER:
|
||||||
double* graphicsbase;
|
{
|
||||||
|
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
||||||
|
{
|
||||||
|
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
|
||||||
|
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
|
||||||
|
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
|
||||||
|
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
|
||||||
|
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
||||||
|
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
|
||||||
|
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
||||||
|
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PHY_SHORT:
|
||||||
|
{
|
||||||
|
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
||||||
|
{
|
||||||
|
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
|
||||||
|
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
|
||||||
|
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
|
||||||
|
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
|
||||||
|
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
||||||
|
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
|
||||||
|
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
||||||
|
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (gfxindextype)
|
case PHY_DOUBLE:
|
||||||
{
|
{
|
||||||
case PHY_INTEGER:
|
double* graphicsbase;
|
||||||
{
|
|
||||||
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
|
||||||
{
|
|
||||||
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
|
|
||||||
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
|
|
||||||
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
|
|
||||||
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
|
|
||||||
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
|
||||||
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
|
|
||||||
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
|
||||||
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PHY_SHORT:
|
|
||||||
{
|
|
||||||
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
|
||||||
{
|
|
||||||
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
|
|
||||||
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
|
|
||||||
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
|
|
||||||
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
|
|
||||||
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
|
||||||
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
|
|
||||||
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
|
||||||
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
btAssert((type == PHY_FLOAT) || (type == PHY_DOUBLE));
|
|
||||||
}
|
|
||||||
#endif //BT_USE_DOUBLE_PRECISION
|
|
||||||
|
|
||||||
unLockReadOnlyVertexBase(part);
|
switch (gfxindextype)
|
||||||
}
|
{
|
||||||
|
case PHY_INTEGER:
|
||||||
|
{
|
||||||
|
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
||||||
|
{
|
||||||
|
unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
|
||||||
|
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
|
||||||
|
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||||
|
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
|
||||||
|
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||||
|
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
|
||||||
|
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||||
|
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PHY_SHORT:
|
||||||
|
{
|
||||||
|
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
||||||
|
{
|
||||||
|
unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
|
||||||
|
graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
|
||||||
|
triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||||
|
graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
|
||||||
|
triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||||
|
graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
|
||||||
|
triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ());
|
||||||
|
callback->internalProcessTriangleIndex(triangle,part,gfxindex);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
btAssert((type == PHY_FLOAT) || (type == PHY_DOUBLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
unLockReadOnlyVertexBase(part);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void btStridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax)
|
void btStridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax)
|
||||||
@@ -174,7 +170,7 @@ void btStridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVecto
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//first calculate the total aabb for all triangles
|
//first calculate the total aabb for all triangles
|
||||||
AabbCalculationCallback aabbCallback;
|
AabbCalculationCallback aabbCallback;
|
||||||
aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
|
aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
|
||||||
aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
|
aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
|
||||||
|
|||||||
@@ -103,23 +103,23 @@ btDiscreteDynamicsWorld::~btDiscreteDynamicsWorld()
|
|||||||
|
|
||||||
void btDiscreteDynamicsWorld::saveKinematicState(btScalar timeStep)
|
void btDiscreteDynamicsWorld::saveKinematicState(btScalar timeStep)
|
||||||
{
|
{
|
||||||
|
///would like to iterate over m_nonStaticRigidBodies, but unfortunately old API allows
|
||||||
|
///to switch status _after_ adding kinematic objects to the world
|
||||||
|
///fix it for Bullet 3.x release
|
||||||
for (int i=0;i<m_collisionObjects.size();i++)
|
for (int i=0;i<m_collisionObjects.size();i++)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj = m_collisionObjects[i];
|
btCollisionObject* colObj = m_collisionObjects[i];
|
||||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||||
if (body)
|
if (body && body->getActivationState() != ISLAND_SLEEPING)
|
||||||
{
|
{
|
||||||
if (body->getActivationState() != ISLAND_SLEEPING)
|
if (body->isKinematicObject())
|
||||||
{
|
{
|
||||||
if (body->isKinematicObject())
|
//to calculate velocities next frame
|
||||||
{
|
body->saveKinematicState(timeStep);
|
||||||
//to calculate velocities next frame
|
}
|
||||||
body->saveKinematicState(timeStep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void btDiscreteDynamicsWorld::debugDrawWorld()
|
void btDiscreteDynamicsWorld::debugDrawWorld()
|
||||||
@@ -217,15 +217,12 @@ void btDiscreteDynamicsWorld::debugDrawWorld()
|
|||||||
void btDiscreteDynamicsWorld::clearForces()
|
void btDiscreteDynamicsWorld::clearForces()
|
||||||
{
|
{
|
||||||
///@todo: iterate over awake simulation islands!
|
///@todo: iterate over awake simulation islands!
|
||||||
for ( int i=0;i<m_collisionObjects.size();i++)
|
for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj = m_collisionObjects[i];
|
btRigidBody* body = m_nonStaticRigidBodies[i];
|
||||||
|
//need to check if next line is ok
|
||||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
//it might break backward compatibility (people applying forces on sleeping objects get never cleared and accumulate on wake-up
|
||||||
if (body)
|
body->clearForces();
|
||||||
{
|
|
||||||
body->clearForces();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,12 +230,10 @@ void btDiscreteDynamicsWorld::clearForces()
|
|||||||
void btDiscreteDynamicsWorld::applyGravity()
|
void btDiscreteDynamicsWorld::applyGravity()
|
||||||
{
|
{
|
||||||
///@todo: iterate over awake simulation islands!
|
///@todo: iterate over awake simulation islands!
|
||||||
for ( int i=0;i<m_collisionObjects.size();i++)
|
for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj = m_collisionObjects[i];
|
btRigidBody* body = m_nonStaticRigidBodies[i];
|
||||||
|
if (body->isActive())
|
||||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
|
||||||
if (body && body->isActive())
|
|
||||||
{
|
{
|
||||||
body->applyGravity();
|
body->applyGravity();
|
||||||
}
|
}
|
||||||
@@ -271,12 +266,10 @@ void btDiscreteDynamicsWorld::synchronizeMotionStates()
|
|||||||
BT_PROFILE("synchronizeMotionStates");
|
BT_PROFILE("synchronizeMotionStates");
|
||||||
{
|
{
|
||||||
//todo: iterate over awake simulation islands!
|
//todo: iterate over awake simulation islands!
|
||||||
for ( int i=0;i<m_collisionObjects.size();i++)
|
for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj = m_collisionObjects[i];
|
btRigidBody* body = m_nonStaticRigidBodies[i];
|
||||||
|
if (body->isActive())
|
||||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
|
||||||
if (body)
|
|
||||||
synchronizeSingleMotionState(body);
|
synchronizeSingleMotionState(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -411,11 +404,10 @@ void btDiscreteDynamicsWorld::internalSingleStepSimulation(btScalar timeStep)
|
|||||||
void btDiscreteDynamicsWorld::setGravity(const btVector3& gravity)
|
void btDiscreteDynamicsWorld::setGravity(const btVector3& gravity)
|
||||||
{
|
{
|
||||||
m_gravity = gravity;
|
m_gravity = gravity;
|
||||||
for ( int i=0;i<m_collisionObjects.size();i++)
|
for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj = m_collisionObjects[i];
|
btRigidBody* body = m_nonStaticRigidBodies[i];
|
||||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
if (body->isActive())
|
||||||
if (body)
|
|
||||||
{
|
{
|
||||||
body->setGravity(gravity);
|
body->setGravity(gravity);
|
||||||
}
|
}
|
||||||
@@ -430,6 +422,7 @@ btVector3 btDiscreteDynamicsWorld::getGravity () const
|
|||||||
|
|
||||||
void btDiscreteDynamicsWorld::removeRigidBody(btRigidBody* body)
|
void btDiscreteDynamicsWorld::removeRigidBody(btRigidBody* body)
|
||||||
{
|
{
|
||||||
|
m_nonStaticRigidBodies.remove(body);
|
||||||
removeCollisionObject(body);
|
removeCollisionObject(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,6 +435,11 @@ void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
|
|||||||
|
|
||||||
if (body->getCollisionShape())
|
if (body->getCollisionShape())
|
||||||
{
|
{
|
||||||
|
if (!body->isStaticObject())
|
||||||
|
{
|
||||||
|
m_nonStaticRigidBodies.push_back(body);
|
||||||
|
}
|
||||||
|
|
||||||
bool isDynamic = !(body->isStaticObject() || body->isKinematicObject());
|
bool isDynamic = !(body->isStaticObject() || body->isKinematicObject());
|
||||||
short collisionFilterGroup = isDynamic? short(btBroadphaseProxy::DefaultFilter) : short(btBroadphaseProxy::StaticFilter);
|
short collisionFilterGroup = isDynamic? short(btBroadphaseProxy::DefaultFilter) : short(btBroadphaseProxy::StaticFilter);
|
||||||
short collisionFilterMask = isDynamic? short(btBroadphaseProxy::AllFilter) : short(btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);
|
short collisionFilterMask = isDynamic? short(btBroadphaseProxy::AllFilter) : short(btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);
|
||||||
@@ -459,6 +457,10 @@ void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body, short group, short
|
|||||||
|
|
||||||
if (body->getCollisionShape())
|
if (body->getCollisionShape())
|
||||||
{
|
{
|
||||||
|
if (!body->isStaticObject())
|
||||||
|
{
|
||||||
|
m_nonStaticRigidBodies.push_back(body);
|
||||||
|
}
|
||||||
addCollisionObject(body,group,mask);
|
addCollisionObject(body,group,mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -479,10 +481,9 @@ void btDiscreteDynamicsWorld::updateActivationState(btScalar timeStep)
|
|||||||
{
|
{
|
||||||
BT_PROFILE("updateActivationState");
|
BT_PROFILE("updateActivationState");
|
||||||
|
|
||||||
for ( int i=0;i<m_collisionObjects.size();i++)
|
for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj = m_collisionObjects[i];
|
btRigidBody* body = m_nonStaticRigidBodies[i];
|
||||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
|
||||||
if (body)
|
if (body)
|
||||||
{
|
{
|
||||||
body->updateDeactivation(timeStep);
|
body->updateDeactivation(timeStep);
|
||||||
@@ -828,46 +829,42 @@ void btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep)
|
|||||||
{
|
{
|
||||||
BT_PROFILE("integrateTransforms");
|
BT_PROFILE("integrateTransforms");
|
||||||
btTransform predictedTrans;
|
btTransform predictedTrans;
|
||||||
for ( int i=0;i<m_collisionObjects.size();i++)
|
for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj = m_collisionObjects[i];
|
btRigidBody* body = m_nonStaticRigidBodies[i];
|
||||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
body->setHitFraction(1.f);
|
||||||
if (body)
|
|
||||||
|
if (body->isActive() && (!body->isStaticOrKinematicObject()))
|
||||||
{
|
{
|
||||||
body->setHitFraction(1.f);
|
body->predictIntegratedTransform(timeStep, predictedTrans);
|
||||||
|
btScalar squareMotion = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2();
|
||||||
|
|
||||||
if (body->isActive() && (!body->isStaticOrKinematicObject()))
|
if (body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion)
|
||||||
{
|
{
|
||||||
body->predictIntegratedTransform(timeStep, predictedTrans);
|
BT_PROFILE("CCD motion clamping");
|
||||||
btScalar squareMotion = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2();
|
if (body->getCollisionShape()->isConvex())
|
||||||
|
|
||||||
if (body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion)
|
|
||||||
{
|
{
|
||||||
BT_PROFILE("CCD motion clamping");
|
gNumClampedCcdMotions++;
|
||||||
if (body->getCollisionShape()->isConvex())
|
|
||||||
|
btClosestNotMeConvexResultCallback sweepResults(body,body->getWorldTransform().getOrigin(),predictedTrans.getOrigin(),getBroadphase()->getOverlappingPairCache(),getDispatcher());
|
||||||
|
btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape());
|
||||||
|
btSphereShape tmpSphere(body->getCcdSweptSphereRadius());//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape());
|
||||||
|
|
||||||
|
sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup;
|
||||||
|
sweepResults.m_collisionFilterMask = body->getBroadphaseProxy()->m_collisionFilterMask;
|
||||||
|
|
||||||
|
convexSweepTest(&tmpSphere,body->getWorldTransform(),predictedTrans,sweepResults);
|
||||||
|
if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f))
|
||||||
{
|
{
|
||||||
gNumClampedCcdMotions++;
|
body->setHitFraction(sweepResults.m_closestHitFraction);
|
||||||
|
body->predictIntegratedTransform(timeStep*body->getHitFraction(), predictedTrans);
|
||||||
btClosestNotMeConvexResultCallback sweepResults(body,body->getWorldTransform().getOrigin(),predictedTrans.getOrigin(),getBroadphase()->getOverlappingPairCache(),getDispatcher());
|
body->setHitFraction(0.f);
|
||||||
btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape());
|
|
||||||
btSphereShape tmpSphere(body->getCcdSweptSphereRadius());//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape());
|
|
||||||
|
|
||||||
sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup;
|
|
||||||
sweepResults.m_collisionFilterMask = body->getBroadphaseProxy()->m_collisionFilterMask;
|
|
||||||
|
|
||||||
convexSweepTest(&tmpSphere,body->getWorldTransform(),predictedTrans,sweepResults);
|
|
||||||
if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f))
|
|
||||||
{
|
|
||||||
body->setHitFraction(sweepResults.m_closestHitFraction);
|
|
||||||
body->predictIntegratedTransform(timeStep*body->getHitFraction(), predictedTrans);
|
|
||||||
body->setHitFraction(0.f);
|
|
||||||
// printf("clamped integration to hit fraction = %f\n",fraction);
|
// printf("clamped integration to hit fraction = %f\n",fraction);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
body->proceedToTransform( predictedTrans);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body->proceedToTransform( predictedTrans);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -879,21 +876,16 @@ void btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep)
|
|||||||
void btDiscreteDynamicsWorld::predictUnconstraintMotion(btScalar timeStep)
|
void btDiscreteDynamicsWorld::predictUnconstraintMotion(btScalar timeStep)
|
||||||
{
|
{
|
||||||
BT_PROFILE("predictUnconstraintMotion");
|
BT_PROFILE("predictUnconstraintMotion");
|
||||||
for ( int i=0;i<m_collisionObjects.size();i++)
|
for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj = m_collisionObjects[i];
|
btRigidBody* body = m_nonStaticRigidBodies[i];
|
||||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
if (!body->isStaticOrKinematicObject())
|
||||||
if (body)
|
|
||||||
{
|
{
|
||||||
if (!body->isStaticOrKinematicObject())
|
body->integrateVelocities( timeStep);
|
||||||
{
|
//damping
|
||||||
|
body->applyDamping(timeStep);
|
||||||
body->integrateVelocities( timeStep);
|
|
||||||
//damping
|
|
||||||
body->applyDamping(timeStep);
|
|
||||||
|
|
||||||
body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform());
|
body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ protected:
|
|||||||
|
|
||||||
btAlignedObjectArray<btTypedConstraint*> m_constraints;
|
btAlignedObjectArray<btTypedConstraint*> m_constraints;
|
||||||
|
|
||||||
|
btAlignedObjectArray<btRigidBody*> m_nonStaticRigidBodies;
|
||||||
|
|
||||||
btVector3 m_gravity;
|
btVector3 m_gravity;
|
||||||
|
|
||||||
//for variable timesteps
|
//for variable timesteps
|
||||||
|
|||||||
Reference in New Issue
Block a user