Search in sources :

Example 1 with PhysicsCollisionGroupListener

use of com.jme3.bullet.collision.PhysicsCollisionGroupListener 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);
}
Also used : PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) PhysicsCollisionGroupListener(com.jme3.bullet.collision.PhysicsCollisionGroupListener) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) BroadphaseProxy(com.bulletphysics.collision.broadphase.BroadphaseProxy) OverlapFilterCallback(com.bulletphysics.collision.broadphase.OverlapFilterCallback) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Aggregations

BroadphaseProxy (com.bulletphysics.collision.broadphase.BroadphaseProxy)1 OverlapFilterCallback (com.bulletphysics.collision.broadphase.OverlapFilterCallback)1 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)1 PhysicsCollisionGroupListener (com.jme3.bullet.collision.PhysicsCollisionGroupListener)1 PhysicsCollisionObject (com.jme3.bullet.collision.PhysicsCollisionObject)1