Search in sources :

Example 6 with PairCachingGhostObject

use of com.bulletphysics.collision.dispatch.PairCachingGhostObject in project Terasology by MovingBlocks.

the class BulletPhysics method updateTrigger.

@Override
public // TODO: update if detectGroups changed
boolean updateTrigger(EntityRef entity) {
    LocationComponent location = entity.getComponent(LocationComponent.class);
    PairCachingGhostObject triggerObj = entityTriggers.get(entity);
    if (location == null) {
        logger.warn("Trying to update or create trigger of entity that has no LocationComponent?! Entity: {}", entity);
        return false;
    }
    if (triggerObj != null) {
        float scale = location.getWorldScale();
        if (Math.abs(triggerObj.getCollisionShape().getLocalScaling(new Vector3f()).x - scale) > BulletGlobals.SIMD_EPSILON) {
            discreteDynamicsWorld.removeCollisionObject(triggerObj);
            newTrigger(entity);
        } else {
            Quat4f worldRotation = VecMath.to(location.getWorldRotation());
            Vector3f worldPosition = VecMath.to(location.getWorldPosition());
            triggerObj.setWorldTransform(new Transform(new Matrix4f(worldRotation, worldPosition, 1.0f)));
        }
        return true;
    } else {
        newTrigger(entity);
        return false;
    }
}
Also used : Matrix4f(javax.vecmath.Matrix4f) Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) LocationComponent(org.terasology.logic.location.LocationComponent) PairCachingGhostObject(com.bulletphysics.collision.dispatch.PairCachingGhostObject) Quat4f(javax.vecmath.Quat4f)

Aggregations

PairCachingGhostObject (com.bulletphysics.collision.dispatch.PairCachingGhostObject)6 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)2 Transform (com.bulletphysics.linearmath.Transform)2 Matrix4f (javax.vecmath.Matrix4f)2 Quat4f (javax.vecmath.Quat4f)2 Vector3f (javax.vecmath.Vector3f)2 LocationComponent (org.terasology.logic.location.LocationComponent)2 BroadphasePair (com.bulletphysics.collision.broadphase.BroadphasePair)1 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)1 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)1 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)1 DiscreteDynamicsWorld (com.bulletphysics.dynamics.DiscreteDynamicsWorld)1 DynamicsWorld (com.bulletphysics.dynamics.DynamicsWorld)1 KinematicCharacterController (com.bulletphysics.dynamics.character.KinematicCharacterController)1 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 CollisionGroup (org.terasology.physics.CollisionGroup)1 StandardCollisionGroup (org.terasology.physics.StandardCollisionGroup)1 TriggerComponent (org.terasology.physics.components.TriggerComponent)1 PhysicsSystem (org.terasology.physics.engine.PhysicsSystem)1