Hey, I have a btBoxShape that needs to have it's center of mass offset. So reading these forums I use a btCompoundShape and apply that offset there. In this example, its 1 1x1x1 box, and I have offset +1 in Y.
Then I pass the inverse of the offset into the 2nd parameter of the constructor for btDefaultMotionState, so my graphic transform is correct.
The transform I pass into the first parameter of btDefaultMotionState's constructor is a transform with an origin at (0,5,0), since that's where I want the box to start out.
Things look 'almost' right, as the box isn't colliding at spots where there is nothing there or anything like that, however the solution still looks very wrong.
If I leave the offset in the btCompoundShape to be (0,0,0) then it looks correct.
Here are videos of the right and wrong look.
Any ideas what I'm missing?
Thanks in advance
btCompoundShape with offset, wrong solution
-
- Posts: 8
- Joined: Tue May 03, 2011 9:04 pm
btCompoundShape with offset, wrong solution
You do not have the required permissions to view the files attached to this post.
-
- Posts: 8
- Joined: Tue May 03, 2011 9:04 pm
Re: btCompoundShape with offset, wrong solution
To be more specific:
Is there a accuracy loss when using btCompoundShape?
Is there any functions I need to call on the btCompoundShape after doing addChildShape().
Is there a accuracy loss when using btCompoundShape?
Is there any functions I need to call on the btCompoundShape after doing addChildShape().
-
- Posts: 3
- Joined: Wed May 04, 2011 7:19 am
Re: btCompoundShape with offset, wrong solution
Maybe you should keep the compoundshape in (0,0,0), and you can adjust the position of childShapes.
-
- Posts: 8
- Joined: Tue May 03, 2011 9:04 pm
Re: btCompoundShape with offset, wrong solution
My apologies, the offset is applied to the child, in the addChildShape function. Here is some code
If I change the offset of 1 to 0 (and the inverse) and change the start transform to +Y of 6 instead of five, the animation looks correct.
Code: Select all
btTransform centerOfMass;
centerOfMass.setIdentity();
centerOfMass.setOrigin(btVector3(0, 1, 0));
btCompoundShape *c = new btCompoundShape();
// colShape is btBoxShape with nothing set but it's size
c->addChildShape(centerOfMass, colShape);
btVector3 localInertia(0, 0, 0);
c->calculateLocalInertia(mass,localInertia);
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0, 5, 0));
// Inverse of the center of mass of the box
centerOfMass.setIdentity();
centerOfMass.setOrigin(btVector3(0, -1, 0));
btDefaultMotionState* motionState = new btDefaultMotionState(startTransform, centerOfMass);
btRigidBody::btRigidBodyConstructionInfo rbInfo(m,motionState,colShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);