merged most of the changes from the branch into trunk, except for COLLADA, libxml and glut glitches.
Still need to verify to make sure no unwanted renaming is introduced.
This commit is contained in:
@@ -13,28 +13,17 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
//#define USER_DEFINED_FRICTION_MODEL 1
|
||||
//#define PRINT_CONTACT_STATISTICS 1
|
||||
#define REGISTER_CUSTOM_COLLISION_ALGORITHM 1
|
||||
|
||||
#include "CcdPhysicsEnvironment.h"
|
||||
#include "ParallelPhysicsEnvironment.h"
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#include "CcdPhysicsController.h"
|
||||
#include "MyMotionState.h"
|
||||
|
||||
#include "ParallelIslandDispatcher.h"
|
||||
|
||||
#include "LinearMath/GenQuickprof.h"
|
||||
#include "LinearMath/GenIDebugDraw.h"
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
|
||||
|
||||
#include "PHY_Pro.h"
|
||||
#include "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
@@ -68,40 +57,35 @@ const int maxNumObjects = 32760;
|
||||
|
||||
int shapeIndex[maxNumObjects];
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
ParallelPhysicsEnvironment* m_physicsEnvironmentPtr = 0;
|
||||
#else
|
||||
CcdPhysicsEnvironment* m_physicsEnvironmentPtr = 0;
|
||||
#endif
|
||||
|
||||
#define CUBE_HALF_EXTENTS 1
|
||||
|
||||
#define EXTRA_HEIGHT -20.f
|
||||
//GL_LineSegmentShape shapeE(SimdPoint3(-50,0,0),
|
||||
// SimdPoint3(50,0,0));
|
||||
//GL_LineSegmentShape shapeE(btPoint3(-50,0,0),
|
||||
// btPoint3(50,0,0));
|
||||
static const int numShapes = 4;
|
||||
|
||||
CollisionShape* shapePtr[numShapes] =
|
||||
btCollisionShape* shapePtr[numShapes] =
|
||||
{
|
||||
///Please don't make the box sizes larger then 1000: the collision detection will be inaccurate.
|
||||
///See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=346
|
||||
|
||||
//#define USE_GROUND_PLANE 1
|
||||
#ifdef USE_GROUND_PLANE
|
||||
new StaticPlaneShape(SimdVector3(0,1,0),10),
|
||||
new btStaticPlaneShape(btVector3(0,1,0),10),
|
||||
#else
|
||||
new BoxShape (SimdVector3(50,10,50)),
|
||||
new btBoxShape (btVector3(50,10,50)),
|
||||
#endif
|
||||
|
||||
new BoxShape (SimdVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)),
|
||||
new SphereShape (CUBE_HALF_EXTENTS- 0.05f),
|
||||
new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)),
|
||||
new btSphereShape (CUBE_HALF_EXTENTS- 0.05f),
|
||||
|
||||
//new ConeShape(CUBE_HALF_EXTENTS,2.f*CUBE_HALF_EXTENTS),
|
||||
//new BU_Simplex1to4(SimdPoint3(-1,-1,-1),SimdPoint3(1,-1,-1),SimdPoint3(-1,1,-1),SimdPoint3(0,0,1)),
|
||||
//new btConeShape(CUBE_HALF_EXTENTS,2.f*CUBE_HALF_EXTENTS),
|
||||
//new btBU_Simplex1to4(btPoint3(-1,-1,-1),btPoint3(1,-1,-1),btPoint3(-1,1,-1),btPoint3(0,0,1)),
|
||||
|
||||
//new EmptyShape(),
|
||||
//new btEmptyShape(),
|
||||
|
||||
new BoxShape (SimdVector3(0.4,1,0.8))
|
||||
new btBoxShape (btVector3(0.4,1,0.8))
|
||||
|
||||
};
|
||||
|
||||
@@ -138,19 +122,17 @@ void CcdPhysicsDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
|
||||
if (m_physicsEnvironmentPtr)
|
||||
m_physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::beginBlock("render");
|
||||
btProfiler::beginBlock("render");
|
||||
#endif //USE_QUICKPROF
|
||||
|
||||
renderme();
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
Profiler::endBlock("render");
|
||||
btProfiler::endBlock("render");
|
||||
#endif
|
||||
glFlush();
|
||||
//some additional debugging info
|
||||
@@ -171,12 +153,15 @@ void CcdPhysicsDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
/*
|
||||
if (m_physicsEnvironmentPtr)
|
||||
{
|
||||
m_physicsEnvironmentPtr->UpdateAabbs(deltaTime);
|
||||
//draw contactpoints
|
||||
m_physicsEnvironmentPtr->CallbackTriggers();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
renderme();
|
||||
|
||||
@@ -192,7 +177,7 @@ void CcdPhysicsDemo::displayCallback(void) {
|
||||
void CcdPhysicsDemo::clientResetScene()
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
int i;
|
||||
int numObjects = m_physicsEnvironmentPtr->GetNumControllers();
|
||||
|
||||
@@ -203,7 +188,7 @@ void CcdPhysicsDemo::clientResetScene()
|
||||
{
|
||||
CcdPhysicsController* ctrl = m_physicsEnvironmentPtr->GetPhysicsController(i);
|
||||
|
||||
if ((getDebugMode() & IDebugDraw::DBG_NoHelpText))
|
||||
if ((getDebugMode() & btIDebugDraw::DBG_NoHelpText))
|
||||
{
|
||||
if (ctrl->GetRigidBody()->GetCollisionShape()->GetShapeType() != SPHERE_SHAPE_PROXYTYPE)
|
||||
{
|
||||
@@ -213,7 +198,7 @@ void CcdPhysicsDemo::clientResetScene()
|
||||
ctrl->GetRigidBody()->SetCollisionShape(shapePtr[1]);
|
||||
}
|
||||
|
||||
BroadphaseProxy* bpproxy = ctrl->GetRigidBody()->m_broadphaseHandle;
|
||||
btBroadphaseProxy* bpproxy = ctrl->GetRigidBody()->m_broadphaseHandle;
|
||||
m_physicsEnvironmentPtr->GetBroadphase()->CleanProxyFromPairs(bpproxy);
|
||||
}
|
||||
|
||||
@@ -236,11 +221,13 @@ void CcdPhysicsDemo::clientResetScene()
|
||||
ctrl->SetAngularVelocity(0,0,0,false);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
///User-defined friction model, the most simple friction model available: no friction
|
||||
float myFrictionModel( RigidBody& body1, RigidBody& body2, ManifoldPoint& contactPoint, const ContactSolverInfo& solverInfo )
|
||||
float myFrictionModel( btRigidBody& body1, btRigidBody& body2, btManifoldPoint& contactPoint, const btContactSolverInfo& solverInfo )
|
||||
{
|
||||
//don't do any friction
|
||||
return 0.f;
|
||||
@@ -249,32 +236,25 @@ float myFrictionModel( RigidBody& body1, RigidBody& body2, ManifoldPoint& contac
|
||||
void CcdPhysicsDemo::initPhysics()
|
||||
{
|
||||
|
||||
CollisionDispatcher* dispatcher = new CollisionDispatcher();
|
||||
btCollisionDispatcher* dispatcher = new btCollisionDispatcher();
|
||||
|
||||
SimdVector3 worldAabbMin(-10000,-10000,-10000);
|
||||
SimdVector3 worldAabbMax(10000,10000,10000);
|
||||
btVector3 worldAabbMin(-10000,-10000,-10000);
|
||||
btVector3 worldAabbMax(10000,10000,10000);
|
||||
|
||||
OverlappingPairCache* broadphase = new AxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
|
||||
// OverlappingPairCache* broadphase = new SimpleBroadphase;
|
||||
btOverlappingPairCache* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
|
||||
// btOverlappingPairCache* broadphase = new btSimpleBroadphase;
|
||||
|
||||
#ifdef REGISTER_CUSTOM_COLLISION_ALGORITHM
|
||||
dispatcher->RegisterCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,new SphereSphereCollisionAlgorithm::CreateFunc);
|
||||
dispatcher->RegisterCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,new btSphereSphereCollisionAlgorithm::CreateFunc);
|
||||
#endif //REGISTER_CUSTOM_COLLISION_ALGORITHM
|
||||
|
||||
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
m_physicsEnvironmentPtr = new ParallelPhysicsEnvironment(dispatcher2,broadphase);
|
||||
#else
|
||||
m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
|
||||
#endif
|
||||
m_physicsEnvironmentPtr->setDeactivationTime(2.f);
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver);
|
||||
|
||||
m_physicsEnvironmentPtr->setGravity(0,-10,0);
|
||||
|
||||
m_physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
|
||||
|
||||
#ifdef USER_DEFINED_FRICTION_MODEL
|
||||
SequentialImpulseConstraintSolver* solver = (SequentialImpulseConstraintSolver*) m_physicsEnvironmentPtr->GetConstraintSolver();
|
||||
btSequentialImpulseConstraintSolver* solver = (btSequentialImpulseConstraintSolver*) m_physicsEnvironmentPtr->GetConstraintSolver();
|
||||
//solver->SetContactSolverFunc(ContactSolverFunc func,USER_CONTACT_SOLVER_TYPE1,DEFAULT_CONTACT_SOLVER_TYPE);
|
||||
solver->SetFrictionSolverFunc(myFrictionModel,USER_CONTACT_SOLVER_TYPE1,DEFAULT_CONTACT_SOLVER_TYPE);
|
||||
solver->SetFrictionSolverFunc(myFrictionModel,DEFAULT_CONTACT_SOLVER_TYPE,USER_CONTACT_SOLVER_TYPE1);
|
||||
@@ -285,7 +265,7 @@ void CcdPhysicsDemo::initPhysics()
|
||||
|
||||
int i;
|
||||
|
||||
SimdTransform tr;
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
|
||||
|
||||
@@ -301,26 +281,26 @@ void CcdPhysicsDemo::initPhysics()
|
||||
|
||||
if (useCompound)
|
||||
{
|
||||
CompoundShape* compoundShape = new CompoundShape();
|
||||
CollisionShape* oldShape = shapePtr[1];
|
||||
btCompoundShape* compoundShape = new btCompoundShape();
|
||||
btCollisionShape* oldShape = shapePtr[1];
|
||||
shapePtr[1] = compoundShape;
|
||||
|
||||
SimdTransform ident;
|
||||
btTransform ident;
|
||||
ident.setIdentity();
|
||||
ident.setOrigin(SimdVector3(0,0,0));
|
||||
ident.setOrigin(btVector3(0,0,0));
|
||||
compoundShape->AddChildShape(ident,oldShape);//
|
||||
ident.setOrigin(SimdVector3(0,0,2));
|
||||
compoundShape->AddChildShape(ident,new SphereShape(0.9));//
|
||||
ident.setOrigin(btVector3(0,0,2));
|
||||
compoundShape->AddChildShape(ident,new btSphereShape(0.9));//
|
||||
}
|
||||
|
||||
for (i=0;i<gNumObjects;i++)
|
||||
{
|
||||
CollisionShape* shape = shapePtr[shapeIndex[i]];
|
||||
btCollisionShape* shape = shapePtr[shapeIndex[i]];
|
||||
shape->SetMargin(0.05f);
|
||||
|
||||
bool isDyna = i>0;
|
||||
|
||||
SimdTransform trans;
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
|
||||
if (i>0)
|
||||
@@ -338,13 +318,13 @@ void CcdPhysicsDemo::initPhysics()
|
||||
row2 |=1;
|
||||
}
|
||||
|
||||
SimdVector3 pos(col*2*CUBE_HALF_EXTENTS + (row2%2)*CUBE_HALF_EXTENTS,
|
||||
btVector3 pos(col*2*CUBE_HALF_EXTENTS + (row2%2)*CUBE_HALF_EXTENTS,
|
||||
row*2*CUBE_HALF_EXTENTS+CUBE_HALF_EXTENTS+EXTRA_HEIGHT,0);
|
||||
|
||||
trans.setOrigin(pos);
|
||||
} else
|
||||
{
|
||||
trans.setOrigin(SimdVector3(0,-30,0));
|
||||
trans.setOrigin(btVector3(0,-30,0));
|
||||
}
|
||||
|
||||
float mass = 1.f;
|
||||
@@ -352,13 +332,16 @@ void CcdPhysicsDemo::initPhysics()
|
||||
if (!isDyna)
|
||||
mass = 0.f;
|
||||
|
||||
CcdPhysicsController* ctrl = LocalCreatePhysicsObject(isDyna,mass,trans,shape);
|
||||
|
||||
btRigidBody* body = LocalCreateRigidBody(isDyna,mass,trans,shape);
|
||||
|
||||
m_dynamicsWorld->AddCollisionObject(body);
|
||||
|
||||
// Only do CCD if motion in one timestep (1.f/60.f) exceeds CUBE_HALF_EXTENTS
|
||||
ctrl->GetRigidBody()->m_ccdSquareMotionTreshold = CUBE_HALF_EXTENTS;
|
||||
body->m_ccdSquareMotionTreshold = CUBE_HALF_EXTENTS;
|
||||
|
||||
//Experimental: better estimation of CCD Time of Impact:
|
||||
ctrl->GetRigidBody()->m_ccdSweptShereRadius = 0.2*CUBE_HALF_EXTENTS;
|
||||
body->m_ccdSweptShereRadius = 0.2*CUBE_HALF_EXTENTS;
|
||||
|
||||
#ifdef USER_DEFINED_FRICTION_MODEL
|
||||
///Advanced use: override the friction solver
|
||||
ctrl->GetRigidBody()->m_frictionSolverType = USER_CONTACT_SOLVER_TYPE1;
|
||||
@@ -369,7 +352,6 @@ void CcdPhysicsDemo::initPhysics()
|
||||
|
||||
clientResetScene();
|
||||
|
||||
m_physicsEnvironmentPtr->SyncMotionStates(0.f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user