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.