Search in sources :

Example 1 with ArrayListGameObject

use of com.nilunder.bdx.GameObject.ArrayListGameObject in project bdx by GoranM.

the class Scene method detectCollisions.

private void detectCollisions() {
    for (GameObject g : objects) {
        ArrayListGameObject hitLast = g.touchingObjectsLast;
        g.touchingObjectsLast = g.touchingObjects;
        g.touchingObjects = hitLast;
        g.touchingObjects.clear();
        g.contactManifolds.clear();
    }
    int numManifolds = world.getDispatcher().getNumManifolds();
    for (int i = 0; i < numManifolds; ++i) {
        PersistentManifold mani = world.getDispatcher().getManifoldByIndexInternal(i);
        if (mani.getNumContacts() > 0) {
            RigidBody a = (RigidBody) mani.getBody0();
            RigidBody b = (RigidBody) mani.getBody1();
            GameObject A = (GameObject) a.getUserPointer();
            GameObject B = (GameObject) b.getUserPointer();
            A.touchingObjects.add(B);
            B.touchingObjects.add(A);
            A.contactManifolds.add(mani);
            B.contactManifolds.add(mani);
        }
    }
}
Also used : PersistentManifold(com.bulletphysics.collision.narrowphase.PersistentManifold) ArrayListGameObject(com.nilunder.bdx.GameObject.ArrayListGameObject) ArrayListGameObject(com.nilunder.bdx.GameObject.ArrayListGameObject) RigidBody(com.bulletphysics.dynamics.RigidBody)

Aggregations

PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)1 RigidBody (com.bulletphysics.dynamics.RigidBody)1 ArrayListGameObject (com.nilunder.bdx.GameObject.ArrayListGameObject)1