+ Fix btSubsimplexConvexCast

Thanks to Nacho, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2422)
Fix in rendering, GL_STENCIL
+ btTriangleIndexVertexArray indices should be unsigned int/unsigned short int,
+ Made InternalProcessAllTriangles virtual, thanks to 
Both thank to Fullmetalcoder, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2401
+clamp impulse for btPoint2PointConstraint
Thanks to Martijn Reuvers, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2418
+ Free memory of bvh, pass in scaling factor (optional)
Thanks to Roy Eltham, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2375
This commit is contained in:
erwin.coumans
2008-07-31 19:44:28 +00:00
parent 9cd83c004b
commit af4520801b
22 changed files with 332 additions and 273 deletions

View File

@@ -335,7 +335,7 @@ int main(int argc, char** argv)
printf("Bullet version %d\n",bulletVersion); printf("Bullet version %d\n",bulletVersion);
glutInit(&argc, argv); glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE |GLUT_DEPTH); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE |GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(width, height); glutInitWindowSize(width, height);
mainWindow = glutCreateWindow("http://bulletphysics.com"); mainWindow = glutCreateWindow("http://bulletphysics.com");
#ifdef BT_USE_FREEGLUT #ifdef BT_USE_FREEGLUT

View File

@@ -184,7 +184,9 @@ void ConcaveDemo::initPhysics()
//comment out the next line to read the BVH from disk (first run the demo once to create the BVH) //comment out the next line to read the BVH from disk (first run the demo once to create the BVH)
#define SERIALIZE_TO_DISK 1 #define SERIALIZE_TO_DISK 1
#ifdef SERIALIZE_TO_DISK #ifdef SERIALIZE_TO_DISK
trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression); btVector3 aabbMin(-1000,-1000,-1000),aabbMax(1000,1000,1000);
trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax);
m_collisionShapes.push_back(trimeshShape); m_collisionShapes.push_back(trimeshShape);
@@ -295,7 +297,7 @@ void ConcaveDemo::initPhysics()
startTransform.setIdentity(); startTransform.setIdentity();
staticBody = localCreateRigidBody(mass, startTransform,groundShape); staticBody = localCreateRigidBody(mass, startTransform,groundShape);
staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT); staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);//STATIC_OBJECT);
//enable custom material callback //enable custom material callback
staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);

View File

@@ -2,13 +2,17 @@
#include "ConcaveDemo.h" #include "ConcaveDemo.h"
#include "GlutStuff.h" #include "GlutStuff.h"
#include "GLDebugDrawer.h"
#include "btBulletDynamicsCommon.h"
GLDebugDrawer gDebugDrawer;
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
ConcaveDemo* concaveDemo = new ConcaveDemo(); ConcaveDemo* concaveDemo = new ConcaveDemo();
concaveDemo->initPhysics(); concaveDemo->initPhysics();
concaveDemo->setCameraDistance(30.f); concaveDemo->setCameraDistance(30.f);
concaveDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
return glutmain(argc, argv,640,480,"Static Concave Mesh Demo",concaveDemo); return glutmain(argc, argv,640,480,"Static Concave Mesh Demo",concaveDemo);
} }

View File

@@ -599,6 +599,8 @@ btVector3 DemoApplication::getRayTo(int x,int y)
return rayTo; return rayTo;
} }
btScalar mousePickClamping = 3.f;
void DemoApplication::mouseFunc(int button, int state, int x, int y) void DemoApplication::mouseFunc(int button, int state, int x, int y)
{ {
@@ -686,6 +688,8 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
btVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos; btVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos;
btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*body,localPivot); btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*body,localPivot);
p2p->m_setting.m_impulseClamp = mousePickClamping;
m_dynamicsWorld->addConstraint(p2p); m_dynamicsWorld->addConstraint(p2p);
m_pickConstraint = p2p; m_pickConstraint = p2p;
@@ -965,6 +969,8 @@ for(int i=0;i<numObjects;i++)
// //
void DemoApplication::renderme() void DemoApplication::renderme()
{ {
myinit();
updateCamera(); updateCamera();
if (m_dynamicsWorld) if (m_dynamicsWorld)

View File

@@ -443,7 +443,13 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
//glPushMatrix(); //glPushMatrix();
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
if(m_textureenabled) glEnable(GL_TEXTURE_2D); if(m_textureenabled)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,m_texturehandle);
}
glColor3f(color.x(),color.y(), color.z()); glColor3f(color.x(),color.y(), color.z());
bool useWireframeFallback = true; bool useWireframeFallback = true;

View File

@@ -1597,7 +1597,7 @@ ColladaConverter::addConcaveMesh(btCollisionShape* shape, const char* nodeName)
{ {
for (int t = 0; t < numFaces; t++) for (int t = 0; t < numFaces; t++)
{ {
short int* index = (short int*)indexBase; unsigned short int* index = (unsigned short int*)indexBase;
indices.append3( index[0], index[1], index[2]); indices.append3( index[0], index[1], index[2]);
indexBase += indexStride; indexBase += indexStride;
} }
@@ -1605,7 +1605,7 @@ ColladaConverter::addConcaveMesh(btCollisionShape* shape, const char* nodeName)
{ {
for (int t = 0; t < numFaces; t++) for (int t = 0; t < numFaces; t++)
{ {
int* index = (int*)indexBase; unsigned int* index = (unsigned int*)indexBase;
indices.append3( index[0], index[1], index[2]); indices.append3( index[0], index[1], index[2]);
indexBase += indexStride; indexBase += indexStride;
} }

View File

@@ -181,6 +181,9 @@ void SpuGatheringCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPai
{ {
btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject; btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject; btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
if (dispatcher->needsCollision(colObj0,colObj1))
{
btManifoldResult contactPointResult(colObj0,colObj1); btManifoldResult contactPointResult(colObj0,colObj1);
if (dispatchInfo.m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE) if (dispatchInfo.m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE)
@@ -198,6 +201,7 @@ void SpuGatheringCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPai
} }
} }
} }
}
//make sure all SPU work is done //make sure all SPU work is done
m_spuCollisionTaskProcess->flush2(); m_spuCollisionTaskProcess->flush2();

View File

@@ -270,20 +270,20 @@ public:
// ugly solution to support both 16bit and 32bit indices // ugly solution to support both 16bit and 32bit indices
if (m_lsMemPtr->bvhShapeData.gIndexMesh.m_indexType == PHY_SHORT) if (m_lsMemPtr->bvhShapeData.gIndexMesh.m_indexType == PHY_SHORT)
{ {
short int* indexBasePtr = (short int*)(m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexBase+triangleIndex*m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexStride); unsigned short int* indexBasePtr = (unsigned short int*)(m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexBase+triangleIndex*m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexStride);
ATTRIBUTE_ALIGNED16(short int tmpIndices[3]); ATTRIBUTE_ALIGNED16(unsigned short int tmpIndices[3]);
small_cache_read_triple(&tmpIndices[0],(ppu_address_t)&indexBasePtr[0], small_cache_read_triple(&tmpIndices[0],(ppu_address_t)&indexBasePtr[0],
&tmpIndices[1],(ppu_address_t)&indexBasePtr[1], &tmpIndices[1],(ppu_address_t)&indexBasePtr[1],
&tmpIndices[2],(ppu_address_t)&indexBasePtr[2], &tmpIndices[2],(ppu_address_t)&indexBasePtr[2],
sizeof(short int)); sizeof(unsigned short int));
m_lsMemPtr->spuIndices[0] = int(tmpIndices[0]); m_lsMemPtr->spuIndices[0] = int(tmpIndices[0]);
m_lsMemPtr->spuIndices[1] = int(tmpIndices[1]); m_lsMemPtr->spuIndices[1] = int(tmpIndices[1]);
m_lsMemPtr->spuIndices[2] = int(tmpIndices[2]); m_lsMemPtr->spuIndices[2] = int(tmpIndices[2]);
} else } else
{ {
int* indexBasePtr = (int*)(m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexBase+triangleIndex*m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexStride); unsigned int* indexBasePtr = (unsigned int*)(m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexBase+triangleIndex*m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexStride);
small_cache_read_triple(&m_lsMemPtr->spuIndices[0],(ppu_address_t)&indexBasePtr[0], small_cache_read_triple(&m_lsMemPtr->spuIndices[0],(ppu_address_t)&indexBasePtr[0],
&m_lsMemPtr->spuIndices[1],(ppu_address_t)&indexBasePtr[1], &m_lsMemPtr->spuIndices[1],(ppu_address_t)&indexBasePtr[1],
@@ -978,9 +978,12 @@ void processCollisionTask(void* userPtr, void* lsMemPtr)
// Get the collision objects // Get the collision objects
dmaAndSetupCollisionObjects(collisionPairInput, lsMem); dmaAndSetupCollisionObjects(collisionPairInput, lsMem);
if (lsMem.getColObj0()->isActive() || lsMem.getColObj1()->isActive())
{
handleCollisionPair(collisionPairInput, lsMem, spuContacts, handleCollisionPair(collisionPairInput, lsMem, spuContacts,
(ppu_address_t)lsMem.getColObj0()->getCollisionShape(), &lsMem.gCollisionShapes[0].collisionShape, (ppu_address_t)lsMem.getColObj0()->getCollisionShape(), &lsMem.gCollisionShapes[0].collisionShape,
(ppu_address_t)lsMem.getColObj1()->getCollisionShape(), &lsMem.gCollisionShapes[1].collisionShape); (ppu_address_t)lsMem.getColObj1()->getCollisionShape(), &lsMem.gCollisionShapes[1].collisionShape);
}
} }
} }

View File

@@ -404,9 +404,9 @@ void spuWalkStacklessQuantizedTreeAgainstRays(RaycastTask_LocalStoreMemory* lsMe
#define RAYAABB2 #define RAYAABB2
#ifdef RAYAABB2 #ifdef RAYAABB2
unsigned int sign[numWorkUnits][3]; unsigned int sign[SPU_RAYCAST_WORK_UNITS_PER_TASK][3];
btVector3 rayInvDirection[numWorkUnits]; btVector3 rayInvDirection[SPU_RAYCAST_WORK_UNITS_PER_TASK];
btScalar lambda_max[numWorkUnits]; btScalar lambda_max[SPU_RAYCAST_WORK_UNITS_PER_TASK];
for (int i = 0; i < numWorkUnits; i++) for (int i = 0; i < numWorkUnits; i++)
{ {
btVector3 rayDirection = (rayTo[i]-rayFrom[i]); btVector3 rayDirection = (rayTo[i]-rayFrom[i]);
@@ -512,10 +512,10 @@ void performRaycastAgainstConcave (RaycastGatheredObjectData* gatheredObjectData
//need the mesh interface, for access to triangle vertices //need the mesh interface, for access to triangle vertices
dmaBvhShapeData (&(lsMemPtr->bvhShapeData), trimeshShape); dmaBvhShapeData (&(lsMemPtr->bvhShapeData), trimeshShape);
unsigned short int quantizedQueryAabbMin[numWorkUnits][3]; unsigned short int quantizedQueryAabbMin[SPU_RAYCAST_WORK_UNITS_PER_TASK][3];
unsigned short int quantizedQueryAabbMax[numWorkUnits][3]; unsigned short int quantizedQueryAabbMax[SPU_RAYCAST_WORK_UNITS_PER_TASK][3];
btVector3 rayFromInTriangleSpace[numWorkUnits]; btVector3 rayFromInTriangleSpace[SPU_RAYCAST_WORK_UNITS_PER_TASK];
btVector3 rayToInTriangleSpace[numWorkUnits]; btVector3 rayToInTriangleSpace[SPU_RAYCAST_WORK_UNITS_PER_TASK];
/* Calculate the AABB for the ray in the triangle mesh shape */ /* Calculate the AABB for the ray in the triangle mesh shape */
btTransform rayInTriangleSpace; btTransform rayInTriangleSpace;

View File

@@ -235,7 +235,7 @@ btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlg
if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE)) if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
{ {
return m_boxBoxCF; //return m_boxBoxCF;
} }
if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE)) if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))

View File

@@ -143,17 +143,13 @@ class btPersistentManifoldSortPredicate
}; };
void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects)
//
// todo: this is random access, it can be walked 'cache friendly'!
//
void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects, IslandCallback* callback)
{ {
BT_PROFILE("islandUnionFindAndQuickSort"); BT_PROFILE("islandUnionFindAndQuickSort");
m_islandmanifold.resize(0);
//we are going to sort the unionfind array, and store the element id in the size //we are going to sort the unionfind array, and store the element id in the size
//afterwards, we clean unionfind, to make sure no-one uses it anymore //afterwards, we clean unionfind, to make sure no-one uses it anymore
@@ -287,6 +283,23 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
#endif //SPLIT_ISLANDS #endif //SPLIT_ISLANDS
} }
} }
}
//
// todo: this is random access, it can be walked 'cache friendly'!
//
void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects, IslandCallback* callback)
{
buildIslands(dispatcher,collisionObjects);
int endIslandIndex=1;
int startIslandIndex;
int numElem = getUnionFind().getNumElements();
BT_PROFILE("processIslands");
#ifndef SPLIT_ISLANDS #ifndef SPLIT_ISLANDS
btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer(); btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer();
@@ -367,5 +380,5 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
} }
#endif //SPLIT_ISLANDS #endif //SPLIT_ISLANDS
m_islandmanifold.resize(0);
} }

View File

@@ -63,6 +63,8 @@ public:
void buildAndProcessIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects, IslandCallback* callback); void buildAndProcessIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects, IslandCallback* callback);
void buildIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects);
}; };
#endif //SIMULATION_ISLAND_MANAGER_H #endif //SIMULATION_ISLAND_MANAGER_H

View File

@@ -127,13 +127,13 @@ void btBvhTriangleMeshShape::performRaycast (btTriangleCallback* callback, const
indicestype, indicestype,
nodeSubPart); nodeSubPart);
int* gfxbase = (int*)(indexbase+nodeTriangleIndex*indexstride); unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT); btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
const btVector3& meshScaling = m_meshInterface->getScaling(); const btVector3& meshScaling = m_meshInterface->getScaling();
for (int j=2;j>=0;j--) for (int j=2;j>=0;j--)
{ {
int graphicsindex = indicestype==PHY_SHORT?((short*)gfxbase)[j]:gfxbase[j]; int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride); btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
@@ -187,13 +187,13 @@ void btBvhTriangleMeshShape::performConvexcast (btTriangleCallback* callback, co
indicestype, indicestype,
nodeSubPart); nodeSubPart);
int* gfxbase = (int*)(indexbase+nodeTriangleIndex*indexstride); unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT); btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
const btVector3& meshScaling = m_meshInterface->getScaling(); const btVector3& meshScaling = m_meshInterface->getScaling();
for (int j=2;j>=0;j--) for (int j=2;j>=0;j--)
{ {
int graphicsindex = indicestype==PHY_SHORT?((short*)gfxbase)[j]:gfxbase[j]; int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride); btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
@@ -259,14 +259,14 @@ void btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,co
indicestype, indicestype,
nodeSubPart); nodeSubPart);
int* gfxbase = (int*)(indexbase+nodeTriangleIndex*indexstride); unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT); btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
const btVector3& meshScaling = m_meshInterface->getScaling(); const btVector3& meshScaling = m_meshInterface->getScaling();
for (int j=2;j>=0;j--) for (int j=2;j>=0;j--)
{ {
int graphicsindex = indicestype==PHY_SHORT?((short*)gfxbase)[j]:gfxbase[j]; int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
#ifdef DEBUG_TRIANGLE_MESH #ifdef DEBUG_TRIANGLE_MESH
@@ -299,7 +299,6 @@ void btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,co
} }
void btBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling) void btBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling)
{ {
if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON) if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
@@ -315,6 +314,22 @@ void btBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling)
m_bvh = new(mem) btOptimizedBvh(); m_bvh = new(mem) btOptimizedBvh();
//rebuild the bvh... //rebuild the bvh...
m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax); m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax);
m_ownsBvh = true;
}
}
void btBvhTriangleMeshShape::setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& scaling)
{
btAssert(!m_bvh);
btAssert(!m_ownsBvh);
m_bvh = bvh;
m_ownsBvh = false;
// update the scaling without rebuilding the bvh
if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
{
btTriangleMeshShape::setLocalScaling(scaling);
} }
} }

View File

@@ -75,14 +75,7 @@ public:
} }
void setOptimizedBvh(btOptimizedBvh* bvh) void setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1));
{
btAssert(!m_bvh);
btAssert(!m_ownsBvh);
m_bvh = bvh;
m_ownsBvh = false;
}
bool usesQuantizedAabbCompression() const bool usesQuantizedAabbCompression() const
{ {

View File

@@ -334,13 +334,13 @@ void btOptimizedBvh::updateBvhNodes(btStridingMeshInterface* meshInterface,int f
} }
//triangles->getLockedReadOnlyVertexIndexBase(vertexBase,numVerts, //triangles->getLockedReadOnlyVertexIndexBase(vertexBase,numVerts,
int* gfxbase = (int*)(indexbase+nodeTriangleIndex*indexstride); unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
for (int j=2;j>=0;j--) for (int j=2;j>=0;j--)
{ {
int graphicsindex = indicestype==PHY_SHORT?((short*)gfxbase)[j]:gfxbase[j]; int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride); btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
#ifdef DEBUG_PATCH_COLORS #ifdef DEBUG_PATCH_COLORS
btVector3 mycolor = color[index&3]; btVector3 mycolor = color[index&3];

View File

@@ -51,7 +51,7 @@ void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
{ {
for (gfxindex=0;gfxindex<numtriangles;gfxindex++) for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{ {
int* tri_indices= (int*)(indexbase+gfxindex*indexstride); unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride); graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride); graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride);
@@ -66,7 +66,7 @@ void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
{ {
for (gfxindex=0;gfxindex<numtriangles;gfxindex++) for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{ {
short int* tri_indices= (short int*)(indexbase+gfxindex*indexstride); unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride); graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride); graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride);

View File

@@ -47,7 +47,7 @@ class btStridingMeshInterface
void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const; virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
///brute force method to calculate aabb ///brute force method to calculate aabb
void calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax); void calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax);

View File

@@ -30,8 +30,8 @@ class btTriangleMesh : public btTriangleIndexVertexArray
btAlignedObjectArray<btVector3> m_4componentVertices; btAlignedObjectArray<btVector3> m_4componentVertices;
btAlignedObjectArray<float> m_3componentVertices; btAlignedObjectArray<float> m_3componentVertices;
btAlignedObjectArray<int> m_32bitIndices; btAlignedObjectArray<unsigned int> m_32bitIndices;
btAlignedObjectArray<short int> m_16bitIndices; btAlignedObjectArray<unsigned short int> m_16bitIndices;
bool m_use32bitIndices; bool m_use32bitIndices;
bool m_use4componentVertices; bool m_use4componentVertices;

View File

@@ -120,7 +120,7 @@ bool btSubsimplexConvexCast::calcTimeOfImpact(
dist2 = v.length2(); dist2 = v.length2();
hasResult = true; hasResult = true;
//todo: check this normal for validity //todo: check this normal for validity
n=v; //n=v;
//printf("V=%f , %f, %f\n",v[0],v[1],v[2]); //printf("V=%f , %f, %f\n",v[0],v[1],v[2]);
//printf("DIST2=%f\n",dist2); //printf("DIST2=%f\n",dist2);
//printf("numverts = %i\n",m_simplexSolver->numVertices()); //printf("numverts = %i\n",m_simplexSolver->numVertices());

View File

@@ -100,6 +100,16 @@ void btPoint2PointConstraint::solveConstraint(btScalar timeStep)
btScalar depth = -(pivotAInW - pivotBInW).dot(normal); //this is the error projected on the normal btScalar depth = -(pivotAInW - pivotBInW).dot(normal); //this is the error projected on the normal
btScalar impulse = depth*m_setting.m_tau/timeStep * jacDiagABInv - m_setting.m_damping * rel_vel * jacDiagABInv; btScalar impulse = depth*m_setting.m_tau/timeStep * jacDiagABInv - m_setting.m_damping * rel_vel * jacDiagABInv;
btScalar impulseClamp = m_setting.m_impulseClamp;
if (impulseClamp > 0)
{
if (impulse < -impulseClamp)
impulse = -impulseClamp;
if (impulse > impulseClamp)
impulse = impulseClamp;
}
m_appliedImpulse+=impulse; m_appliedImpulse+=impulse;
btVector3 impulse_vector = normal * impulse; btVector3 impulse_vector = normal * impulse;
m_rbA.applyImpulse(impulse_vector, pivotAInW - m_rbA.getCenterOfMassPosition()); m_rbA.applyImpulse(impulse_vector, pivotAInW - m_rbA.getCenterOfMassPosition());

View File

@@ -26,11 +26,13 @@ struct btConstraintSetting
{ {
btConstraintSetting() : btConstraintSetting() :
m_tau(btScalar(0.3)), m_tau(btScalar(0.3)),
m_damping(btScalar(1.)) m_damping(btScalar(1.)),
m_impulseClamp(btScalar(0.))
{ {
} }
btScalar m_tau; btScalar m_tau;
btScalar m_damping; btScalar m_damping;
btScalar m_impulseClamp;
}; };
/// point to point constraint between two rigidbodies each with a pivotpoint that descibes the 'ballsocket' location in local space /// point to point constraint between two rigidbodies each with a pivotpoint that descibes the 'ballsocket' location in local space

View File

@@ -154,7 +154,6 @@ void initSolverBody(btSolverBody* solverBody, btCollisionObject* collisionObject
} }
int gNumSplitImpulseRecoveries = 0; int gNumSplitImpulseRecoveries = 0;
btScalar restitutionCurve(btScalar rel_vel, btScalar restitution); btScalar restitutionCurve(btScalar rel_vel, btScalar restitution);