javaphysicsjbullet

JBullet - Convex Shapes not working properly when static


I use dynamic box-shapes bodies for collision in JBullet. They collide with each other correctly. But I'm fiddling arround with building the world and came upon some strange problems.

When I'm trying to make convex RigidBodies (BoxShape or TriangleShape) static (by setting mass to 0), collision is only working at some kind of point at (0,0,0) instead of the given shape. If it's dynamic, it's working well.

Additional problem and maybe there's some link: If I use a BvhTriangleMeshShape or GImpactMeshShape it's working well only if dynamic and not colliding anyway0 when it's static (despite the fact BvhTriangleMeshShape is to be used for static bodies).

Here's how I init the world:

BroadphaseInterface broadphase = new DbvtBroadphase();
CollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration();
CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfiguration);
ConstraintSolver solver = new SequentialImpulseConstraintSolver();
dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld.setGravity(new Vector3f(0, 0, 0));
GImpactCollisionAlgorithm.registerAlgorithm(dispatcher);

The problematic object:

Vector3f inertia = new Vector3f(0, 0, 0);
MotionState motion = new DefaultMotionState(new Transform());

//BvhTriangleMeshShape shape = ShapeUtil.getShapeFromModel(testSphere);
//CompoundShape shape = ShapeUtil.getCompoundShapeFromModel(testSphere);
//GImpactMeshShape shape = ShapeUtil.getGImpactShapeFromModel(testSphere);
BoxShape shape = new BoxShape (new Vector3f(2,2,2));
//TriangleShape shape = new TriangleShape(new Vector3f(-20,0,-10), new Vector3f(20,20,-10), new Vector3f(20,-20,-10));

RigidBodyConstructionInfo constructionInfo = new RigidBodyConstructionInfo(0, motion, shape, inertia);
RigidBody body = new RigidBody(constructionInfo);
//body.setCollisionFlags(CollisionFlags.STATIC_OBJECT);

dynamicsWorld.addRigidBody(body);
this.bodies[64] = body;

Can anyone please help me? I'm using the JBullet version from 10/10/2010. Thanks in advance.


Solution

  • It seems I found the problem. I solved it by replacing the line

    MotionState motion = new DefaultMotionState(new Transform());
    

    by

    Transform transform = new Transform();
    transform.setIdentity();
    MotionState motion = new DefaultMotionState(transform);
    

    It looks like Transform's default Constructor won't create an identity Transform as I'd expect.