btCompound and local vs world trafos

Post Reply
Moose
Posts: 31
Joined: Mon Nov 04, 2013 10:58 am

btCompound and local vs world trafos

Post by Moose »

Hi all,

I am new to that forum. Currently developing a bullet integration for an abstracted physics engine interface into a commercial visualization application that sports a rather complex scene graph structure. Please excuse my lack of in-depth bullet knowledge as I am relatively new to this.

Basically, I have succeeded in integrating quite a few shapes and meshes, as well as several Constraints and now struggling with compound shapes.

The issue is, that they do not behave the way I expect them to.

Let me illustrate an example with a compound that contains only one shape. A sphere. It is not in the origin of the ocmpound but has a local translation. What I do is roughly following (I extract code but this is not a working example):


btSphereShape *sphere = new btSphereShape(100);

and a plane on the ground that is a static object and has no translation or mass or anything.

Then a compound:

btCompound *compound = new btCompound(true);
sb->addChildShape(btTransform( /*translation is 100, 10000, 0 */), sphere);

btTransform principal;
btVector3 inertia;
btScalar *masses = new btScalar[1];
masses[0] = 1;
compound->createAabbTreeFromChildren();
compound->calculatePrincipalAxisTransform(masses, principal, inertia);
delete[] masses;

btVector3 inertia(0, 0, 0);
compound->calculateLocalInertia(1.0, inertia);
motionState = new btDefaultMotionState(btTransform( /*translation is 0, 0, 0 */));
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, motionState, compound, inertia);
btRigidBody *cb = new btRigidBody(rigidBodyCI);
cb->setActivationState(DISABLE_DEACTIVATION);

// all right. There might be errors as I free-typed that but I guess you see what I'm aiming at.

In my test program I start the simulation and output the compound's motion state transform and see if it collides with anything. I would expect the compound (the ball) to fall down onto the ground plane as it has a local transform to the center of mass (origin?) of the compound and then come to rest after falling 9950 (10000 - 50) or so units. Which would mean, it starts at 0.0 (the origin of the compound) and then descends to -9950. Instead I see this:

....start...
compound X and Y: 0 -8.175 collision with 0
compound X and Y: 0 -286.125 collision with 0
compound X and Y: 0 -885.625 collision with 0
compound X and Y: 0 -1915.68 collision with 0
compound X and Y: 0 -3338.13 collision with 0
compound X and Y: 0 -4986.75 collision with 0
compound X and Y: 0 -6965.1 collision with 0
compound X and Y: 0 -9499.35 collision with 0 // all good to here
compound X and Y: 20.1942 -10041.8 collision with 1 objects (ground)
compound X and Y: 47.4288 -10244.1 collision with 1 objects (ground)
compound X and Y: 74.9495 -10750.2 collision with 1 objects (ground)
compound X and Y: 102.315 -11589.3 collision with 1 objects (ground)
compound X and Y: 126.961 -12732.6 collision with 1 objects (ground)
compound X and Y: 152.895 -14129.2 collision with 1 objects (ground)
compound X and Y: 177.535 -15773.3 collision with 1 objects (ground)
compound X and Y: 204.799 -17830.2 collision with 1 objects (ground)
compound X and Y: 232.211 -20285.8 collision with 1 objects (ground)
compound X and Y: 259.406 -23039.4 collision with 1 objects (ground)
compound X and Y: 284.545 -26203 collision with 1 objects (ground)
compound X and Y: 308.853 -29700.6 collision with 1 objects (ground)
... snip... falls further into the abyss.

You see, I get a collision with the ground but the object continues to fall, which I don't get. Also, it appears to drift to the side after the collision which makes no sense either.

Please note that when I drop a compound with two objects, both roughly at the same position it seems to be OK. Can't know for sure though. Also, when I drop other stuff, like only the ball with no compound or a triangle mesh or anything else I have the simulation behaves nicely.

Can anyone shed some light on this? My suspicion is, that I use the local trafo in the compound wrong. Or misunderstand the entire motionstate thing. I already learned from an old post in that forum, that what bullet calls the center of mass is not actually the center of mass but the local transform of a child to the compound.

By experiment I found that when I use btCompound::calculatePrincipalAxisTransform() I can determine the actual center of mass for the compound but it comes in world trafo as it seems. Why is that?

I understand this function is supposed to help me integrating this into a scene graph based application that would typically have a group node for the compound. Can you give me any example of how this is done best?

All, right, that'll bit it for now.

Thanks a bunch for any response.

Moose
Post Reply