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;
}
});
}
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);
}
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());
}
}
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);
}
}
}
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);
}
}
Aggregations