Intro to the board and inquiring about btCompoundShape

tomacpace
Posts: 3
Joined: Sun Apr 11, 2010 7:07 pm

Intro to the board and inquiring about btCompoundShape

Post by tomacpace »

Hi everyone!

I am making my first post here, and it's nice to join a group of open source people.


The Bullet Physics library is very large, and in past projects I normally have simply written my own methods for applying movement, but the combination of everything into a single package provides an ideal solution. The only problem for me, personally, is that my use of bullet is intermediated by another, non-bullet library.

90% of the other library is bullet-independant, and whatever works with bullet, there are in-between methods. So I"ve had to struggle with learning everything and building my own methods to get use of bullet, and I've had most success so far, woo hoo!


But now I'm coming to a real tricky situation: the inbetween library has no support for bullet collision shapes beyond the box, cone, cylinder, convex hull and triangle mesh. None of these provided the solution I was looking for in the current task of my project, and so I did my own bullet research, and decided my collision shape requirement is the btCompoundShape class.

I've set up the object and given it the proper children objects (as follows), and think all requirements are satisfied. But I think something is still missing, because there are some strange behaviours. I've looked on the forum for introductory information on the btCompoundShape and there's too much for me to absorb, and I"ve looked on the doxygen info and tried to cover all the required elements.

Obviously there are a million things that can go wrong with physics setups, but I'm only looking for pointers and suggestions, and help if anyone happens to have experienced something like this.



The scenario:

I have a 3D object modelled in blender, plus two big collision boxes that represent the collision area, and I'm firing projectiles at the model.
The model and boxes are being exported from blender, and the two boxes are interpreted as independant btRigidBody objects.

The basic code I've written to build the btCompoundShape follows, with my project-specifics removed for clarity):

Code: Select all

softRigidDynamicsWorld->removeRigidBody(collisionBox1->_btRigidBody);
softRigidDynamicsWorld->removeRigidBody(collisionBox2->_btRigidBody);

btCompoundShape *_btCompoundShape = new btCompoundShape();
_btCompoundShape->addChildShape(  collisionBox1->_btRigidBody->getWorldTransform(), collisionBox1->_btRigidBody->getCollisionShape() );
_btCompoundShape->addChildShape(  collisionBox2->_btRigidBody->getWorldTransform(), collisionBox2->_btRigidBody->getCollisionShape() );

// assorted memory management lines...

collisionBox1->_btRigidBody->setCollisionShape( _btCompoundShape);

softRigidDynamicsWorld->addRigidBody( collisionBox1->_btRigidBody);
I hope that's clear and detailed enough.



The problem:

The model is stationary, and I am throwing a single projectile.
The projectile and collisionBoxes are all using box collision shapes.

Success: When the projectiles travel through the full volume of the collisionshape and miss the two boxes, nothing happens.
Success: When they hit collisionBox1, they lose their energy and the energy is transferred to the object, and it gets tossed in the same direction as the projectiles were travelling.
Success: Single projectile hits collisionBox1, it will lose its energy and the whole model gets tossed in the projectile direction.
Inconsistent: Single projectile hits collisionBox2, projectile will lose some of its energy and the whole model gets tossed in the projectile direction.
Failure: Projectile hits collisionBox2, projectile goes through collisionBox2 and a small amount of energy goes into the model and it moves back slowly. (not sure if it depends on where on the collisionBox2 the contact is made)
Failure: Projectile hits collisionBox2, projectile goes into collisionBox2, and then bounces back out the way it went in, and the model moves basically in the opposite direction the projectile was going. As if there was a second object the projectile hit, it bounced backward and hit the model from the other side.

I've also been using a bit of code to catch collisions between particular objects, and I'm confused by how a single object pair may have multiple manifold contact points if they're both boxes, but that's a separate issue.
tomacpace
Posts: 3
Joined: Sun Apr 11, 2010 7:07 pm

Re: Intro to the board and inquiring about btCompoundShape

Post by tomacpace »

Hi everyone again...

The solution was right in front of me all this time (literally), but I couldn't see it because of the angles and perspective. The collision boxes are being rendered, and as exported from Blender was inside out. The reason I didn't notice is because the collisionBox2 is very thin, about the depth of a stone projectile, and I was looking at it along the normals of the large faces.

So that makes sense how the projectile was able to enter into the object, bounce and come back out, and at the same time as it was coming back toward me, it would hit the OTHER side, and drag the whole model toward me. Very weird behaviour, but it makes sense with this discovery.

I just don't understand why the projectile would actually still sometimes go all the way through the collision shape without registering a hit.


So, there could be a million different possibilities to all the problems that can exist, and fortunately this one was solved relatively quickly. When switching to a different perspective, I saw a slight irregularity in the rendering of the collision box, setting off red flags in my head so investigation led me to the blender file. I flipped the normals, 100% testing is success for collision.

I like to learn solutions myself instead of resorting to help, because it stretches my capabilities and competency (even if it's very limited to begin with). Hope this helps anyone in the future.


Glad to be part of the forum now, too.