use of org.terasology.physics.components.TriggerComponent 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 org.terasology.physics.components.TriggerComponent in project Terasology by MovingBlocks.
the class PhysicsSystem method getCollidesWithGroupFlag.
private short getCollidesWithGroupFlag(EntityRef entity) {
List<CollisionGroup> collidesWithGroup = Lists.<CollisionGroup>newArrayList(StandardCollisionGroup.NONE);
if (entity.hasComponent(TriggerComponent.class)) {
TriggerComponent entityTrigger = entity.getComponent(TriggerComponent.class);
collidesWithGroup = entityTrigger.detectGroups;
} else if (entity.hasComponent(RigidBodyComponent.class)) {
RigidBodyComponent entityRigidBody = entity.getComponent(RigidBodyComponent.class);
collidesWithGroup = entityRigidBody.collidesWith;
}
short flag = 0;
Iterator<CollisionGroup> iter = collidesWithGroup.iterator();
while (iter.hasNext()) {
CollisionGroup group = iter.next();
flag |= group.getFlag();
}
return flag;
}
use of org.terasology.physics.components.TriggerComponent in project Terasology by MovingBlocks.
the class PhysicsSystem method getCollisionGroupFlag.
private short getCollisionGroupFlag(EntityRef entity) {
CollisionGroup collisionGroup = StandardCollisionGroup.NONE;
if (entity.hasComponent(TriggerComponent.class)) {
TriggerComponent entityTrigger = entity.getComponent(TriggerComponent.class);
collisionGroup = entityTrigger.collisionGroup;
} else if (entity.hasComponent(RigidBodyComponent.class)) {
RigidBodyComponent entityRigidBody = entity.getComponent(RigidBodyComponent.class);
collisionGroup = entityRigidBody.collisionGroup;
}
return collisionGroup.getFlag();
}
Aggregations