Add the old Bullet 2.x obsolete demos, and CMake buildsystem files, and gradually move them to newer Bullet 3.x structure
Use statically linked freeglut, instead of dynamic glut for the obsolete Bullet 2.x demos Add the 'reset' method to b3GpuDynamicsWorld, and use it in the BasicGpuDemo (pretty slow in debug mode, use release mode) Don't crash in btCollisionWorld, if there is no collision dispatcher
This commit is contained in:
@@ -15,9 +15,9 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
///create 125 (5x5x5) dynamic object
|
||||
#define ARRAY_SIZE_X 25
|
||||
#define ARRAY_SIZE_X 20
|
||||
#define ARRAY_SIZE_Y 20
|
||||
#define ARRAY_SIZE_Z 25
|
||||
#define ARRAY_SIZE_Z 20
|
||||
|
||||
//maximum number of objects (and allow user to shoot additional boxes)
|
||||
#define MAX_PROXIES (ARRAY_SIZE_X*ARRAY_SIZE_Y*ARRAY_SIZE_Z + 1024)
|
||||
@@ -182,8 +182,11 @@ BasicGpuDemo::~BasicGpuDemo()
|
||||
}
|
||||
|
||||
|
||||
extern bool gUseLargeBatches;
|
||||
|
||||
void BasicGpuDemo::initPhysics()
|
||||
{
|
||||
gUseLargeBatches = true;//for testing, this option is faster on NVIDIA GPUs
|
||||
//use the Bullet 2.x btQuickprof for profiling of Bullet 3.x
|
||||
b3SetCustomEnterProfileZoneFunc(CProfileManager::Start_Profile);
|
||||
b3SetCustomLeaveProfileZoneFunc(CProfileManager::Stop_Profile);
|
||||
@@ -228,7 +231,13 @@ void BasicGpuDemo::initPhysics()
|
||||
|
||||
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
|
||||
|
||||
///create a few basic rigid bodies
|
||||
|
||||
createObjects();
|
||||
}
|
||||
|
||||
void BasicGpuDemo::createObjects()
|
||||
{
|
||||
///create a few basic rigid bodies
|
||||
btBoxShape* groundShape = new btBoxShape(btVector3(btScalar(150.),btScalar(50.),btScalar(150.)));
|
||||
//groundShape->initializePolyhedralFeatures();
|
||||
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
|
||||
@@ -346,8 +355,36 @@ void BasicGpuDemo::initPhysics()
|
||||
}
|
||||
void BasicGpuDemo::clientResetScene()
|
||||
{
|
||||
/*
|
||||
exitPhysics();
|
||||
initPhysics();
|
||||
*/
|
||||
|
||||
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if (body && body->getMotionState())
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );//reset will take care of this
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
btCollisionShape* shape = m_collisionShapes[j];
|
||||
delete shape;
|
||||
}
|
||||
m_collisionShapes.clear();
|
||||
|
||||
((b3GpuDynamicsWorld*)m_dynamicsWorld)->reset();
|
||||
|
||||
createObjects();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ class BasicGpuDemo : public PlatformDemoApplication
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
void createObjects();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
@@ -12,7 +12,8 @@ SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
########################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos/OpenGL
|
||||
)
|
||||
|
||||
|
||||
@@ -27,7 +28,7 @@ ADD_EXECUTABLE(AppBasicDemo
|
||||
main.cpp
|
||||
BasicDemo.cpp
|
||||
BasicDemo.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build/bullet.rc
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppBasicDemo
|
||||
@@ -40,25 +41,6 @@ ENDIF()
|
||||
|
||||
|
||||
|
||||
IF (WIN32)
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
IF (CMAKE_CL_64)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppBasicDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ELSE(CMAKE_CL_64)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppBasicDemo
|
||||
POST_BUILD
|
||||
# COMMAND copy /Y ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ENDIF(CMAKE_CL_64)
|
||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
|
||||
ENDIF(WIN32)
|
||||
ELSE (USE_GLUT)
|
||||
|
||||
|
||||
@@ -74,7 +56,7 @@ ELSE (USE_GLUT)
|
||||
Win32BasicDemo.cpp
|
||||
BasicDemo.cpp
|
||||
BasicDemo.h
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build/bullet.rc
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h"
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
//#include "Bullet3Common/b3Logging.h"
|
||||
#include "Bullet3OpenCL/BroadphaseCollision/b3GpuSapBroadphase.h"
|
||||
#include "Bullet3OpenCL/RigidBody/b3GpuNarrowPhase.h"
|
||||
#include "Bullet3OpenCL/RigidBody/b3GpuRigidBodyPipeline.h"
|
||||
@@ -20,7 +21,6 @@
|
||||
#include "Bullet3Dynamics/ConstraintSolver/b3Generic6DofConstraint.h"
|
||||
|
||||
#include "Bullet3Collision/NarrowPhaseCollision/b3RigidBodyCL.h"
|
||||
#include "Bullet3Common/b3Logging.h"
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -28,9 +28,9 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if (BT_BULLET_VERSION >= 282)
|
||||
#define BT_USE_BODY_UPDATE_REVISION
|
||||
#endif
|
||||
//#if (BT_BULLET_VERSION >= 282)
|
||||
//#define BT_USE_BODY_UPDATE_REVISION
|
||||
//#endif
|
||||
|
||||
|
||||
b3GpuDynamicsWorld::b3GpuDynamicsWorld(class b3GpuSapBroadphase* bp,class b3GpuNarrowPhase* np, class b3GpuRigidBodyPipeline* rigidBodyPipeline)
|
||||
@@ -54,7 +54,7 @@ b3GpuDynamicsWorld::~b3GpuDynamicsWorld()
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
int b3GpuDynamicsWorld::stepSimulation( btScalar timeStepUnused, int maxSubStepsUnused, btScalar fixedTimeStep)
|
||||
{
|
||||
@@ -62,10 +62,7 @@ int b3GpuDynamicsWorld::stepSimulation( btScalar timeStepUnused, int maxSubStep
|
||||
///Please use the CPU version in btDiscreteDynamicsWorld if you don't like this
|
||||
|
||||
|
||||
#ifndef BT_NO_PROFILE
|
||||
CProfileManager::Reset();
|
||||
#endif //BT_NO_PROFILE
|
||||
|
||||
|
||||
BT_PROFILE("stepSimulation");
|
||||
|
||||
@@ -115,13 +112,13 @@ int b3GpuDynamicsWorld::stepSimulation( btScalar timeStepUnused, int maxSubStep
|
||||
|
||||
// detect any change (very simple)
|
||||
{
|
||||
BT_PROFILE("body update revision detection (CPU)");
|
||||
B3_PROFILE("body update revision detection (CPU)");
|
||||
#ifdef BT_USE_BODY_UPDATE_REVISION
|
||||
b3Assert(m_bodyUpdateRevisions.size() == m_collisionObjects.size());
|
||||
b3Assert(m_np->getNumRigidBodies() == m_bodyUpdateRevisions.size());
|
||||
#endif //BT_USE_BODY_UPDATE_REVISION
|
||||
|
||||
|
||||
b3RigidBodyCL* bodiesCL = (b3RigidBodyCL*)m_np->getBodiesCpu();
|
||||
for (int i=0;i<this->m_collisionObjects.size();i++)
|
||||
{
|
||||
if (i>=m_np->getNumRigidBodies())
|
||||
@@ -233,13 +230,16 @@ int b3GpuDynamicsWorld::stepSimulation( btScalar timeStepUnused, int maxSubStep
|
||||
}
|
||||
}
|
||||
|
||||
clearForces();
|
||||
|
||||
{
|
||||
B3_PROFILE("clearForces");
|
||||
clearForces();
|
||||
}
|
||||
|
||||
#ifndef B3_NO_PROFILE
|
||||
#ifndef BT_NO_PROFILE
|
||||
CProfileManager::Increment_Frame_Counter();
|
||||
#endif //B3_NO_PROFILE
|
||||
|
||||
// CProfileManager::dumpAll();
|
||||
#endif //BT_NO_PROFILE
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -491,6 +491,35 @@ void b3GpuDynamicsWorld::removeRigidBody(btRigidBody* colObj)
|
||||
}
|
||||
|
||||
|
||||
void b3GpuDynamicsWorld::reset()
|
||||
{
|
||||
m_staticBody = 0;
|
||||
|
||||
if (m_collisionObjects.size())
|
||||
b3Warning("m_collisionObjects should be empty before calling b3GpuDynamicsWorld::reset");
|
||||
m_collisionObjects.clear();
|
||||
if (m_bodyUpdateRevisions.size())
|
||||
b3Warning("world (m_bodyUpdateRevisions) should be empty before calling b3GpuDynamicsWorld::reset");
|
||||
m_bodyUpdateRevisions.clear();
|
||||
|
||||
if (m_constraints.size())
|
||||
b3Warning("m_constraints should be empty before calling b3GpuDynamicsWorld::reset");
|
||||
m_constraints.clear();
|
||||
|
||||
|
||||
m_uniqueShapes.resize(0);
|
||||
m_uniqueShapeMapping.resize(0);
|
||||
m_np->reset();
|
||||
m_bp->reset();
|
||||
m_rigidBodyPipeline->reset();
|
||||
#ifdef BT_USE_BODY_UPDATE_REVISION
|
||||
m_bodyUpdateRevisions.resize(0);
|
||||
#endif
|
||||
|
||||
btConvexHullShape* nullShape = new btConvexHullShape();
|
||||
m_staticBody = new btRigidBody(0,0,nullShape);
|
||||
addRigidBody(m_staticBody,0,0);
|
||||
}
|
||||
|
||||
void b3GpuDynamicsWorld::removeCollisionObject(btCollisionObject* colObj)
|
||||
{
|
||||
@@ -503,14 +532,7 @@ void b3GpuDynamicsWorld::removeCollisionObject(btCollisionObject* colObj)
|
||||
}
|
||||
if (getNumCollisionObjects()==0)
|
||||
{
|
||||
m_uniqueShapes.resize(0);
|
||||
m_uniqueShapeMapping.resize(0);
|
||||
m_np->reset();
|
||||
m_bp->reset();
|
||||
m_rigidBodyPipeline->reset();
|
||||
#ifdef BT_USE_BODY_UPDATE_REVISION
|
||||
m_bodyUpdateRevisions.resize(0);
|
||||
#endif
|
||||
reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class btTypedConstraint;
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "BulletDynamics/Dynamics/btDynamicsWorld.h"
|
||||
#include "Bullet3Common/b3Logging.h"
|
||||
|
||||
|
||||
class b3GpuDynamicsWorld : public btDynamicsWorld
|
||||
@@ -30,9 +31,9 @@ class b3GpuDynamicsWorld : public btDynamicsWorld
|
||||
bool m_cpuGpuSync;
|
||||
float m_localTime;
|
||||
class btRigidBody* m_staticBody;//used for picking and Bullet 2.x compatibility. In Bullet 3.x all constraints have explicitly 2 bodies.
|
||||
|
||||
int findOrRegisterCollisionShape(const btCollisionShape* colShape);
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
b3GpuDynamicsWorld(class b3GpuSapBroadphase* bp,class b3GpuNarrowPhase* np, class b3GpuRigidBodyPipeline* rigidBodyPipeline);
|
||||
@@ -57,7 +58,6 @@ public:
|
||||
virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false);
|
||||
|
||||
virtual void removeConstraint(btTypedConstraint* constraint);
|
||||
|
||||
void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const;
|
||||
|
||||
btAlignedObjectArray<class btCollisionObject*>& getCollisionObjectArray();
|
||||
@@ -75,8 +75,6 @@ public:
|
||||
addRigidBody(body);
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void addAction(btActionInterface* action)
|
||||
{
|
||||
btAssert(0);
|
||||
@@ -108,6 +106,8 @@ public:
|
||||
|
||||
///this can be useful to synchronize a single rigid body -> graphics object
|
||||
void synchronizeSingleMotionState(btRigidBody* body);
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
#endif //B3_GPU_DYNAMICS_WORLD_H
|
||||
|
||||
Reference in New Issue
Block a user