CompoundShape, what do i make wrong?

Empire-Phoenix
Posts: 24
Joined: Sat Nov 07, 2009 7:57 pm

CompoundShape, what do i make wrong?

Post by Empire-Phoenix »

Well I created using a simple grafic engine a small box that falls on a long flat box.
Works as expected so far, but now the problem, since I want to use a bit more complex shapes than only boxes (in my case combinations of multiple boxes) I use a CompoundShape.

For testing I use a BoxShape (the same as before in the test )and add it to the CompoundShape
with a no rotation and at 0,0,0.

However the visible Box now start to behave really strange (moving half through objects, rolling like a ball, ect)

Why is it doing this? Shouldn't it behave exactly as before?
Jasonrun
Posts: 11
Joined: Fri Oct 30, 2009 7:44 pm

Re: CompoundShape, what do i make wrong?

Post by Jasonrun »

My guess is you are somehow translating the position of your child box so that your compound object actually only has "solid" areas somewhere not centered on it. This bit below works for me, and I can reproduce what you describe by changing the localTransform from the local origin. startTransform moves the box up 16 units in the y direction so that it can fall. If that's not the issue then posting your code could help.

Code: Select all

boxShape = new btBoxShape(btVector3(1,1,1));
btCompoundShape* colShape = new btCompoundShape;
btTransform localTransform;
localTransform.setIdentity();
localTransform.setOrigin(btVector3(0, 0, 0));

colShape->addChildShape(localTransform,boxShape); //EDIT I forgot to include this line before

btTransform startTransform;
startTransform.setIdentity();

btScalar	mass(10.f);
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0,0,0);
if (isDynamic)
	colShape->calculateLocalInertia(mass,localInertia);
startTransform.setOrigin(btVector3(0,16,0));

btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

body->setFriction(0.3f);
body->setRestitution(0.5f);
body->setDamping(0.1f,0.1f);

body->setLinearFactor(btVector3(1,1,0)); //For 2d effect
body->setAngularFactor(btVector3(0,0,1)); //For 2d effect
dynamicsWorld->addRigidBody(body);
Last edited by Jasonrun on Sun Nov 08, 2009 9:02 pm, edited 1 time in total.
Empire-Phoenix
Posts: 24
Joined: Sat Nov 07, 2009 7:57 pm

Re: CompoundShape, what do i make wrong?

Post by Empire-Phoenix »

Yep, that helped, seems like I forgot this one:
localTransform.setIdentity();

Thanks