Search in sources :

Example 1 with ContactAddedCallback

use of com.bulletphysics.ContactAddedCallback in project jmonkeyengine by jMonkeyEngine.

the class PhysicsSpace method setContactCallbacks.

private void setContactCallbacks() {
    BulletGlobals.setContactAddedCallback(new ContactAddedCallback() {

        public boolean contactAdded(ManifoldPoint cp, com.bulletphysics.collision.dispatch.CollisionObject colObj0, int partId0, int index0, com.bulletphysics.collision.dispatch.CollisionObject colObj1, int partId1, int index1) {
            System.out.println("contact added");
            return true;
        }
    });
    BulletGlobals.setContactProcessedCallback(new ContactProcessedCallback() {

        public boolean contactProcessed(ManifoldPoint cp, Object body0, Object body1) {
            if (body0 instanceof CollisionObject && body1 instanceof CollisionObject) {
                PhysicsCollisionObject node = null, node1 = null;
                CollisionObject rBody0 = (CollisionObject) body0;
                CollisionObject rBody1 = (CollisionObject) body1;
                node = (PhysicsCollisionObject) rBody0.getUserPointer();
                node1 = (PhysicsCollisionObject) rBody1.getUserPointer();
                collisionEvents.add(eventFactory.getEvent(PhysicsCollisionEvent.TYPE_PROCESSED, node, node1, cp));
            }
            return true;
        }
    });
    BulletGlobals.setContactDestroyedCallback(new ContactDestroyedCallback() {

        public boolean contactDestroyed(Object userPersistentData) {
            System.out.println("contact destroyed");
            return true;
        }
    });
}
Also used : PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) ContactDestroyedCallback(com.bulletphysics.ContactDestroyedCallback) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) ContactAddedCallback(com.bulletphysics.ContactAddedCallback) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) PairCachingGhostObject(com.bulletphysics.collision.dispatch.PairCachingGhostObject) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject) PhysicsGhostObject(com.jme3.bullet.objects.PhysicsGhostObject) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) ContactProcessedCallback(com.bulletphysics.ContactProcessedCallback) TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) PhysicsJoint(com.jme3.bullet.joints.PhysicsJoint) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Aggregations

ContactAddedCallback (com.bulletphysics.ContactAddedCallback)1 ContactDestroyedCallback (com.bulletphysics.ContactDestroyedCallback)1 ContactProcessedCallback (com.bulletphysics.ContactProcessedCallback)1 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)1 PairCachingGhostObject (com.bulletphysics.collision.dispatch.PairCachingGhostObject)1 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)1 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)1 PhysicsCollisionObject (com.jme3.bullet.collision.PhysicsCollisionObject)1 PhysicsJoint (com.jme3.bullet.joints.PhysicsJoint)1 PhysicsGhostObject (com.jme3.bullet.objects.PhysicsGhostObject)1