use of com.bulletphysics.dynamics.DynamicsWorld in project jmonkeyengine by jMonkeyEngine.
the class PhysicsSpace method setTickCallback.
private void setTickCallback() {
final PhysicsSpace space = this;
InternalTickCallback callback2 = new InternalTickCallback() {
@Override
public void internalTick(DynamicsWorld dw, float f) {
//execute task list
AppTask task = pQueue.poll();
task = pQueue.poll();
while (task != null) {
while (task.isCancelled()) {
task = pQueue.poll();
}
try {
task.invoke();
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
}
task = pQueue.poll();
}
for (Iterator<PhysicsTickListener> it = tickListeners.iterator(); it.hasNext(); ) {
PhysicsTickListener physicsTickCallback = it.next();
physicsTickCallback.prePhysicsTick(space, f);
}
}
};
dynamicsWorld.setPreTickCallback(callback2);
InternalTickCallback callback = new InternalTickCallback() {
@Override
public void internalTick(DynamicsWorld dw, float f) {
for (Iterator<PhysicsTickListener> it = tickListeners.iterator(); it.hasNext(); ) {
PhysicsTickListener physicsTickCallback = it.next();
physicsTickCallback.physicsTick(space, f);
}
}
};
dynamicsWorld.setInternalTickCallback(callback, this);
}
use of com.bulletphysics.dynamics.DynamicsWorld in project Terasology by MovingBlocks.
the class BulletPhysics method getNewCollisionPairs.
private Collection<? extends PhysicsSystem.CollisionPair> getNewCollisionPairs() {
List<PhysicsSystem.CollisionPair> collisionPairs = Lists.newArrayList();
DynamicsWorld world = discreteDynamicsWorld;
ObjectArrayList<PersistentManifold> manifolds = new ObjectArrayList<>();
for (PairCachingGhostObject trigger : entityTriggers.values()) {
EntityRef entity = (EntityRef) trigger.getUserPointer();
for (BroadphasePair initialPair : trigger.getOverlappingPairCache().getOverlappingPairArray()) {
EntityRef otherEntity = null;
if (initialPair.pProxy0.clientObject == trigger) {
if (((CollisionObject) initialPair.pProxy1.clientObject).getUserPointer() instanceof EntityRef) {
otherEntity = (EntityRef) ((CollisionObject) initialPair.pProxy1.clientObject).getUserPointer();
}
} else {
if (((CollisionObject) initialPair.pProxy0.clientObject).getUserPointer() instanceof EntityRef) {
otherEntity = (EntityRef) ((CollisionObject) initialPair.pProxy0.clientObject).getUserPointer();
}
}
if (otherEntity == null || otherEntity == EntityRef.NULL) {
continue;
}
BroadphasePair pair = world.getPairCache().findPair(initialPair.pProxy0, initialPair.pProxy1);
if (pair == null) {
continue;
}
manifolds.clear();
if (pair.algorithm != null) {
pair.algorithm.getAllContactManifolds(manifolds);
}
for (PersistentManifold manifold : manifolds) {
for (int point = 0; point < manifold.getNumContacts(); ++point) {
ManifoldPoint manifoldPoint = manifold.getContactPoint(point);
if (manifoldPoint.getDistance() < 0) {
collisionPairs.add(new PhysicsSystem.CollisionPair(entity, otherEntity, VecMath.from(manifoldPoint.positionWorldOnA), VecMath.from(manifoldPoint.positionWorldOnB), manifoldPoint.getDistance(), VecMath.from(manifoldPoint.normalWorldOnB)));
break;
}
}
}
}
}
return collisionPairs;
}
Aggregations