Search in sources :

Example 1 with BroadphasePair

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

the class SimulationIslandManager method findUnions.

public void findUnions(Dispatcher dispatcher, CollisionWorld colWorld) {
    ObjectArrayList<BroadphasePair> pairPtr = colWorld.getPairCache().getOverlappingPairArray();
    for (int i = 0; i < pairPtr.size(); i++) {
        BroadphasePair collisionPair = pairPtr.getQuick(i);
        CollisionObject colObj0 = (CollisionObject) collisionPair.pProxy0.clientObject;
        CollisionObject colObj1 = (CollisionObject) collisionPair.pProxy1.clientObject;
        if (((colObj0 != null) && ((colObj0).mergesSimulationIslands())) && ((colObj1 != null) && ((colObj1).mergesSimulationIslands()))) {
            unionFind.unite((colObj0).getIslandTag(), (colObj1).getIslandTag());
        }
    }
}
Also used : BroadphasePair(com.bulletphysics.collision.broadphase.BroadphasePair)

Example 2 with BroadphasePair

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

the class KinematicCharacterController method recoverFromPenetration.

protected boolean recoverFromPenetration(CollisionWorld collisionWorld) {
    boolean penetration = false;
    Stack stack = Stack.enter();
    collisionWorld.getDispatcher().dispatchAllCollisionPairs(ghostObject.getOverlappingPairCache(), collisionWorld.getDispatchInfo(), collisionWorld.getDispatcher());
    currentPosition.set(ghostObject.getWorldTransform(stack.allocTransform()).origin);
    float maxPen = 0.0f;
    for (int i = 0; i < ghostObject.getOverlappingPairCache().getNumOverlappingPairs(); i++) {
        manifoldArray.clear();
        BroadphasePair collisionPair = ghostObject.getOverlappingPairCache().getOverlappingPairArray().getQuick(i);
        if (collisionPair.algorithm != null) {
            collisionPair.algorithm.getAllContactManifolds(manifoldArray);
        }
        for (int j = 0; j < manifoldArray.size(); j++) {
            PersistentManifold manifold = manifoldArray.getQuick(j);
            float directionSign = manifold.getBody0() == ghostObject ? -1.0f : 1.0f;
            for (int p = 0; p < manifold.getNumContacts(); p++) {
                ManifoldPoint pt = manifold.getContactPoint(p);
                float dist = pt.getDistance();
                if (dist < 0.0f) {
                    if (dist < maxPen) {
                        maxPen = dist;
                        //??
                        touchingNormal.set(pt.normalWorldOnB);
                        touchingNormal.scale(directionSign);
                    }
                    currentPosition.scaleAdd(directionSign * dist * 0.2f, pt.normalWorldOnB, currentPosition);
                    penetration = true;
                } else {
                //printf("touching %f\n", dist);
                }
            }
        //manifold->clearManifold();
        }
    }
    Transform newTrans = ghostObject.getWorldTransform(stack.allocTransform());
    newTrans.origin.set(currentPosition);
    ghostObject.setWorldTransform(newTrans);
    //printf("m_touchingNormal = %f,%f,%f\n",m_touchingNormal[0],m_touchingNormal[1],m_touchingNormal[2]);
    //System.out.println("recoverFromPenetration "+penetration+" "+touchingNormal);
    stack.leave();
    return penetration;
}
Also used : ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) PersistentManifold(com.bulletphysics.collision.narrowphase.PersistentManifold) BroadphasePair(com.bulletphysics.collision.broadphase.BroadphasePair) Transform(com.bulletphysics.linearmath.Transform) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Aggregations

BroadphasePair (com.bulletphysics.collision.broadphase.BroadphasePair)2 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)1 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)1 Transform (com.bulletphysics.linearmath.Transform)1 Stack (com.bulletphysics.util.Stack)1