Transform class and collision bug

Topics: Developer Forum
Aug 23, 2007 at 1:40 AM
Hi,

Has the btTransform class been deliberately left out of BulletX?

I am trying to port the RaycastVehicle class from the Bullet code.

Comparing Bullet to BulletX in other classes that have already been ported, it seems that transforms are being tracked by separate Matrix and Vector variables - is this the best pattern to follow?

I have completed an initial port of RaycastVehicle and created a basic world with a BoxShape ground object and a Vehicle. (I added CreateRigidVehicle to DemoGame to create the vehicle shape and add the wheels, according to the code in the Bullet Demo - VehicleDemo.cpp).

When I run the project and the Vehicle object collides with the Ground object, I get a NullReferenceException in this class and function at the indicated ==> line :

public class ConvexConvexAlgorithm : CollisionAlgorithm, IDisposable
{
public override void ProcessCollision(CollisionObject bodyA, CollisionObject bodyB, DispatcherInfo dispatchInfo, ManifoldResult resultOut)
{
if (_manifold == null)
{
//swapped?
_manifold = Dispatcher.GetNewManifold(bodyA, bodyB);
_ownManifold = true;
}
resultOut.SetPersistentManifold(_manifold);

ConvexShape min0 = bodyA.CollisionShape as ConvexShape;
ConvexShape min1 = bodyB.CollisionShape as ConvexShape;

GjkPairDetector.ClosestPointInput input = new DiscreteCollisionDetectorInterface.ClosestPointInput();

//TODO: if (dispatchInfo.m_useContinuous)
_gjkPairDetector.setMinkowskiA(min0);
_gjkPairDetector.setMinkowskiB(min1);
==> input.MaximumDistanceSquared = min0.Margin + min1.Margin + PersistentManifold.ContactBreakingThreshold;
input.MaximumDistanceSquared *= input.MaximumDistanceSquared;

// input.m_maximumDistanceSquared = 1e30f;

input.TransformA = bodyA.WorldTransform;
input.TransformB = bodyB.WorldTransform;

_gjkPairDetector.GetClosestPoints(input, resultOut, dispatchInfo.DebugDraw);
}
}

min0 is null.

I know that this is a long shot, but has anybody encountered something similar? (I know that it is hard without the entire code).

I am reviewing all of my code to try to find any bugs, comparing to the original Bullet code.

I found this bug already:

public class CompoundCollisionAlgorithm : CollisionAlgorithm
{
public override void ProcessCollision(
CollisionObject bodyA,
CollisionObject bodyB,
DispatcherInfo dispatchInfo, ManifoldResult resultOut)
{
//Begin

/// Kim Groves
/// BUG: This line used to read "? bodyB : bodyB;"
CollisionObject collisionObject = _isSwapped ? bodyB : bodyA;
CollisionObject otherObject = _isSwapped ? bodyA : bodyB;

//Debug.Assert(collisionObject.getCollisionShape().isCompound());
BulletDebug.Assert(collisionObject.CollisionShape.IsCompound);

CompoundShape compoundShape = (CompoundShape)collisionObject.CollisionShape;

int childrenNumber = _childCollisionAlgorithms.Count;

for (int i = 0; i < childrenNumber; i++)
{
CompoundShape childShape = compoundShape.GetChildShape(i) as CompoundShape;

Matrix orgTransform = collisionObject.WorldTransform;
CollisionShape orgShape = collisionObject.CollisionShape;

Matrix childTransform = compoundShape.GetChildTransform(i);
Matrix newChildWorld = orgTransform * childTransform;

collisionObject.WorldTransform = newChildWorld;
collisionObject.CollisionShape = childShape;
_childCollisionAlgorithmsi.ProcessCollision(collisionObject, otherObject, dispatchInfo, resultOut);

collisionObject.CollisionShape = orgShape;
collisionObject.WorldTransform = orgTransform;
}
}
}

If I get the code to work, should I submit it as a patch?

Kim
Coordinator
Aug 23, 2007 at 6:07 AM
Hi,

The bug with "? bodyB : bodyB;" was already reported and fixed.
Transform class is nothing than Matrix3x3 + Vector3 in XNA it's just Matrix. Where Bullet uses Matrix3x3 you should use MathHelpers overrides that doesn't use last matrix row or you should set translation to (0, 0, 0, 1), after multiply or other actions set translation back.
About Nullreference I can't tell anything without code and debugging just try to see why CollisionShape is null or why it's not Convex.

Thanks,
KleMiX