Static And Dynamic Objects Not Colliding - [SOLVED]

Richmar1
Posts: 7
Joined: Wed Jul 30, 2014 6:38 pm

Static And Dynamic Objects Not Colliding - [SOLVED]

Post by Richmar1 »

Hello everyone, I hope you are all having a wonderful day. I'm having a rather aggravating problem lol. My dynamic rigidbodies collide with each other, but my dynamic rigidbody won't collide with a static rigidbodies. The setup is as simple as can get, so no fancy stuff, just all default. Here is my code and i would appreciate it if ya'll could help me. Thanks.

Code: Select all

	auto pColShape = new btBoxShape( btVector3( 0.5f, 0.5f, 0.5f ) );
	btRigidBody::btRigidBodyConstructionInfo RBConstructionInfo( 0, new btDefaultMotionState(), pColShape );
	btRigidBody* pRigidBody = new btRigidBody( RBConstructionInfo );
	m_pWorld->addRigidBody( pRigidBody , btBroadphaseProxy::DefaultFilter, btBroadphaseProxy::AllFilter );
	pRigidBody ->setCollisionFlags( pRigidBody ->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT );
	pRigidBody ->setActivationState( DISABLE_DEACTIVATION );
	pRigidBody ->activate(true);


	auto pColShape2 = new btBoxShape( btVector3( 0.5f, 0.5f, 0.5f ) );
	btVector3 Inertia( 0, 0, 0 );
	pColShape2->calculateLocalInertia( 1, Inertia );
	btTransform Trans2;
	Trans2.setIdentity();
	Trans2.setOrigin( btVector3( 0, 5, 0 ) );
	btRigidBody::btRigidBodyConstructionInfo RBConstructionInfo( 1, new btDefaultMotionState( Trans2 ), pColShape2, Inertia );
	pRigidBody2 = new btRigidBody( RBConstructionInfo );
	m_pWorld->addRigidBody( pRigidBody2, btBroadphaseProxy::DefaultFilter, btBroadphaseProxy::AllFilter );
	pRigidBody2->setActivationState( DISABLE_DEACTIVATION );
        pRigidBody2->activate(true);
Last edited by Richmar1 on Tue Aug 05, 2014 3:34 am, edited 1 time in total.
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Static And Dynamic Objects Not Colliding With Each Other

Post by xexuxjy »

Try setting all your collision flags on the object before you add it to the world. Bullet uses the state of the flags on add to create the broadphase proxy for the object.
Richmar1
Posts: 7
Joined: Wed Jul 30, 2014 6:38 pm

Re: Static And Dynamic Objects Not Colliding With Each Other

Post by Richmar1 »

^^Thank you very much my friend, I had already tried this before i posted for help. i've tried before and after. Any other ideas? On a side note, after posting the original message, I set my own overlapping Filter Callback and It DID indeed get called when the dynamic collided with the static. It just goes through it though. Here is my Overlapping Filter Callback:
struct SBroadPhaseCollisionFilterCallback : public btOverlapFilterCallback
{
virtual bool needBroadphaseCollision( btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1 ) const
{
//Make Sure EVERYTHING Collides just for testing this issue.
return true;
}
};


SBroadPhaseCollisionFilterCallback* pCB = new SBroadPhaseCollisionFilterCallback();
m_pWorld()->getPairCache()->setOverlapFilterCallback( pCB );
Thanks again for your time. If anyone understands why this happens lol, please let me know.

EDIT: I forgot to mention that i am using the latest bullet source from the repository.
Richmar1
Posts: 7
Joined: Wed Jul 30, 2014 6:38 pm

Re: Static And Dynamic Objects Not Colliding - [SOLVED]

Post by Richmar1 »

Okay, everything is fixed now. The code I pasted above was not the issue. The issue was creating the collision shapes. I was passing in a negative value to the "HalfExtents" argument by accident *facepalm*. I was generating the extents programatically and one of the axis resulted in a negative value, I did not know this. This resulted in no collision geometry being created. Thank you all for your help.