Thanks to Mårten Svanfeldt for the contribution:

- optionally disable collisions between bodies that are linked with constraints
- improved debug rendering with support for compounds, spheres, capsules
This commit is contained in:
ejcoumans
2007-06-28 19:14:30 +00:00
parent a0c5401033
commit ced94d63bf
9 changed files with 1204 additions and 1037 deletions

View File

@@ -273,6 +273,8 @@ bool btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionO
if ((!body0->isActive()) && (!body1->isActive())) if ((!body0->isActive()) && (!body1->isActive()))
needsCollision = false; needsCollision = false;
else if (!body0->checkCollideWith(body1))
needsCollision = false;
return needsCollision ; return needsCollision ;

View File

@@ -24,7 +24,8 @@ btCollisionObject::btCollisionObject()
m_userObjectPointer(0), m_userObjectPointer(0),
m_hitFraction(btScalar(1.)), m_hitFraction(btScalar(1.)),
m_ccdSweptSphereRadius(btScalar(0.)), m_ccdSweptSphereRadius(btScalar(0.)),
m_ccdSquareMotionThreshold(btScalar(0.)) m_ccdSquareMotionThreshold(btScalar(0.)),
m_checkCollideWith(false)
{ {
} }

View File

@@ -69,15 +69,23 @@ protected:
void* m_internalOwner; void* m_internalOwner;
///time of impact calculation ///time of impact calculation
btScalar m_hitFraction; btScalar m_hitFraction;
///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm:: ///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
btScalar m_ccdSweptSphereRadius; btScalar m_ccdSweptSphereRadius;
/// Don't do continuous collision detection if square motion (in one step) is less then m_ccdSquareMotionThreshold /// Don't do continuous collision detection if square motion (in one step) is less then m_ccdSquareMotionThreshold
btScalar m_ccdSquareMotionThreshold; btScalar m_ccdSquareMotionThreshold;
char m_pad[8]; /// If some object should have elaborate collision filtering by sub-classes
bool m_checkCollideWith;
char m_pad[7];
virtual bool checkCollideWithOverride(btCollisionObject* co)
{
return true;
}
public: public:
@@ -159,7 +167,7 @@ public:
return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION)); return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
} }
void setRestitution(btScalar rest) void setRestitution(btScalar rest)
{ {
m_restitution = rest; m_restitution = rest;
} }
@@ -322,6 +330,15 @@ public:
m_userObjectPointer = userPointer; m_userObjectPointer = userPointer;
} }
inline bool checkCollideWith(btCollisionObject* co)
{
if (m_checkCollideWith)
return checkCollideWithOverride(co);
return true;
}
} }
; ;

View File

@@ -290,16 +290,32 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
for(int x=startX; x<endX; x++) for(int x=startX; x<endX; x++)
{ {
btVector3 vertices[3]; btVector3 vertices[3];
//first triangle if (!m_flipQuadEdges)
getVertex(x,j,vertices[0]); {
getVertex(x,j+1,vertices[1]); //first triangle
getVertex(x+1,j,vertices[2]); getVertex(x,j,vertices[0]);
callback->processTriangle(vertices,x,j); getVertex(x,j+1,vertices[1]);
//second triangle getVertex(x+1,j,vertices[2]);
getVertex(x+1,j,vertices[0]); callback->processTriangle(vertices,x,j);
getVertex(x,j+1,vertices[1]); //second triangle
getVertex(x+1,j+1,vertices[2]); getVertex(x+1,j,vertices[0]);
callback->processTriangle(vertices,x,j); getVertex(x,j+1,vertices[1]);
getVertex(x+1,j+1,vertices[2]);
callback->processTriangle(vertices,x,j);
} else
{
//first triangle
getVertex(x,j,vertices[0]);
getVertex(x+1,j,vertices[1]);
getVertex(x+1,j+1,vertices[2]);
callback->processTriangle(vertices,x,j);
//second triangle
getVertex(x,j,vertices[0]);
getVertex(x+1,j+1,vertices[1]);
getVertex(x,j+1,vertices[2]);
callback->processTriangle(vertices,x,j);
}
} }
} }

View File

@@ -46,6 +46,20 @@ public:
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
int getSphereCount() const
{
return m_numSpheres;
}
const btVector3& getSpherePosition(int index) const
{
return m_localPositions[index];
}
btScalar getSphereRadius(int index) const
{
return m_radi[index];
}
virtual int getShapeType() const { return MULTI_SPHERE_SHAPE_PROXYTYPE; } virtual int getShapeType() const { return MULTI_SPHERE_SHAPE_PROXYTYPE; }

File diff suppressed because it is too large Load Diff

View File

@@ -1,154 +1,155 @@
/* /*
Bullet Continuous Collision Detection and Physics Library Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty. 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. 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, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: 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. 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. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef BT_DISCRETE_DYNAMICS_WORLD_H #ifndef BT_DISCRETE_DYNAMICS_WORLD_H
#define BT_DISCRETE_DYNAMICS_WORLD_H #define BT_DISCRETE_DYNAMICS_WORLD_H
#include "btDynamicsWorld.h" #include "btDynamicsWorld.h"
class btDispatcher; class btDispatcher;
class btOverlappingPairCache; class btOverlappingPairCache;
class btConstraintSolver; class btConstraintSolver;
class btSimulationIslandManager; class btSimulationIslandManager;
class btTypedConstraint; class btTypedConstraint;
#include "../ConstraintSolver/btContactSolverInfo.h" #include "../ConstraintSolver/btContactSolverInfo.h"
class btRaycastVehicle; class btRaycastVehicle;
class btIDebugDraw; class btIDebugDraw;
#include "../../LinearMath/btAlignedObjectArray.h" #include "../../LinearMath/btAlignedObjectArray.h"
///btDiscreteDynamicsWorld provides discrete rigid body simulation ///btDiscreteDynamicsWorld provides discrete rigid body simulation
///those classes replace the obsolete CcdPhysicsEnvironment/CcdPhysicsController ///those classes replace the obsolete CcdPhysicsEnvironment/CcdPhysicsController
class btDiscreteDynamicsWorld : public btDynamicsWorld class btDiscreteDynamicsWorld : public btDynamicsWorld
{ {
protected: protected:
btConstraintSolver* m_constraintSolver; btConstraintSolver* m_constraintSolver;
btSimulationIslandManager* m_islandManager; btSimulationIslandManager* m_islandManager;
btAlignedObjectArray<btTypedConstraint*> m_constraints; btAlignedObjectArray<btTypedConstraint*> m_constraints;
btIDebugDraw* m_debugDrawer; btIDebugDraw* m_debugDrawer;
btVector3 m_gravity; btVector3 m_gravity;
//for variable timesteps //for variable timesteps
btScalar m_localTime; btScalar m_localTime;
//for variable timesteps //for variable timesteps
bool m_ownsIslandManager; bool m_ownsIslandManager;
bool m_ownsConstraintSolver; bool m_ownsConstraintSolver;
btContactSolverInfo m_solverInfo; btContactSolverInfo m_solverInfo;
btAlignedObjectArray<btRaycastVehicle*> m_vehicles; btAlignedObjectArray<btRaycastVehicle*> m_vehicles;
int m_profileTimings; int m_profileTimings;
void predictUnconstraintMotion(btScalar timeStep); void predictUnconstraintMotion(btScalar timeStep);
void integrateTransforms(btScalar timeStep); void integrateTransforms(btScalar timeStep);
void calculateSimulationIslands(); void calculateSimulationIslands();
void solveConstraints(btContactSolverInfo& solverInfo); void solveConstraints(btContactSolverInfo& solverInfo);
void updateActivationState(btScalar timeStep); void updateActivationState(btScalar timeStep);
void updateVehicles(btScalar timeStep); void updateVehicles(btScalar timeStep);
void startProfiling(btScalar timeStep); void startProfiling(btScalar timeStep);
virtual void internalSingleStepSimulation( btScalar timeStep); virtual void internalSingleStepSimulation( btScalar timeStep);
void synchronizeMotionStates(); void synchronizeMotionStates();
void saveKinematicState(btScalar timeStep); void saveKinematicState(btScalar timeStep);
void debugDrawSphere(btScalar radius, const btTransform& transform, const btVector3& color);
public:
public:
///this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those
btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver); ///this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those
btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver);
virtual ~btDiscreteDynamicsWorld();
virtual ~btDiscreteDynamicsWorld();
///if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.)); ///if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
virtual void updateAabbs();
virtual void updateAabbs();
void addConstraint(btTypedConstraint* constraint);
void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false);
void removeConstraint(btTypedConstraint* constraint);
void removeConstraint(btTypedConstraint* constraint);
void addVehicle(btRaycastVehicle* vehicle);
void addVehicle(btRaycastVehicle* vehicle);
void removeVehicle(btRaycastVehicle* vehicle);
void removeVehicle(btRaycastVehicle* vehicle);
btSimulationIslandManager* getSimulationIslandManager()
{ btSimulationIslandManager* getSimulationIslandManager()
return m_islandManager; {
} return m_islandManager;
}
const btSimulationIslandManager* getSimulationIslandManager() const
{ const btSimulationIslandManager* getSimulationIslandManager() const
return m_islandManager; {
} return m_islandManager;
}
btCollisionWorld* getCollisionWorld()
{ btCollisionWorld* getCollisionWorld()
return this; {
} return this;
}
virtual void setDebugDrawer(btIDebugDraw* debugDrawer)
{ virtual void setDebugDrawer(btIDebugDraw* debugDrawer)
m_debugDrawer = debugDrawer; {
} m_debugDrawer = debugDrawer;
}
virtual btIDebugDraw* getDebugDrawer()
{ virtual btIDebugDraw* getDebugDrawer()
return m_debugDrawer; {
} return m_debugDrawer;
}
virtual void setGravity(const btVector3& gravity);
virtual void setGravity(const btVector3& gravity);
virtual void addRigidBody(btRigidBody* body);
virtual void addRigidBody(btRigidBody* body);
virtual void removeRigidBody(btRigidBody* body);
virtual void removeRigidBody(btRigidBody* body);
void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color);
void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color);
virtual void setConstraintSolver(btConstraintSolver* solver);
virtual void setConstraintSolver(btConstraintSolver* solver);
virtual int getNumConstraints() const;
virtual int getNumConstraints() const;
virtual btTypedConstraint* getConstraint(int index) ;
virtual btTypedConstraint* getConstraint(int index) ;
virtual const btTypedConstraint* getConstraint(int index) const;
virtual const btTypedConstraint* getConstraint(int index) const;
btContactSolverInfo& getSolverInfo()
{ btContactSolverInfo& getSolverInfo()
return m_solverInfo; {
} return m_solverInfo;
}
};
};
#endif //BT_DISCRETE_DYNAMICS_WORLD_H
#endif //BT_DISCRETE_DYNAMICS_WORLD_H

View File

@@ -16,8 +16,9 @@ subject to the following restrictions:
#include "btRigidBody.h" #include "btRigidBody.h"
#include "BulletCollision/CollisionShapes/btConvexShape.h" #include "BulletCollision/CollisionShapes/btConvexShape.h"
#include "LinearMath/btMinMax.h" #include "LinearMath/btMinMax.h"
#include <LinearMath/btTransformUtil.h> #include "LinearMath/btTransformUtil.h"
#include <LinearMath/btMotionState.h> #include "LinearMath/btMotionState.h"
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
btScalar gLinearAirDamping = btScalar(1.); btScalar gLinearAirDamping = btScalar(1.);
//'temporarily' global variables //'temporarily' global variables
@@ -305,4 +306,33 @@ void btRigidBody::setCenterOfMassTransform(const btTransform& xform)
} }
bool btRigidBody::checkCollideWithOverride(btCollisionObject* co)
{
btRigidBody* otherRb = btRigidBody::upcast(co);
if (!otherRb)
return true;
for (int i = 0; i < m_constraintRefs.size(); ++i)
{
btTypedConstraint* c = m_constraintRefs[i];
if (&c->getRigidBodyA() == otherRb || &c->getRigidBodyB() == otherRb)
return false;
}
return true;
}
void btRigidBody::addConstraintRef(btTypedConstraint* c)
{
int index = m_constraintRefs.findLinearSearch(c);
if (index == m_constraintRefs.size())
m_constraintRefs.push_back(c);
m_checkCollideWith = true;
}
void btRigidBody::removeConstraintRef(btTypedConstraint* c)
{
m_constraintRefs.remove(c);
m_checkCollideWith = m_constraintRefs.size() > 0;
}

View File

@@ -16,6 +16,7 @@ subject to the following restrictions:
#ifndef RIGIDBODY_H #ifndef RIGIDBODY_H
#define RIGIDBODY_H #define RIGIDBODY_H
#include "../../LinearMath/btAlignedObjectArray.h"
#include "../../LinearMath/btPoint3.h" #include "../../LinearMath/btPoint3.h"
#include "../../LinearMath/btTransform.h" #include "../../LinearMath/btTransform.h"
#include "../../BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" #include "../../BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
@@ -23,7 +24,7 @@ subject to the following restrictions:
class btCollisionShape; class btCollisionShape;
class btMotionState; class btMotionState;
class btTypedConstraint;
extern btScalar gLinearAirDamping; extern btScalar gLinearAirDamping;
@@ -57,6 +58,9 @@ class btRigidBody : public btCollisionObject
//m_optionalMotionState allows to automatic synchronize the world transform for active objects //m_optionalMotionState allows to automatic synchronize the world transform for active objects
btMotionState* m_optionalMotionState; btMotionState* m_optionalMotionState;
//keep track of typed constraints referencing this rigid body
btAlignedObjectArray<btTypedConstraint*> m_constraintRefs;
public: public:
#ifdef OBSOLETE_MOTIONSTATE_LESS #ifdef OBSOLETE_MOTIONSTATE_LESS
@@ -339,6 +343,11 @@ public:
return (getBroadphaseProxy() != 0); return (getBroadphaseProxy() != 0);
} }
virtual bool checkCollideWithOverride(btCollisionObject* co);
void addConstraintRef(btTypedConstraint* c);
void removeConstraintRef(btTypedConstraint* c);
int m_debugBodyId; int m_debugBodyId;
}; };