use of com.bulletphysics.collision.broadphase.OverlapFilterCallback in project jmonkeyengine by jMonkeyEngine.
the class PhysicsSpace method setOverlapFilterCallback.
private void setOverlapFilterCallback() {
OverlapFilterCallback callback = new OverlapFilterCallback() {
public boolean needBroadphaseCollision(BroadphaseProxy bp, BroadphaseProxy bp1) {
boolean collides = (bp.collisionFilterGroup & bp1.collisionFilterMask) != 0;
if (collides) {
collides = (bp1.collisionFilterGroup & bp.collisionFilterMask) != 0;
}
if (collides) {
assert (bp.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject && bp.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject);
com.bulletphysics.collision.dispatch.CollisionObject colOb = (com.bulletphysics.collision.dispatch.CollisionObject) bp.clientObject;
com.bulletphysics.collision.dispatch.CollisionObject colOb1 = (com.bulletphysics.collision.dispatch.CollisionObject) bp1.clientObject;
assert (colOb.getUserPointer() != null && colOb1.getUserPointer() != null);
PhysicsCollisionObject collisionObject = (PhysicsCollisionObject) colOb.getUserPointer();
PhysicsCollisionObject collisionObject1 = (PhysicsCollisionObject) colOb1.getUserPointer();
if ((collisionObject.getCollideWithGroups() & collisionObject1.getCollisionGroup()) > 0 || (collisionObject1.getCollideWithGroups() & collisionObject.getCollisionGroup()) > 0) {
PhysicsCollisionGroupListener listener = collisionGroupListeners.get(collisionObject.getCollisionGroup());
PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(collisionObject1.getCollisionGroup());
if (listener != null) {
collides = listener.collide(collisionObject, collisionObject1);
}
if (listener1 != null && collisionObject.getCollisionGroup() != collisionObject1.getCollisionGroup()) {
collides = listener1.collide(collisionObject, collisionObject1) && collides;
}
} else {
return false;
}
}
return collides;
}
};
dynamicsWorld.getPairCache().setOverlapFilterCallback(callback);
}
Aggregations