another large series of changes, related to the refactoring.
CompoundShapes are tricky to manage with respect to persistent contact points and swapped order of btCollisionObjects, During dispatch, finding an algorith etc. order can be swapped. fixed several other issues, related to SimpleBroadphase (removing a proxy was not working)
This commit is contained in:
@@ -134,6 +134,7 @@ void BspDemo::initPhysics(char* bspfilename)
|
||||
|
||||
///Setup a Physics Simulation Environment
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
||||
m_dynamicsWorld->setGravity(-m_cameraUp);
|
||||
|
||||
|
||||
#ifdef QUAKE_BSP_IMPORTING
|
||||
|
||||
@@ -14,7 +14,8 @@ subject to the following restrictions:
|
||||
*/
|
||||
|
||||
//#define USER_DEFINED_FRICTION_MODEL 1
|
||||
//#define PRINT_CONTACT_STATISTICS 1
|
||||
#define PRINT_CONTACT_STATISTICS 1
|
||||
//#define USE_KINEMATIC_GROUND 1
|
||||
#define REGISTER_CUSTOM_COLLISION_ALGORITHM 1
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
@@ -121,6 +122,14 @@ void CcdPhysicsDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
#ifdef USE_KINEMATIC_GROUND
|
||||
//btQuaternion kinRotation(btVector3(0,0,1),0.);
|
||||
btVector3 kinTranslation(0,0,0.01);
|
||||
//kinematic object
|
||||
m_dynamicsWorld->getCollisionObjectArray()[0]->m_worldTransform.getOrigin() += kinTranslation;
|
||||
#endif //USE_KINEMATIC_GROUND
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
|
||||
@@ -243,7 +252,7 @@ void CcdPhysicsDemo::initPhysics()
|
||||
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver);
|
||||
//setGravity(btVector3(0,0,1));
|
||||
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
|
||||
|
||||
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
||||
|
||||
@@ -328,6 +337,14 @@ void CcdPhysicsDemo::initPhysics()
|
||||
mass = 0.f;
|
||||
|
||||
btRigidBody* body = localCreateRigidBody(mass,trans,shape);
|
||||
#ifdef USE_KINEMATIC_GROUND
|
||||
if (mass == 0.f)
|
||||
{
|
||||
body->m_collisionFlags = btCollisionObject::CF_KINEMATIC_OJBECT;
|
||||
body->SetActivationState(DISABLE_DEACTIVATION);
|
||||
body->setLinearVelocity(btVector3(0,0,1));
|
||||
}
|
||||
#endif //USE_KINEMATIC_GROUND
|
||||
|
||||
|
||||
// Only do CCD if motion in one timestep (1.f/60.f) exceeds CUBE_HALF_EXTENTS
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -100,7 +100,7 @@ class MyColladaConverter : public ColladaConverter
|
||||
|
||||
virtual void setGravity(const btVector3& grav)
|
||||
{
|
||||
m_demoApp->setGravity(grav);
|
||||
m_demoApp->getDynamicsWorld()->setGravity(grav);
|
||||
}
|
||||
virtual void setCameraInfo(const btVector3& camUp,int forwardAxis)
|
||||
{
|
||||
|
||||
@@ -60,12 +60,12 @@ bool CustomMaterialCombinerCallback(btManifoldPoint& cp, const btCollisionObject
|
||||
float restitution0 = colObj0->getRestitution();
|
||||
float restitution1 = colObj1->getRestitution();
|
||||
|
||||
if (colObj0->m_collisionFlags & btCollisionObject::customMaterialCallback)
|
||||
if (colObj0->m_collisionFlags & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
|
||||
{
|
||||
friction0 = 1.0;//partId0,index0
|
||||
restitution0 = 0.f;
|
||||
}
|
||||
if (colObj1->m_collisionFlags & btCollisionObject::customMaterialCallback)
|
||||
if (colObj1->m_collisionFlags & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
|
||||
{
|
||||
if (index1&1)
|
||||
{
|
||||
@@ -161,10 +161,10 @@ void ConcaveDemo::initPhysics()
|
||||
|
||||
btRigidBody* staticBody = localCreateRigidBody(mass, startTransform,trimeshShape);
|
||||
|
||||
staticBody->m_collisionFlags |=btCollisionObject::isStatic;
|
||||
staticBody->m_collisionFlags |=btCollisionObject::CF_STATIC_OBJECT;
|
||||
|
||||
//enable custom material callback
|
||||
staticBody->m_collisionFlags |= btCollisionObject::customMaterialCallback;
|
||||
staticBody->m_collisionFlags |= btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK;
|
||||
|
||||
{
|
||||
for (int i=0;i<10;i++)
|
||||
|
||||
@@ -24,8 +24,8 @@ subject to the following restrictions:
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "BMF_Api.h"
|
||||
#include "BulletDynamics/Dynamics/btMassProps.h"
|
||||
|
||||
extern bool gDisableDeactivation;
|
||||
int numObjects = 0;
|
||||
const int maxNumObjects = 16384;
|
||||
btTransform startTransforms[maxNumObjects];
|
||||
@@ -37,7 +37,6 @@ DemoApplication::DemoApplication()
|
||||
:
|
||||
m_dynamicsWorld(0),
|
||||
m_pickConstraint(0),
|
||||
m_gravity(0,-10,0),
|
||||
m_cameraDistance(15.0),
|
||||
m_debugMode(0),
|
||||
m_ele(0.f),
|
||||
@@ -58,6 +57,7 @@ m_gravity(0,-10,0),
|
||||
}
|
||||
|
||||
|
||||
|
||||
DemoApplication::~DemoApplication()
|
||||
{
|
||||
|
||||
@@ -290,7 +290,15 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
|
||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoDeactivation);
|
||||
else
|
||||
m_debugMode |= btIDebugDraw::DBG_NoDeactivation;
|
||||
if (m_debugMode | btIDebugDraw::DBG_NoDeactivation)
|
||||
{
|
||||
gDisableDeactivation = true;
|
||||
} else
|
||||
{
|
||||
gDisableDeactivation = false;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -346,6 +354,29 @@ void DemoApplication::specialKeyboard(int key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case GLUT_KEY_F1:
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GLUT_KEY_F2:
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case GLUT_KEY_END:
|
||||
{
|
||||
int numObj = getDynamicsWorld()->getNumCollisionObjects();
|
||||
if (numObj)
|
||||
{
|
||||
btCollisionObject* obj = getDynamicsWorld()->getCollisionObjectArray()[numObj-1];
|
||||
getDynamicsWorld()->removeCollisionObject(obj);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GLUT_KEY_LEFT : stepLeft(); break;
|
||||
case GLUT_KEY_RIGHT : stepRight(); break;
|
||||
case GLUT_KEY_UP : stepFront(); break;
|
||||
@@ -522,7 +553,8 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
|
||||
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
|
||||
if (body)
|
||||
{
|
||||
if (!body->IsStatic())
|
||||
//other exclusions?
|
||||
if (!(body->isStaticObject() || body->isKinematicObject()))
|
||||
{
|
||||
pickedBody = body;
|
||||
pickedBody->SetActivationState(DISABLE_DEACTIVATION);
|
||||
@@ -616,27 +648,8 @@ btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform
|
||||
|
||||
btRigidBody* body = new btRigidBody(mass,startTransform,shape,localInertia);
|
||||
|
||||
//filtering allows to excluded collision pairs, early in the collision pipeline (broadphase)
|
||||
bool useFiltering = true;
|
||||
if (useFiltering)
|
||||
{
|
||||
short collisionFilterGroup = isDynamic?
|
||||
btBroadphaseProxy::DefaultFilter :
|
||||
btBroadphaseProxy::StaticFilter;
|
||||
short collisionFilterMask = isDynamic?
|
||||
btBroadphaseProxy::AllFilter :
|
||||
btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter;
|
||||
|
||||
m_dynamicsWorld->addCollisionObject(body,collisionFilterGroup,collisionFilterMask);
|
||||
} else
|
||||
{
|
||||
//no collision filtering, so always create an overlapping pair, even between static-static etc.
|
||||
m_dynamicsWorld->addCollisionObject(body);
|
||||
}
|
||||
|
||||
//Bullet uses per-object gravity
|
||||
body->setGravity(m_gravity);
|
||||
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,6 @@ class DemoApplication
|
||||
///constraint for mouse picking
|
||||
btTypedConstraint* m_pickConstraint;
|
||||
|
||||
btVector3 m_gravity;
|
||||
|
||||
float m_cameraDistance;
|
||||
int m_debugMode;
|
||||
|
||||
@@ -141,10 +139,7 @@ public:
|
||||
///Demo functions
|
||||
void shootBox(const btVector3& destination);
|
||||
|
||||
void setGravity(const btVector3& grav)
|
||||
{
|
||||
m_gravity = grav;
|
||||
}
|
||||
|
||||
btVector3 getRayTo(int x,int y);
|
||||
|
||||
btRigidBody* localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape);
|
||||
|
||||
@@ -136,7 +136,7 @@ void UserCollisionAlgorithm::initPhysics()
|
||||
|
||||
btRigidBody* staticBody= localCreateRigidBody(mass, startTransform,trimeshShape);
|
||||
//enable custom material callback
|
||||
staticBody->m_collisionFlags |= btCollisionObject::customMaterialCallback;
|
||||
staticBody->m_collisionFlags |= btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK;
|
||||
|
||||
{
|
||||
for (int i=0;i<10;i++)
|
||||
|
||||
Reference in New Issue
Block a user