Unable to orient a child shape in a btCompundShape

Verbo
Posts: 39
Joined: Fri May 08, 2009 9:27 pm

Unable to orient a child shape in a btCompundShape

Post by Verbo »

Hi,

I am trying to add a capsule shape in a btCompoundShape and I want to orient the capsule local Y axis along a specific vector, let's call it "V". I have no problem offsetting the position of the capsule via the local transform. However, when I try to set the "V" vector orientation inside the local transform (in the rigid body coord space), I never get the expected orientation. But weirdly, if I try to hardcode an arbitrary rotation in the local transform, let's say 30 degree around the Z axis (set via setValue() ), then it works.

Am I going nuts or am I missing something? :roll:

thx.

Verbo
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Unable to orient a child shape in a btCompundShape

Post by Erwin Coumans »

Please post Bullet specific issues in the proper forum next time.

Others might be able to help, if you provide some code-snippet on how you rotate the child shape.
Thanks,
Erwin
Verbo
Posts: 39
Joined: Fri May 08, 2009 9:27 pm

Re: Unable to orient a child shape in a btCompundShape

Post by Verbo »

Hi again (sorry to hav eposted to the wrong thread),

I will provide some visual and a simplified version of my code at the bottom, to show you my problem.

First, here is a picture of my child capsule WITHOUT orientation, with the desired orientation I want to apply to it:
ChildCapsuleWithoutRotation.JPG
Then, here is the picture of my child capsule WITH the problematic orientation applied to it:
ChildCapsuleWithRotation.JPG
Ok, first, just to avoid confusion, I validated that my direction vector was ok.

Here is a simplified version of my code that applies the rotation. I did not put everything, just the essential so that you can see how I setup the rotation:
*******************************************************************************************************************

btCompoundShape* pCompoundBodyCollisionShape = new btCompoundShape;
...
...
...
if(pCompoundBodyCollisionShape)
{
// Add the main body collision shape to the compound shape.
btTransform localTransform;
localTransform.setIdentity();
pCompoundBodyCollisionShape->addChildShape(localTransform, BulletPhysicsUtils::CreateConvexVerticesShapeFromMesh(*pMainBodyMesh, localScaling) );
...
...
...
// Get the car main body entity world transform.
btTransform bulletMainBodyEntityTransformWS;
BulletPhysicsUtils::ConvertVtTransformToBulletTransform(pTargetObject->GetWorldMatrix(),bulletMainBodyEntityTransformWS);

btScalar hardpointVerticalOffset(-0.7);
btVector3 chassisConnectionPointES = btVector3(bulletWheelPositionES.x(), hardpointVerticalOffset, bulletWheelPositionES.z());

btVector3 bulletCapsuleSnapPointToBody = bulletMainBodyEntityTransformWS( btVector3(btScalar(0.0),hardpointVerticalOffset,btScalar(0.0)) );
btVector3 bulletBodyToHardPointVec = bulletMainBodyEntityTransformWS(chassisConnectionPointES ) - bulletCapsuleSnapPointToBody;

btScalar capsuleLength = bulletBodyToHardPointVec.length();
btScalar capsuleRadius(0.15);

if( btCapsuleShape* pNewHardPointToBodyCapsule = new btCapsuleShape(capsuleRadius,capsuleLength) )
{
btTransform localTransform;
localTransform.setIdentity();

btVector3 bulletCapsuleUp = bulletBodyToHardPointVec.normalized();
btVector3 bulletCapsuleRight = bulletCapsuleUp.cross( bulletMainBodyEntityTransformWS.getBasis()[1] ).normalized();
btVector3 bulletCapsuleDir = bulletCapsuleRight.cross(bulletCapsuleUp).normalized();

btMatrix3x3 capsuleOrientation(bulletCapsuleRight.x(),bulletCapsuleRight.y(),bulletCapsuleRight.z(),
bulletCapsuleUp.x(),bulletCapsuleUp.y(),bulletCapsuleUp.z(),
bulletCapsuleDir.x(),bulletCapsuleDir.y(),bulletCapsuleDir.z() );

capsuleOrientation = bulletMainBodyEntityTransformWS.getBasis().inverse() * capsuleOrientation ;


localTransform.setBasis(capsuleOrientation);
localTransform.setOrigin( bulletMainBodyEntityTransformWS.inverse() * ( (bulletBodyToHardPointVec* btScalar(0.5) + bulletMainBodyEntityTransformWS.getOrigin()) ) );

pCompoundBodyCollisionShape->addChildShape(localTransform,pNewHardPointToBodyCapsule);
}

}


Basically, what I wanted to do is to be able to keep using a raycast vehicle, but still allow wheels to be way out of the car body. The problem with that is that I need the collision of the chassis to be extended up to a zone over each wheel, or weird effect happens, like the wheels encroaching while the body is bumping on walls. My first guess was to simply add a simple capsule over each wheel, but then it could mean that some other rigid body could slip through between the wheel and the car body. So I wanted to add a capsule that extend from the car body center up to the wheel hard point, and that's where I am having the orientation problem. This is just experimental, I am not yet convinced this will work fine :)

Thanks for the help!

Verbo
You do not have the required permissions to view the files attached to this post.