Search in sources :

Example 1 with PhysicsCollisionObject

use of com.jme3.bullet.collision.PhysicsCollisionObject 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)

Example 2 with PhysicsCollisionObject

use of com.jme3.bullet.collision.PhysicsCollisionObject 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 3 with PhysicsCollisionObject

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

the class TestPhysicsRayCast method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    List<PhysicsRayTestResult> rayTest = bulletAppState.getPhysicsSpace().rayTest(cam.getLocation(), cam.getLocation().add(cam.getDirection()));
    if (rayTest.size() > 0) {
        PhysicsRayTestResult get = rayTest.get(0);
        PhysicsCollisionObject collisionObject = get.getCollisionObject();
        //do stuff
        fpsText.setText(collisionObject.getUserObject().toString());
    }
}
Also used : PhysicsRayTestResult(com.jme3.bullet.collision.PhysicsRayTestResult) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Example 4 with PhysicsCollisionObject

use of com.jme3.bullet.collision.PhysicsCollisionObject 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)

Example 5 with PhysicsCollisionObject

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

the class TestSweepTest method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    float move = tpf * 1;
    boolean colliding = false;
    List<PhysicsSweepTestResult> sweepTest = bulletAppState.getPhysicsSpace().sweepTest(capsuleCollisionShape, new Transform(capsule.getWorldTranslation()), new Transform(capsule.getWorldTranslation().add(dist, 0, 0)));
    for (PhysicsSweepTestResult result : sweepTest) {
        if (result.getCollisionObject().getCollisionShape() != capsuleCollisionShape) {
            PhysicsCollisionObject collisionObject = result.getCollisionObject();
            fpsText.setText("Almost colliding with " + collisionObject.getUserObject().toString());
            colliding = true;
        }
    }
    if (!colliding) {
        // if the sweep is clear then move the spatial
        capsule.move(move, 0, 0);
    }
}
Also used : Transform(com.jme3.math.Transform) PhysicsSweepTestResult(com.jme3.bullet.collision.PhysicsSweepTestResult) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Aggregations

PhysicsCollisionObject (com.jme3.bullet.collision.PhysicsCollisionObject)6 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)2 ContactAddedCallback (com.bulletphysics.ContactAddedCallback)1 ContactDestroyedCallback (com.bulletphysics.ContactDestroyedCallback)1 ContactProcessedCallback (com.bulletphysics.ContactProcessedCallback)1 BroadphaseProxy (com.bulletphysics.collision.broadphase.BroadphaseProxy)1 OverlapFilterCallback (com.bulletphysics.collision.broadphase.OverlapFilterCallback)1 PairCachingGhostObject (com.bulletphysics.collision.dispatch.PairCachingGhostObject)1 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)1 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)1 Bone (com.jme3.animation.Bone)1 PhysicsCollisionGroupListener (com.jme3.bullet.collision.PhysicsCollisionGroupListener)1 PhysicsRayTestResult (com.jme3.bullet.collision.PhysicsRayTestResult)1 PhysicsSweepTestResult (com.jme3.bullet.collision.PhysicsSweepTestResult)1 RagdollCollisionListener (com.jme3.bullet.collision.RagdollCollisionListener)1 PhysicsJoint (com.jme3.bullet.joints.PhysicsJoint)1 PhysicsGhostObject (com.jme3.bullet.objects.PhysicsGhostObject)1 PhysicsRigidBody (com.jme3.bullet.objects.PhysicsRigidBody)1 Transform (com.jme3.math.Transform)1