Skip to content

Commit

Permalink
Introduce kF_UseGjkConvexCastRaytest, and make kF_UseSubSimplexConvex…
Browse files Browse the repository at this point in the history
…CastRaytest the default for btCollisionWorld::rayTest See #34

Add btCollisionObject::setIgnoreCollisionCheck to disable collisions between specific instances, without having a btTypedConstraint. See #165

Make btMultiBody and btMultiBodyJointMotor backwards compatible with Bullet 2.82 API (single-DOF API)
  • Loading branch information
erwincoumans committed May 1, 2014
1 parent 907ac49 commit 7151865
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,23 +394,16 @@ btMultiBody* FeatherstoneMultiBodyDemo::createFeatherstoneMultiBody(class btMult
if (1)
{
btCollisionShape* box = new btBoxShape(btVector3(halfExtents[0],halfExtents[1],halfExtents[2])*scaling);
btRigidBody* body = new btRigidBody(mass,0,box,inertia);
btMultiBodyLinkCollider* col= new btMultiBodyLinkCollider(bod,-1);

body->setCollisionShape(box);
col->setCollisionShape(box);

btTransform tr;
tr.setIdentity();
tr.setOrigin(local_origin[0]);
tr.setRotation(btQuaternion(quat[0],quat[1],quat[2],quat[3]));
body->setWorldTransform(tr);
col->setWorldTransform(tr);

world->addCollisionObject(col, 2,1+2);
col->setFriction(friction);
bod->setBaseCollider(col);

bod->setBaseCollider(col);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ bool btCollisionDispatcher::needsCollision(const btCollisionObject* body0,const

if ((!body0->isActive()) && (!body1->isActive()))
needsCollision = false;
else if (!body0->checkCollideWith(body1))
else if ((!body0->checkCollideWith(body1)) || (!body1->checkCollideWith(body0)))
needsCollision = false;

return needsCollision ;
Expand Down
35 changes: 30 additions & 5 deletions src/BulletCollision/CollisionDispatch/btCollisionObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,11 @@ ATTRIBUTE_ALIGNED16(class) btCollisionObject
/// If some object should have elaborate collision filtering by sub-classes
int m_checkCollideWith;

btAlignedObjectArray<const btCollisionObject*> m_objectsWithoutCollisionCheck;

///internal update revision number. It will be increased when the object changes. This allows some subsystems to perform lazy evaluation.
int m_updateRevision;

virtual bool checkCollideWithOverride(const btCollisionObject* /* co */) const
{
return true;
}

public:

Expand Down Expand Up @@ -225,7 +223,34 @@ ATTRIBUTE_ALIGNED16(class) btCollisionObject
return m_collisionShape;
}


void setIgnoreCollisionCheck(const btCollisionObject* co, bool ignoreCollisionCheck)
{
if (ignoreCollisionCheck)
{
//We don't check for duplicates. Is it ok to leave that up to the user of this API?
//int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
//if (index == m_objectsWithoutCollisionCheck.size())
//{
m_objectsWithoutCollisionCheck.push_back(co);
//}
}
else
{
m_objectsWithoutCollisionCheck.remove(co);
}
m_checkCollideWith = m_objectsWithoutCollisionCheck.size() > 0;
}

virtual bool checkCollideWithOverride(const btCollisionObject* co) const
{
int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
if (index < m_objectsWithoutCollisionCheck.size())
{
return false;
}
return true;
}




Expand Down
7 changes: 4 additions & 3 deletions src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ void btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,con
//btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
bool condition = true;
btConvexCast* convexCasterPtr = 0;
if (resultCallback.m_flags & btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest)
convexCasterPtr = &subSimplexConvexCaster;
else
//use kF_UseSubSimplexConvexCastRaytest by default
if (resultCallback.m_flags & btTriangleRaycastCallback::kF_UseGjkConvexCastRaytest)
convexCasterPtr = &gjkConvexCaster;
else
convexCasterPtr = &subSimplexConvexCaster;

btConvexCast& convexCaster = *convexCasterPtr;

Expand Down
7 changes: 5 additions & 2 deletions src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ subject to the following restrictions:
struct btBroadphaseProxy;
class btConvexShape;


class btTriangleRaycastCallback: public btTriangleCallback
{
public:
Expand All @@ -32,10 +33,12 @@ class btTriangleRaycastCallback: public btTriangleCallback
//@BP Mod - allow backface filtering and unflipped normals
enum EFlags
{
kF_None = 0,
kF_None = 0,
kF_FilterBackfaces = 1 << 0,
kF_KeepUnflippedNormal = 1 << 1, // Prevents returned face normal getting flipped when a ray hits a back-facing triangle
kF_UseSubSimplexConvexCastRaytest = 1 << 2, // Uses an approximate but faster ray versus convex intersection algorithm
///SubSimplexConvexCastRaytest is the default, even if kF_None is set.
kF_UseSubSimplexConvexCastRaytest = 1 << 2, // Uses an approximate but faster ray versus convex intersection algorithm
kF_UseGjkConvexCastRaytest = 1 << 3,
kF_Terminator = 0xFFFFFFFF
};
unsigned int m_flags;
Expand Down
50 changes: 30 additions & 20 deletions src/BulletDynamics/Dynamics/btRigidBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,38 +317,48 @@ void btRigidBody::setCenterOfMassTransform(const btTransform& xform)
}


bool btRigidBody::checkCollideWithOverride(const btCollisionObject* co) const
{
const btRigidBody* otherRb = btRigidBody::upcast(co);
if (!otherRb)
return true;

for (int i = 0; i < m_constraintRefs.size(); ++i)
{
const btTypedConstraint* c = m_constraintRefs[i];
if (c->isEnabled())
if (&c->getRigidBodyA() == otherRb || &c->getRigidBodyB() == otherRb)
return false;
}

return true;
}



void btRigidBody::addConstraintRef(btTypedConstraint* c)
{
///disable collision with the 'other' body

int index = m_constraintRefs.findLinearSearch(c);
//don't add constraints that are already referenced
btAssert(index == m_constraintRefs.size());
if (index == m_constraintRefs.size())
m_constraintRefs.push_back(c);

m_checkCollideWith = true;
{
m_constraintRefs.push_back(c);
btCollisionObject* colObjA = &c->getRigidBodyA();
btCollisionObject* colObjB = &c->getRigidBodyB();
if (colObjA == this)
{
colObjA->setIgnoreCollisionCheck(colObjB, true);
}
else
{
colObjB->setIgnoreCollisionCheck(colObjA, true);
}
}
}

void btRigidBody::removeConstraintRef(btTypedConstraint* c)
{
int index = m_constraintRefs.findLinearSearch(c);
//don't remove constraints that are not referenced
btAssert(index < m_constraintRefs.size());
m_constraintRefs.remove(c);
m_checkCollideWith = m_constraintRefs.size() > 0;
btCollisionObject* colObjA = &c->getRigidBodyA();
btCollisionObject* colObjB = &c->getRigidBodyB();
if (colObjA == this)
{
colObjA->setIgnoreCollisionCheck(colObjB, false);
}
else
{
colObjB->setIgnoreCollisionCheck(colObjA, false);
}
}

int btRigidBody::calculateSerializeBufferSize() const
Expand Down
4 changes: 1 addition & 3 deletions src/BulletDynamics/Dynamics/btRigidBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class btRigidBody : public btCollisionObject
//m_optionalMotionState allows to automatic synchronize the world transform for active objects
btMotionState* m_optionalMotionState;

//keep track of typed constraints referencing this rigid body
//keep track of typed constraints referencing this rigid body, to disable collision between linked bodies
btAlignedObjectArray<btTypedConstraint*> m_constraintRefs;

int m_rigidbodyFlags;
Expand Down Expand Up @@ -506,8 +506,6 @@ class btRigidBody : public btCollisionObject
return (getBroadphaseProxy() != 0);
}

virtual bool checkCollideWithOverride(const btCollisionObject* co) const;

void addConstraintRef(btTypedConstraint* c);
void removeConstraintRef(btTypedConstraint* c);

Expand Down
13 changes: 7 additions & 6 deletions src/BulletDynamics/Featherstone/btMultiBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ class btMultiBody
// initialization
//

btMultiBody(int n_links, // NOT including the base
btScalar mass, // mass of base
const btVector3 &inertia, // inertia of base, in base frame; assumed diagonal
bool fixedBase, // whether the base is fixed (true) or can move (false)
bool canSleep,
bool multiDof
btMultiBody(int n_links, // NOT including the base
btScalar mass, // mass of base
const btVector3 &inertia, // inertia of base, in base frame; assumed diagonal
bool fixedBase, // whether the base is fixed (true) or can move (false)
bool canSleep,
bool multiDof = false
);


~btMultiBody();

void setupPrismatic(int i, // 0 to num_links-1
Expand Down
6 changes: 6 additions & 0 deletions src/BulletDynamics/Featherstone/btMultiBodyJointMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ subject to the following restrictions:
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"


btMultiBodyJointMotor::btMultiBodyJointMotor(btMultiBody* body, int link, btScalar desiredVelocity, btScalar maxMotorImpulse)
:btMultiBodyJointMotor(body,link,0,desiredVelocity,maxMotorImpulse)
{
}


btMultiBodyJointMotor::btMultiBodyJointMotor(btMultiBody* body, int link, int linkDoF, btScalar desiredVelocity, btScalar maxMotorImpulse)
//:btMultiBodyConstraint(body,0,link,-1,1,true),
:btMultiBodyConstraint(body,body,link,link,1,true),
Expand Down
1 change: 1 addition & 0 deletions src/BulletDynamics/Featherstone/btMultiBodyJointMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class btMultiBodyJointMotor : public btMultiBodyConstraint

public:

btMultiBodyJointMotor(btMultiBody* body, int link,btScalar desiredVelocity, btScalar maxMotorImpulse);
btMultiBodyJointMotor(btMultiBody* body, int link, int linkDoF, btScalar desiredVelocity, btScalar maxMotorImpulse);
virtual ~btMultiBodyJointMotor();

Expand Down

0 comments on commit 7151865

Please sign in to comment.