fixes in serialization (don't serialize shapes multiple times), hull shape issue,

fix InternalEdgeDemo compilation using GLUT
This commit is contained in:
erwin.coumans
2010-01-30 06:55:39 +00:00
parent d5f5ddf2f1
commit 01b66a6799
7 changed files with 43 additions and 13 deletions

View File

@@ -190,7 +190,7 @@ void InternalEdgeDemo::initPhysics()
//gVertices[1].setY(21.1); //gVertices[1].setY(21.1);
//gVertices[1].setY(121.1); //gVertices[1].setY(121.1);
gVertices[1].setY(.1); gVertices[1].setY(.1f);
#ifdef ROTATE_GROUND #ifdef ROTATE_GROUND
//gVertices[1].setY(-1.1); //gVertices[1].setY(-1.1);
@@ -353,7 +353,7 @@ void InternalEdgeDemo::initPhysics()
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
m_dynamicsWorld->getSolverInfo().m_splitImpulse = true; m_dynamicsWorld->getSolverInfo().m_splitImpulse = true;
m_dynamicsWorld->getSolverInfo().m_splitImpulsePenetrationThreshold = 1e30f; m_dynamicsWorld->getSolverInfo().m_splitImpulsePenetrationThreshold = 1e30f;
m_dynamicsWorld->getSolverInfo().m_maxErrorReduction = 1e30; m_dynamicsWorld->getSolverInfo().m_maxErrorReduction = 1e30f;
m_dynamicsWorld->getSolverInfo().m_erp =1.f; m_dynamicsWorld->getSolverInfo().m_erp =1.f;
m_dynamicsWorld->getSolverInfo().m_erp2 = 1.f; m_dynamicsWorld->getSolverInfo().m_erp2 = 1.f;
@@ -375,7 +375,7 @@ void InternalEdgeDemo::initPhysics()
{ {
for (int i=0;i<1;i++) for (int i=0;i<1;i++)
{ {
startTransform.setOrigin(btVector3(-10+i*3,1+i*0.1,-1.3)); startTransform.setOrigin(btVector3(-10.f+i*3.f,1.f+btScalar(i)*0.1f,-1.3f));
btRigidBody* body = localCreateRigidBody(100, startTransform,colShape); btRigidBody* body = localCreateRigidBody(100, startTransform,colShape);
body->setActivationState(DISABLE_DEACTIVATION); body->setActivationState(DISABLE_DEACTIVATION);
body->setLinearVelocity(btVector3(0,0,-1)); body->setLinearVelocity(btVector3(0,0,-1));
@@ -485,7 +485,7 @@ void InternalEdgeDemo::clientMoveAndDisplay()
renderme(); renderme();
glFlush(); glFlush();
glutSwapBuffers(); swapBuffers();
} }

View File

@@ -15,7 +15,14 @@ subject to the following restrictions:
#ifndef CONCAVE_DEMO_H #ifndef CONCAVE_DEMO_H
#define CONCAVE_DEMO_H #define CONCAVE_DEMO_H
#ifdef _WINDOWS
#include "Win32DemoApplication.h"
#define PlatformDemoApplication Win32DemoApplication
#else
#include "GlutDemoApplication.h" #include "GlutDemoApplication.h"
#define PlatformDemoApplication GlutDemoApplication
#endif
#include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btAlignedObjectArray.h"
class btBroadphaseInterface; class btBroadphaseInterface;
@@ -29,7 +36,7 @@ class btTriangleIndexVertexArray;
///InternalEdgeDemo shows usage of static concave triangle meshes ///InternalEdgeDemo shows usage of static concave triangle meshes
///It also shows per-triangle material (friction/restitution) through CustomMaterialCombinerCallback ///It also shows per-triangle material (friction/restitution) through CustomMaterialCombinerCallback
class InternalEdgeDemo : public GlutDemoApplication class InternalEdgeDemo : public PlatformDemoApplication
{ {
//keep the collision shapes, for deletion/cleanup //keep the collision shapes, for deletion/cleanup

View File

@@ -19,7 +19,7 @@ subject to the following restrictions:
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo ///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
DemoApplication* createDemo() DemoApplication* createDemo()
{ {
return new InternalEdgeDemo.cpp(); return new InternalEdgeDemo();
} }
#endif #endif

View File

@@ -161,9 +161,9 @@ void SerializeDemo::initPhysics()
btVector3 positions[2] = {btVector3(0.1f,0.2f,0.3f),btVector3(0.4f,0.5f,0.6f)}; btVector3 positions[2] = {btVector3(0.1f,0.2f,0.3f),btVector3(0.4f,0.5f,0.6f)};
btScalar radii[2] = {0.3f,0.4f}; btScalar radii[2] = {0.3f,0.4f};
//btMultiSphereShape* colShape = new btMultiSphereShape(positions,radii,numSpheres); btMultiSphereShape* colShape = new btMultiSphereShape(positions,radii,numSpheres);
btCollisionShape* colShape = new btCapsuleShapeZ(SCALING*1,SCALING*1); //btCollisionShape* colShape = new btCapsuleShapeZ(SCALING*1,SCALING*1);
//btCollisionShape* colShape = new btCylinderShapeZ(btVector3(SCALING*1,SCALING*1,SCALING*1)); //btCollisionShape* colShape = new btCylinderShapeZ(btVector3(SCALING*1,SCALING*1,SCALING*1));
//btCollisionShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1)); //btCollisionShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
//btCollisionShape* colShape = new btSphereShape(btScalar(1.)); //btCollisionShape* colShape = new btSphereShape(btScalar(1.));

View File

@@ -253,6 +253,7 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
{ {
hullShape->addPoint(tmpPoints[i]); hullShape->addPoint(tmpPoints[i]);
} }
shape = hullShape;
break; break;
} }
default: default:

View File

@@ -305,7 +305,8 @@ const char* btCompoundShape::serialize(void* dataBuffer, btSerializer* serialize
{ {
memPtr->m_childMargin = float(m_children[i].m_childMargin); memPtr->m_childMargin = float(m_children[i].m_childMargin);
memPtr->m_childShape = (btCollisionShapeData*)m_children[i].m_childShape; memPtr->m_childShape = (btCollisionShapeData*)m_children[i].m_childShape;
//don't serialize shapes that already have been serialized
if (!serializer->findPointer(memPtr->m_childShape))
{ {
btChunk* chunk = serializer->allocate(m_children[i].m_childShape->calculateSerializeBufferSize(),1); btChunk* chunk = serializer->allocate(m_children[i].m_childShape->calculateSerializeBufferSize(),1);
const char* structType = m_children[i].m_childShape->serialize(chunk->m_oldPtr,serializer); const char* structType = m_children[i].m_childShape->serialize(chunk->m_oldPtr,serializer);

View File

@@ -53,7 +53,9 @@ public:
virtual btChunk* allocate(size_t size, int numElements) = 0; virtual btChunk* allocate(size_t size, int numElements) = 0;
virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr) const = 0; virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr)= 0;
virtual void* findPointer(void* oldPtr) = 0;
virtual void startSerialization() = 0; virtual void startSerialization() = 0;
@@ -89,14 +91,27 @@ class btDefaultSerializer : public btSerializer
btHashMap<btHashInt, int> mStructReverse; btHashMap<btHashInt, int> mStructReverse;
btHashMap<btHashString,int> mTypeLookup; btHashMap<btHashString,int> mTypeLookup;
btAlignedObjectArray<btChunk*> m_chunkPtrs;
btHashMap<btHashPtr,void*> m_chunkP;
int m_totalSize; int m_totalSize;
unsigned char* m_buffer; unsigned char* m_buffer;
int m_currentSize; int m_currentSize;
btAlignedObjectArray<btChunk*> m_chunkPtrs;
protected: protected:
virtual void* findPointer(void* oldPtr)
{
void** ptr = m_chunkP.find(oldPtr);
if (ptr && *ptr)
return *ptr;
return 0;
}
void writeDNA() void writeDNA()
{ {
unsigned char* dnaTarget = m_buffer+m_currentSize; unsigned char* dnaTarget = m_buffer+m_currentSize;
@@ -389,12 +404,16 @@ public:
return m_currentSize; return m_currentSize;
} }
virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr) const virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr)
{ {
btAssert(!findPointer(oldPtr));
chunk->m_dna_nr = getReverseType(structType); chunk->m_dna_nr = getReverseType(structType);
chunk->m_chunkCode = chunkCode; chunk->m_chunkCode = chunkCode;
m_chunkP.insert(oldPtr,chunk->m_oldPtr);
chunk->m_oldPtr = oldPtr; chunk->m_oldPtr = oldPtr;
} }
@@ -406,6 +425,7 @@ public:
unsigned char* ptr = m_buffer+m_currentSize; unsigned char* ptr = m_buffer+m_currentSize;
m_currentSize += int(size)*numElements+sizeof(btChunk); m_currentSize += int(size)*numElements+sizeof(btChunk);
btAssert(m_currentSize<m_totalSize);
unsigned char* data = ptr + sizeof(btChunk); unsigned char* data = ptr + sizeof(btChunk);
@@ -417,6 +437,7 @@ public:
m_chunkPtrs.push_back(chunk); m_chunkPtrs.push_back(chunk);
return chunk; return chunk;
} }