Search in sources :

Example 1 with BroadphaseProxy

use of com.bulletphysics.collision.broadphase.BroadphaseProxy 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)

Example 2 with BroadphaseProxy

use of com.bulletphysics.collision.broadphase.BroadphaseProxy in project bdx by GoranM.

the class CollisionWorld method destroy.

public void destroy() {
    // clean up remaining objects
    for (int i = 0; i < collisionObjects.size(); i++) {
        CollisionObject collisionObject = collisionObjects.getQuick(i);
        BroadphaseProxy bp = collisionObject.getBroadphaseHandle();
        if (bp != null) {
            //
            // only clear the cached algorithms
            //
            getBroadphase().getOverlappingPairCache().cleanProxyFromPairs(bp, dispatcher1);
            getBroadphase().destroyProxy(bp, dispatcher1);
        }
    }
}
Also used : BroadphaseProxy(com.bulletphysics.collision.broadphase.BroadphaseProxy)

Example 3 with BroadphaseProxy

use of com.bulletphysics.collision.broadphase.BroadphaseProxy in project bdx by GoranM.

the class PairCachingGhostObject method removeOverlappingObjectInternal.

@Override
public void removeOverlappingObjectInternal(BroadphaseProxy otherProxy, Dispatcher dispatcher, BroadphaseProxy thisProxy1) {
    CollisionObject otherObject = (CollisionObject) otherProxy.clientObject;
    BroadphaseProxy actualThisProxy = thisProxy1 != null ? thisProxy1 : getBroadphaseHandle();
    assert (actualThisProxy != null);
    assert (otherObject != null);
    int index = overlappingObjects.indexOf(otherObject);
    if (index != -1) {
        overlappingObjects.setQuick(index, overlappingObjects.getQuick(overlappingObjects.size() - 1));
        overlappingObjects.removeQuick(overlappingObjects.size() - 1);
        hashPairCache.removeOverlappingPair(actualThisProxy, otherProxy, dispatcher);
    }
}
Also used : BroadphaseProxy(com.bulletphysics.collision.broadphase.BroadphaseProxy)

Example 4 with BroadphaseProxy

use of com.bulletphysics.collision.broadphase.BroadphaseProxy in project bdx by GoranM.

the class PairCachingGhostObject method addOverlappingObjectInternal.

/**
	 * This method is mainly for expert/internal use only.
	 */
@Override
public void addOverlappingObjectInternal(BroadphaseProxy otherProxy, BroadphaseProxy thisProxy) {
    BroadphaseProxy actualThisProxy = thisProxy != null ? thisProxy : getBroadphaseHandle();
    assert (actualThisProxy != null);
    CollisionObject otherObject = (CollisionObject) otherProxy.clientObject;
    assert (otherObject != null);
    // if this linearSearch becomes too slow (too many overlapping objects) we should add a more appropriate data structure
    int index = overlappingObjects.indexOf(otherObject);
    if (index == -1) {
        overlappingObjects.add(otherObject);
        hashPairCache.addOverlappingPair(actualThisProxy, otherProxy);
    }
}
Also used : BroadphaseProxy(com.bulletphysics.collision.broadphase.BroadphaseProxy)

Aggregations

BroadphaseProxy (com.bulletphysics.collision.broadphase.BroadphaseProxy)4 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