Search in sources :

Example 1 with RagdollCollisionListener

use of com.jme3.bullet.collision.RagdollCollisionListener in project jmonkeyengine by jMonkeyEngine.

the class KinematicRagdollControl method collision.

/**
     * For internal use only callback for collisionevent
     *
     * @param event
     */
public void collision(PhysicsCollisionEvent event) {
    PhysicsCollisionObject objA = event.getObjectA();
    PhysicsCollisionObject objB = event.getObjectB();
    //excluding collisions that involve 2 parts of the ragdoll
    if (event.getNodeA() == null && event.getNodeB() == null) {
        return;
    }
    //discarding low impulse collision
    if (event.getAppliedImpulse() < eventDispatchImpulseThreshold) {
        return;
    }
    boolean hit = false;
    Bone hitBone = null;
    PhysicsCollisionObject hitObject = null;
    //Computing which bone has been hit
    if (objA.getUserObject() instanceof PhysicsBoneLink) {
        PhysicsBoneLink link = (PhysicsBoneLink) objA.getUserObject();
        if (link != null) {
            hit = true;
            hitBone = link.bone;
            hitObject = objB;
        }
    }
    if (objB.getUserObject() instanceof PhysicsBoneLink) {
        PhysicsBoneLink link = (PhysicsBoneLink) objB.getUserObject();
        if (link != null) {
            hit = true;
            hitBone = link.bone;
            hitObject = objA;
        }
    }
    //dispatching the event if the ragdoll has been hit
    if (hit && listeners != null) {
        for (RagdollCollisionListener listener : listeners) {
            listener.collide(hitBone, hitObject, event);
        }
    }
}
Also used : RagdollCollisionListener(com.jme3.bullet.collision.RagdollCollisionListener) Bone(com.jme3.animation.Bone) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Aggregations

Bone (com.jme3.animation.Bone)1 PhysicsCollisionObject (com.jme3.bullet.collision.PhysicsCollisionObject)1 RagdollCollisionListener (com.jme3.bullet.collision.RagdollCollisionListener)1