Search in sources :

Example 46 with LocationComponent

use of org.terasology.logic.location.LocationComponent 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)

Example 47 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class EntityMotionState method setWorldTransform.

@Override
public void setWorldTransform(Transform transform) {
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    if (loc != null) {
        loc.setWorldPosition(VecMath.from(transform.origin));
        loc.setWorldRotation(VecMath.from(transform.getRotation(new javax.vecmath.Quat4f())));
    }
}
Also used : LocationComponent(org.terasology.logic.location.LocationComponent)

Example 48 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method createPlayerStore.

private PlayerStoreBuilder createPlayerStore(Client client, EntityRef character) {
    LocationComponent location = character.getComponent(LocationComponent.class);
    Vector3f relevanceLocation;
    if (location != null) {
        relevanceLocation = location.getWorldPosition();
    } else {
        relevanceLocation = new Vector3f();
    }
    Long characterId;
    if (character.exists()) {
        characterId = character.getId();
    } else {
        characterId = null;
    }
    return new PlayerStoreBuilder(characterId, relevanceLocation);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 49 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class PojoEntityPool method create.

private EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation, boolean sendLifecycleEvents) {
    EntityBuilder builder = newBuilder(prefab);
    builder.setSendLifecycleEvents(sendLifecycleEvents);
    LocationComponent loc = builder.getComponent(LocationComponent.class);
    if (loc == null && (position != null || rotation != null)) {
        loc = new LocationComponent();
        builder.addComponent(loc);
    }
    if (position != null) {
        loc.setWorldPosition(position);
    }
    if (rotation != null) {
        loc.setWorldRotation(rotation);
    }
    return builder.build();
}
Also used : EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 50 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class NetClient method sendNewChunks.

private void sendNewChunks(NetData.NetMessage.Builder message) {
    if (!readyChunks.isEmpty()) {
        chunkSendCounter += chunkSendRate * NET_TICK_RATE * networkSystem.getBandwidthPerClient();
        if (chunkSendCounter > 1.0f) {
            chunkSendCounter -= 1.0f;
            Vector3i center = new Vector3i();
            LocationComponent loc = getEntity().getComponent(ClientComponent.class).character.getComponent(LocationComponent.class);
            if (loc != null) {
                center.set(ChunkMath.calcChunkPos(new Vector3i(loc.getWorldPosition(), RoundingMode.HALF_UP)));
            }
            Vector3i pos = null;
            int distance = Integer.MAX_VALUE;
            for (Vector3i chunkPos : readyChunks.keySet()) {
                int chunkDistance = chunkPos.distanceSquared(center);
                if (pos == null || chunkDistance < distance) {
                    pos = chunkPos;
                    distance = chunkDistance;
                }
            }
            Chunk chunk = readyChunks.remove(pos);
            relevantChunks.add(pos);
            message.addChunkInfo(chunk.encode());
        }
    } else {
        chunkSendCounter = 1.0f;
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) LocationComponent(org.terasology.logic.location.LocationComponent)

Aggregations

LocationComponent (org.terasology.logic.location.LocationComponent)68 EntityRef (org.terasology.entitySystem.entity.EntityRef)40 Vector3f (org.terasology.math.geom.Vector3f)39 ClientComponent (org.terasology.network.ClientComponent)17 Quat4f (org.terasology.math.geom.Quat4f)16 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)11 Command (org.terasology.logic.console.commandSystem.annotations.Command)10 Vector3i (org.terasology.math.geom.Vector3i)10 BlockComponent (org.terasology.world.block.BlockComponent)7 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)6 BaseQuat4f (org.terasology.math.geom.BaseQuat4f)6 Vector3f (javax.vecmath.Vector3f)5 Component (org.terasology.entitySystem.Component)5 BaseVector3f (org.terasology.math.geom.BaseVector3f)5 MeshComponent (org.terasology.rendering.logic.MeshComponent)5 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)4 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)4 Matrix4f (org.terasology.math.geom.Matrix4f)4 BlockFamily (org.terasology.world.block.family.BlockFamily)4 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)3