Getting position of children of btCompountShape

sipickles
Posts: 44
Joined: Thu Aug 07, 2008 6:57 am

Getting position of children of btCompountShape

Post by sipickles »

Hello,

I am slightly confused about the CORRECT way to deduce the position of children of btCompoundShapes.

I have a concave object, actually composed of several btBoxShape collision objects. These children are added like this:

Code: Select all

			btTransform t;
			t.setIdentity();
			t.setOrigin( offset );
			m_compoundShape->addChildShape( t, child->GetBody()->getCollisionShape() );
All forces act on the btRigidBody created using the btCompoundShape.

At render time I need to know the position of each child, relative to the btRigidBody:

Code: Select all

	btTransform bodyTrans, childTrans;
	btMotionState* ms;

	ms = m_body()->getMotionState();
	ms->getWorldTransform(bodyTrans);
	childTrans = m_compoundShape->getChildTransform( 0 );  // other indexes too
	bodyTrans *= childTrans;

// render using bodytrans

My problem is, the position of the rigidBody and that of the children resolved by the above code, do not match.

I think the bodyTrans *= childTrans line is the bad one, but dont know how to progress.

Thanks for any advice.

Simon
sipickles
Posts: 44
Joined: Thu Aug 07, 2008 6:57 am

Re: Getting position of children of btCompountShape

Post by sipickles »

I'm still struggling with this problem, and thought I'd try to explain exactly what seems to happen.

I am building a game tool which allows you to connect objects together to form bigger compound models.

My CModel class has a btCompoundShape. When creating the CModel, the first child shape I add to the btCompoundShape is positioned centrally, with an identity btTransform. This is my root object to which others are supposed to join.

After adding one child shape as the root, I create the btRigidBody and start rendering the object.

When I want to join a second child shape, I destroy the original model and remake it. I add the previously added root object (with the identity btTransform again), then I add the new child shape to the CModel's btCompoundShape. This time I use the appropiate btTransform so the child is in the right place.

I now make a new btRigidBody for the CModel, and resume rendering.

EXPECTED OUTCOME - 1st child appears in same place as when rendered alone, with 2nd child offset as per supplied btTransform.
ACTUAL OUTCOME - 1st and second children have correct position relative to each other, but jump sideways slightly. 1st child is no longer at origin.

Since I am supplied the position for rendering by the btRigidBody's btMotionState, I am wondering if the centre of gravity has changed when a 2nd object is added?

Is that the case? thanks!

Simon


----

EDIT : The source only shows the AABB being stretched to accomodate the new btCompoundChild shape when a new child is added.... So I am baffled! :)
sipickles
Posts: 44
Joined: Thu Aug 07, 2008 6:57 am

Re: Getting position of children of btCompountShape

Post by sipickles »

I've pinned down the problem to the function:

void btCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const


When this is called during the btRigidBody creation process, calculates the inertia based on the size of the AABB. The AABB obviously changes when a second shape is added to the btCompoundShape, hence the local inertia changes too. Fair enough!

I imagine this means the btRigidBody has a new centre.

A simple fix is to not set the startTransform used by btRigidBodyContrucitonInfo to this new centre!

I will turn it back on in the game proper!