added serialization support for btCompoundShape, btCapsuleShapeX/Z, btCylinderShapeX,Z
make some serialization methods const prepare for constraint serialization
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
SUBDIRS( OpenGL BasicDemo Benchmarks Box2dDemo ConvexDecompositionDemo SerializeDemo )
|
||||
SUBDIRS( OpenGL BasicDemo Benchmarks Box2dDemo ConstraintDemo ConvexDecompositionDemo SerializeDemo )
|
||||
|
||||
|
||||
#todo: re-enable the rest of the demos again
|
||||
|
||||
@@ -12,15 +12,35 @@
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConstraintDemo
|
||||
|
||||
|
||||
|
||||
IF (USE_GLUT)
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision LinearMath BulletFileLoader ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConstraintDemo
|
||||
ConstraintDemo.cpp
|
||||
main.cpp
|
||||
)
|
||||
ELSE (USE_GLUT)
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision LinearMath BulletFileLoader ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(AppConstraintDemo
|
||||
WIN32
|
||||
../OpenGL/Win32AppMain.cpp
|
||||
Win32ConstraintDemo.cpp
|
||||
ConstraintDemo.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
ConstraintDemo.h
|
||||
)
|
||||
ENDIF (USE_GLUT)
|
||||
|
||||
@@ -13,6 +13,7 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
//#define TEST_SERIALIZATION 1
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +29,13 @@ subject to the following restrictions:
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
#include "LinearMath/btSerializer.h"
|
||||
#include "btBulletFile.h"
|
||||
#include "btBulletWorldImporter.h"
|
||||
#endif //TEST_SERIALIZATION
|
||||
|
||||
|
||||
const int numObjects = 3;
|
||||
|
||||
#define ENABLE_ALL_DEMOS 1
|
||||
@@ -74,6 +82,15 @@ void drawLimit()
|
||||
}
|
||||
|
||||
|
||||
void ConstraintDemo::setupEmptyDynamicsWorld()
|
||||
{
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
m_overlappingPairCache = new btDbvtBroadphase();
|
||||
m_constraintSolver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration);
|
||||
|
||||
}
|
||||
|
||||
void ConstraintDemo::initPhysics()
|
||||
{
|
||||
@@ -83,14 +100,7 @@ void ConstraintDemo::initPhysics()
|
||||
setCameraDistance(26.f);
|
||||
m_Time = 0;
|
||||
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
btVector3 worldMin(-1000,-1000,-1000);
|
||||
btVector3 worldMax(1000,1000,1000);
|
||||
m_overlappingPairCache = new btAxisSweep3(worldMin,worldMax);
|
||||
m_constraintSolver = new btSequentialImpulseConstraintSolver();
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration);
|
||||
|
||||
setupEmptyDynamicsWorld();
|
||||
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(40.),btScalar(50.)));
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
@@ -338,7 +348,7 @@ void ConstraintDemo::initPhysics()
|
||||
|
||||
btHingeConstraint* pHinge = new btHingeConstraint( *pBody, btPivotA, btAxisA );
|
||||
// pHinge->enableAngularMotor(true, -1.0, 0.165); // use for the old solver
|
||||
pHinge->enableAngularMotor(true, -1.0, 1.65); // use for the new SIMD solver
|
||||
pHinge->enableAngularMotor(true, -1.0f, 1.65f); // use for the new SIMD solver
|
||||
m_dynamicsWorld->addConstraint(pHinge);
|
||||
pHinge->setDbgDrawSize(btScalar(5.f));
|
||||
}
|
||||
@@ -471,13 +481,35 @@ void ConstraintDemo::initPhysics()
|
||||
spHingeDynAB->setDbgDrawSize(btScalar(5.f));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
|
||||
int maxSerializeBufferSize = 1024*1024*5;
|
||||
|
||||
btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize);
|
||||
m_dynamicsWorld->serialize(serializer);
|
||||
|
||||
FILE* f2 = fopen("testFile.bullet","wb");
|
||||
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2);
|
||||
fclose(f2);
|
||||
|
||||
|
||||
exitPhysics();
|
||||
|
||||
setupEmptyDynamicsWorld();
|
||||
|
||||
btBulletWorldImporter* fileLoader = new btBulletWorldImporter(m_dynamicsWorld);
|
||||
|
||||
fileLoader->loadFile("testFile.bullet");
|
||||
|
||||
#endif //TEST_SERIALIZATION
|
||||
|
||||
}
|
||||
|
||||
ConstraintDemo::~ConstraintDemo()
|
||||
void ConstraintDemo::exitPhysics()
|
||||
{
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
int i;
|
||||
int i;
|
||||
|
||||
//removed/delete constraints
|
||||
for (i=m_dynamicsWorld->getNumConstraints()-1; i>=0 ;i--)
|
||||
@@ -511,6 +543,8 @@ ConstraintDemo::~ConstraintDemo()
|
||||
delete shape;
|
||||
}
|
||||
|
||||
m_collisionShapes.clear();
|
||||
|
||||
//delete dynamics world
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
@@ -525,6 +559,13 @@ ConstraintDemo::~ConstraintDemo()
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
}
|
||||
|
||||
ConstraintDemo::~ConstraintDemo()
|
||||
{
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
exitPhysics();
|
||||
|
||||
}
|
||||
|
||||
@@ -550,7 +591,7 @@ void ConstraintDemo::clientMoveAndDisplay()
|
||||
// build twist target
|
||||
//btQuaternion q2(0,0,0);
|
||||
//btQuaternion q2(btVehictor3(1,0,0), -0.3*sin(m_Time));
|
||||
btQuaternion q2(btVector3(1,0,0), -1.49*sin(1.5*m_Time));
|
||||
btQuaternion q2(btVector3(1,0,0), -1.49f*btSin(1.5f*m_Time));
|
||||
|
||||
// compose cone + twist and set target
|
||||
q1 = q1 * q2;
|
||||
@@ -558,12 +599,21 @@ void ConstraintDemo::clientMoveAndDisplay()
|
||||
m_ctc->setMotorTargetInConstraintSpace(q1);
|
||||
}
|
||||
|
||||
{
|
||||
static bool once = false;
|
||||
if (m_dynamicsWorld->getDebugDrawer())
|
||||
{
|
||||
m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawConstraints+btIDebugDraw::DBG_DrawConstraintLimits);
|
||||
once=false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
//during idle mode, just run 1 simulation step maximum
|
||||
int maxSimSubSteps = m_idle ? 1 : 1;
|
||||
if (m_idle)
|
||||
dt = 1.0/420.f;
|
||||
dt = 1.0f/420.f;
|
||||
|
||||
int numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps);
|
||||
|
||||
@@ -593,7 +643,7 @@ void ConstraintDemo::clientMoveAndDisplay()
|
||||
// drawLimit();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
@@ -611,7 +661,7 @@ void ConstraintDemo::displayCallback(void) {
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,10 +15,16 @@ subject to the following restrictions:
|
||||
#ifndef CONSTRAINT_DEMO_H
|
||||
#define CONSTRAINT_DEMO_H
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "Win32DemoApplication.h"
|
||||
#define PlatformDemoApplication Win32DemoApplication
|
||||
#else
|
||||
#include "GlutDemoApplication.h"
|
||||
#define PlatformDemoApplication GlutDemoApplication
|
||||
#endif
|
||||
|
||||
///ConstraintDemo shows how to create a constraint, like Hinge or btGenericD6constraint
|
||||
class ConstraintDemo : public GlutDemoApplication
|
||||
class ConstraintDemo : public PlatformDemoApplication
|
||||
{
|
||||
//keep track of variables to delete memory at the end
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
@@ -31,6 +37,8 @@ class ConstraintDemo : public GlutDemoApplication
|
||||
|
||||
class btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
void setupEmptyDynamicsWorld();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -38,6 +46,8 @@ class ConstraintDemo : public GlutDemoApplication
|
||||
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
25
Demos/ConstraintDemo/Win32ConstraintDemo.cpp
Normal file
25
Demos/ConstraintDemo/Win32ConstraintDemo.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifdef _WINDOWS
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "ConstraintDemo.h"
|
||||
|
||||
///The 'createDemo' function is called from Bullet/Demos/OpenGL/Win32AppMain.cpp to instantiate this particular demo
|
||||
DemoApplication* createDemo()
|
||||
{
|
||||
return new ConstraintDemo();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -24,7 +24,7 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionShapes/btShapeHull.h"
|
||||
|
||||
#define TEST_SERIALIZATION
|
||||
#define NO_OBJ_TO_BULLET
|
||||
//#define NO_OBJ_TO_BULLET
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
#include "LinearMath/btSerializer.h"
|
||||
@@ -518,10 +518,10 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
btBulletWorldImporter* fileLoader = new btBulletWorldImporter(m_dynamicsWorld);
|
||||
//fileLoader->setVerboseMode(true);
|
||||
|
||||
//fileLoader->loadFileFromMemory("testFile.bullet");
|
||||
//fileLoader->loadFileFromMemory("testFile64Double.bullet");
|
||||
//fileLoader->loadFileFromMemory("testFile64Single.bullet");
|
||||
fileLoader->loadFileFromMemory("testFile32Single.bullet");
|
||||
fileLoader->loadFile("testFile.bullet");
|
||||
//fileLoader->loadFile("testFile64Double.bullet");
|
||||
//fileLoader->loadFile("testFile64Single.bullet");
|
||||
//fileLoader->loadFile("testFile32Single.bullet");
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ void GL_DialogWindow::draw(btScalar deltaTime)
|
||||
int curVertPos = m_dialogVertPos;
|
||||
curVertPos += yInc;
|
||||
|
||||
GLDebugDrawString(m_dialogHorPos+m_dialogWidth/2-((strlen(m_dialogTitle)/2)*charWidth),m_dialogVertPos+yInc ,m_dialogTitle);
|
||||
GLDebugDrawString(m_dialogHorPos+m_dialogWidth/2-((int(strlen(m_dialogTitle)/2))*charWidth),m_dialogVertPos+yInc ,m_dialogTitle);
|
||||
curVertPos += 20;
|
||||
|
||||
|
||||
|
||||
@@ -403,6 +403,7 @@ inline void glDrawVector(const btVector3& v) { glVertex3d(v[0], v[1], v[2]); }
|
||||
|
||||
void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax)
|
||||
{
|
||||
|
||||
if (shape->getShapeType() == CUSTOM_CONVEX_SHAPE_TYPE)
|
||||
{
|
||||
btVector3 org(m[12], m[13], m[14]);
|
||||
@@ -795,7 +796,6 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
|
||||
btVector3 v3 = vtx[index3];
|
||||
btVector3 normal = (v3-v1).cross(v2-v1);
|
||||
normal.normalize ();
|
||||
|
||||
glNormal3f(normal.getX(),normal.getY(),normal.getZ());
|
||||
glVertex3f (v1.x(), v1.y(), v1.z());
|
||||
glVertex3f (v2.x(), v2.y(), v2.z());
|
||||
@@ -813,7 +813,8 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
|
||||
}
|
||||
|
||||
|
||||
|
||||
glNormal3f(0,1,0);
|
||||
|
||||
|
||||
/// for polyhedral shapes
|
||||
if (debugMode==btIDebugDraw::DBG_DrawFeaturesText && (shape->isPolyhedral()))
|
||||
|
||||
@@ -159,8 +159,8 @@ void SerializeDemo::initPhysics()
|
||||
|
||||
//btMultiSphereShape* colShape = new btMultiSphereShape(positions,radii,numSpheres);
|
||||
|
||||
btCollisionShape* colShape = new btCapsuleShape(SCALING*1,SCALING*1);
|
||||
//btCollisionShape* colShape = new btCylinderShape(btVector3(SCALING*1,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 btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
|
||||
//btCollisionShape* colShape = new btSphereShape(btScalar(1.));
|
||||
m_collisionShapes.push_back(colShape);
|
||||
@@ -231,7 +231,7 @@ void SerializeDemo::initPhysics()
|
||||
|
||||
btBulletWorldImporter* fileLoader = new btBulletWorldImporter(m_dynamicsWorld);
|
||||
|
||||
fileLoader->loadFileFromMemory("testFile.bullet");
|
||||
fileLoader->loadFile("testFile.bullet");
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user