Collision()

Hopefully I can explain this a lucent manner.



It appears that if a dynamic gimpact collision shape is constructed via



[java] CollisionShapeFactory.createDynamicMeshShape() [/java]



and attached to a PhysicsNode, that a call to public void collision (PhysicsCollisionEvent event) is not performed when a collision does occur. However, the dynamical effects of the collision do occur. But when a static collision shape is created via



[java]CollisionShapeFactory.createMeshShape()[/java]



calls are made to public void collision(PhysicsCollisionEvent event) when a collision occurs.



I have included a test case:



[java]public class Main extends SimpleBulletApplication implements PhysicsCollisionListener

{

pOb p1;

pOb p2;

pOb p3;

pOb1 p1_1;

float totalTPF = 0f;

static int tempI = 0;



public static void main(String[] args)

{

Main app = new Main();

app.start();



}



@Override

public void simpleInitApp()

{

this.getPhysicsSpace().setGravity(Vector3f.ZERO);

getPhysicsSpace().addCollisionListener(this);

getFlyByCamera().setMoveSpeed(50f);



Vector3f v4F = new Vector3f(1000, 10000, 1000);

PointLight pl = new PointLight();

pl.setColor(new ColorRGBA(.25f,.25f,.25f,1f));

pl.setRadius(1000000f);

pl.setPosition(v4F);



v4F.set(-2000f, -2000f, -2000f);

DirectionalLight dl = new DirectionalLight();

dl.setColor(new ColorRGBA(0f,.25f,.25f,.25f));

dl.setDirection(v4F);



rootNode.addLight(pl);

rootNode.addLight(dl);





Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat.setColor(“m_Color”, ColorRGBA.Blue);



Vector3f v3f = new Vector3f(Vector3f.UNIT_XYZ.mult(.5f));



Box b = new Box(Vector3f.ZERO, v3f);

Geometry geom = new Geometry(“BOX”, b);

geom.updateModelBound();

geom.setMaterial(mat);



Spatial sp = assetManager.loadModel(“Models/Box.j3o”);

Spatial sp1 = assetManager.loadModel(“Models/Box.j3o”);

Spatial sp2 = assetManager.loadModel(“Models/Box.j3o”);



CollisionShape staticCs = CollisionShapeFactory.createMeshShape(sp);

CollisionShape dynamicCs1 = CollisionShapeFactory.createDynamicMeshShape(sp1);

CollisionShape dynamicCs2 = CollisionShapeFactory.createDynamicMeshShape(sp2);





//simple dynamic box

PhysicsNode pN1 = new PhysicsNode(geom, new BoxCollisionShape(v3f), 1f );

//dynamic ghostbox

PhysicsGhostNode pN2 = new PhysicsGhostNode(new BoxCollisionShape(v3f));



pN2.attachDebugShape(assetManager);

pN2.setLocalTranslation(10f, 0f, 0f);

pN1.attachChild(pN2);

pN1.setLocalTranslation(-20f, 0f, 0f);

pN1.updateGeometricState();

rootNode.attachChild(pN1);

getPhysicsSpace().addQueued(pN1);

getPhysicsSpace().addQueued(pN2);





//Factory static ghostnode

PhysicsGhostNode staticGNode = new PhysicsGhostNode(sp, staticCs);

staticGNode.setLocalTranslation(-4f, 0f, 0f);

staticGNode.attachDebugShape(assetManager);

staticGNode.updateGeometricState();

rootNode.attachChild(staticGNode);

getPhysicsSpace().addQueued(staticGNode);



//Factor dynamic ghostnode

PhysicsGhostNode gimpGNode = new PhysicsGhostNode(sp1, dynamicCs1);

gimpGNode.attachDebugShape(assetManager);

gimpGNode.setLocalTranslation(0f, 0f, 0f);

gimpGNode.updateGeometricState();

rootNode.attachChild(gimpGNode);

getPhysicsSpace().addQueued(gimpGNode);





//Factor dynamic node

PhysicsNode gimpDNode = new PhysicsNode(sp2, dynamicCs2);

gimpDNode.setLocalTranslation(4f, 0f, 0f);

gimpDNode.attachDebugShape(assetManager);

gimpDNode.updateGeometricState();

rootNode.attachChild(gimpDNode);

getPhysicsSpace().addQueued(gimpDNode);

pN1.setSleepingThresholds(0f, 0f);

pN1.setLinearVelocity(Vector3f.UNIT_X.mult(1f));

fpsText.setLocalTranslation(Vector3f.UNIT_Y.mult(200.f));

}

public void print_text(String st)

{

fpsText.setText(st);

}

public void collision(PhysicsCollisionEvent event)

{



print_text(event.toString());



}

}

[/java]

Hm, gotta check in the bullet documentation if theres something special about GImpact collisions. Thanks for the info!

Cheers,

Normen

If PhysicsCollisionGroupListener is implement instead of PhysicsCollisionListener the proper calls to

[java]collide()[/java]



are made???

Well, the CollisionGroupListener uses a different method and is for a different purpose really. If this would not work then the collision would not happen at all :slight_smile:

You can get the same effect though, if you make a CollisionGroupListener with the group set to ~0 (or 0xffffffff).

I am currently encountering a similar issue when using a GImpactCollisionShape on a mesh. I am finding that although the dynamic collisions are behaving as I expected in the scene, when I attempt to listen to the event using a standard PhysicsCollisionListener, I am never notified of the collision. Most of my scene is modelled through Blender but for design reasons some objects are created withing the engine directly. Specifically in this case I merge 3 individual geometries that are attached to a node using the GeometryBatchFactory as follows:



[java]



binNode.attachChild(baseGeom);

binNode.attachChild(bodyGeom);

binNode.attachChild(lipGeom);

baseGeom.setLocalTranslation(0, 0, (BIN_HEIGHT / 2) - 0.05f);

bodyGeom.setLocalTranslation(0, 0, 0);

lipGeom.setLocalTranslation(0, 0, (-BIN_HEIGHT / 2) + 0.05f);



Mesh m = new Mesh();



List<Geometry> geomList = new ArrayList<Geometry>();

geomList.add(baseGeom);

geomList.add(bodyGeom);

geomList.add(lipGeom);



GeometryBatchFactory.mergeGeometries(geomList, mesh);

Spatial binSpatial = GeometryBatchFactory.optimize(binNode);

binSpatial.setName("Bin");



GImpactCollisionShape meshCollisionShape = new GImpactCollisionShape(mesh);

binPhysics = new RigidBodyControl(meshCollisionShape);



[/java]

As mentioned, the collisions happen as desired but without event notification in the listener. If I switch the collision shape to just be based on the spatial with the 3 geoms attached as follows:

[java]

binPhysics = new RigidBodyControl(CollisionShapeFactory.createDynamicMeshShape(binSpatial))

[/java]

I am then notified in the collision listener of the collision in this instance, but unforunately the mesh shape created using createDynamicMeshShape(…) is not as required hence the use of GImpactCollisionShape (I need a hollow cylinder which the call to createDynamicMeshShape(…) does not provide).



Can anyone shed any light as to why I am not notified of the collison event using the GImpactCollisionShape directly? One final point to make is that if I use a CollisionGroupListener, I do get notified of the event but only when the impact intersects the bounding volume of the binPhsyics which is not as precise as I desire.