Search in sources :

Example 1 with TriggerComponent

use of org.terasology.engine.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.engine.physics.components.RigidBodyComponent) StandardCollisionGroup(org.terasology.engine.physics.StandardCollisionGroup) CollisionGroup(org.terasology.engine.physics.CollisionGroup) TriggerComponent(org.terasology.engine.physics.components.TriggerComponent)

Example 2 with TriggerComponent

use of org.terasology.engine.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);
    btCollisionShape 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;
        btPairCachingGhostObject triggerObj = createCollider(location.getWorldPosition(new Vector3f()), shape, collisionGroup.getFlag(), combineGroups(detectGroups), btCollisionObject.CollisionFlags.CF_NO_CONTACT_RESPONSE);
        triggerObj.userData = entity;
        btPairCachingGhostObject 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 : StandardCollisionGroup(org.terasology.engine.physics.StandardCollisionGroup) CollisionGroup(org.terasology.engine.physics.CollisionGroup) Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent) com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject(com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject) TriggerComponent(org.terasology.engine.physics.components.TriggerComponent) com.badlogic.gdx.physics.bullet.collision.btCollisionShape(com.badlogic.gdx.physics.bullet.collision.btCollisionShape)

Example 3 with TriggerComponent

use of org.terasology.engine.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.engine.physics.components.RigidBodyComponent) StandardCollisionGroup(org.terasology.engine.physics.StandardCollisionGroup) CollisionGroup(org.terasology.engine.physics.CollisionGroup) TriggerComponent(org.terasology.engine.physics.components.TriggerComponent)

Aggregations

CollisionGroup (org.terasology.engine.physics.CollisionGroup)3 StandardCollisionGroup (org.terasology.engine.physics.StandardCollisionGroup)3 TriggerComponent (org.terasology.engine.physics.components.TriggerComponent)3 RigidBodyComponent (org.terasology.engine.physics.components.RigidBodyComponent)2 com.badlogic.gdx.physics.bullet.collision.btCollisionShape (com.badlogic.gdx.physics.bullet.collision.btCollisionShape)1 com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject (com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject)1 Vector3f (org.joml.Vector3f)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1