Search in sources :

Example 1 with TriggerComponent

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;
    }
}
Also used : CollisionGroup(org.terasology.physics.CollisionGroup) StandardCollisionGroup(org.terasology.physics.StandardCollisionGroup) Vector3f(javax.vecmath.Vector3f) ConvexShape(com.bulletphysics.collision.shapes.ConvexShape) LocationComponent(org.terasology.logic.location.LocationComponent) PairCachingGhostObject(com.bulletphysics.collision.dispatch.PairCachingGhostObject) TriggerComponent(org.terasology.physics.components.TriggerComponent)

Example 2 with TriggerComponent

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;
}
Also used : RigidBodyComponent(org.terasology.physics.components.RigidBodyComponent) StandardCollisionGroup(org.terasology.physics.StandardCollisionGroup) CollisionGroup(org.terasology.physics.CollisionGroup) TriggerComponent(org.terasology.physics.components.TriggerComponent)

Example 3 with TriggerComponent

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();
}
Also used : RigidBodyComponent(org.terasology.physics.components.RigidBodyComponent) StandardCollisionGroup(org.terasology.physics.StandardCollisionGroup) CollisionGroup(org.terasology.physics.CollisionGroup) TriggerComponent(org.terasology.physics.components.TriggerComponent)

Aggregations

CollisionGroup (org.terasology.physics.CollisionGroup)3 StandardCollisionGroup (org.terasology.physics.StandardCollisionGroup)3 TriggerComponent (org.terasology.physics.components.TriggerComponent)3 RigidBodyComponent (org.terasology.physics.components.RigidBodyComponent)2 PairCachingGhostObject (com.bulletphysics.collision.dispatch.PairCachingGhostObject)1 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)1 Vector3f (javax.vecmath.Vector3f)1 LocationComponent (org.terasology.logic.location.LocationComponent)1