use of com.bulletphysics.collision.dispatch.PairCachingGhostObject in project Terasology by MovingBlocks.
the class BulletPhysics method createCollider.
private PairCachingGhostObject createCollider(Vector3f pos, ConvexShape shape, short groups, short filters, int collisionFlags) {
Transform startTransform = new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), pos, 1.0f));
PairCachingGhostObject result = new PairCachingGhostObject();
result.setWorldTransform(startTransform);
result.setCollisionShape(shape);
result.setCollisionFlags(collisionFlags);
discreteDynamicsWorld.addCollisionObject(result, groups, filters);
return result;
}
use of com.bulletphysics.collision.dispatch.PairCachingGhostObject in project Terasology by MovingBlocks.
the class BulletPhysics method newTrigger.
// *******************Private helper methods**************************\\
/**
* Creates a new trigger.
*
* @param entity the entity to create a trigger for.
*/
private boolean newTrigger(EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
TriggerComponent trigger = entity.getComponent(TriggerComponent.class);
ConvexShape shape = getShapeFor(entity);
if (shape != null && location != null && trigger != null) {
float scale = location.getWorldScale();
shape.setLocalScaling(new Vector3f(scale, scale, scale));
List<CollisionGroup> detectGroups = Lists.newArrayList(trigger.detectGroups);
CollisionGroup collisionGroup = trigger.collisionGroup;
PairCachingGhostObject triggerObj = createCollider(VecMath.to(location.getWorldPosition()), shape, collisionGroup.getFlag(), combineGroups(detectGroups), CollisionFlags.NO_CONTACT_RESPONSE);
triggerObj.setUserPointer(entity);
PairCachingGhostObject oldTrigger = entityTriggers.put(entity, triggerObj);
if (oldTrigger != null) {
logger.warn("Creating a trigger for an entity that already has a trigger. " + "Multiple trigger pre entity are not supported. Removing old one. Entity: {}", entity);
removeCollider(oldTrigger);
return false;
} else {
return true;
}
} else {
logger.warn("Trying to create trigger for entity without ShapeComponent or without LocationComponent or without TriggerComponent. Entity: {}", entity);
return false;
}
}
use of com.bulletphysics.collision.dispatch.PairCachingGhostObject in project jmonkeyengine by jMonkeyEngine.
the class PhysicsCharacter method buildObject.
protected void buildObject() {
if (gObject == null) {
gObject = new PairCachingGhostObject();
}
gObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT);
gObject.setCollisionFlags(gObject.getCollisionFlags() & ~CollisionFlags.NO_CONTACT_RESPONSE);
gObject.setCollisionShape(collisionShape.getCShape());
gObject.setUserPointer(this);
character = new KinematicCharacterController(gObject, (ConvexShape) collisionShape.getCShape(), stepHeight);
}
use of com.bulletphysics.collision.dispatch.PairCachingGhostObject in project jmonkeyengine by jMonkeyEngine.
the class PhysicsGhostObject method buildObject.
protected void buildObject() {
if (gObject == null) {
gObject = new PairCachingGhostObject();
gObject.setCollisionFlags(gObject.getCollisionFlags() | CollisionFlags.NO_CONTACT_RESPONSE);
}
gObject.setCollisionShape(collisionShape.getCShape());
gObject.setUserPointer(this);
}
use of com.bulletphysics.collision.dispatch.PairCachingGhostObject 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