Search in sources :

Example 86 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class AudioSystem method playTestSound.

/**
 * Plays a test dig sound at an offset from the player in the x and z axis.
 *
 * @param sender The entity sending the sound request
 * @param xOffset The x axis offset from the player to play the sound at.
 * @param zOffset The z axis offset from the player to play the sound at.
 */
@Command(shortDescription = "Plays a test sound")
public void playTestSound(@Sender EntityRef sender, @CommandParam("xOffset") float xOffset, @CommandParam("zOffset") float zOffset) {
    Vector3f position = localPlayer.getPosition();
    position.x += xOffset;
    position.z += zOffset;
    audioManager.playSound(Assets.getSound("engine:dig").get(), position);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 87 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class CameraTargetSystem method updateFocalDistance.

private void updateFocalDistance(HitResult hitInfo, float delta) {
    // how fast the focus distance is updated
    float focusRate = 4.0f;
    // if the hit result from a trace has a recorded a hit
    if (hitInfo.isHit()) {
        Vector3f playerToTargetRay = new Vector3f();
        // calculate the distance from the player to the hit point
        playerToTargetRay.sub(hitInfo.getHitPoint(), localPlayer.getViewPosition());
        // gradually adjust focalDistance from it's current value to the hit point distance
        focalDistance = TeraMath.lerp(focalDistance, playerToTargetRay.length(), delta * focusRate);
    // if nothing was hit, gradually adjust the focusDistance to the maximum length of the update function trace
    } else {
        focalDistance = TeraMath.lerp(focalDistance, targetDistance, delta * focusRate);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Example 88 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class SimpleAISystem method update.

@Override
public void update(float delta) {
    for (EntityRef entity : entityManager.getEntitiesWith(SimpleAIComponent.class, CharacterMovementComponent.class, LocationComponent.class)) {
        LocationComponent location = entity.getComponent(LocationComponent.class);
        Vector3f worldPos = location.getWorldPosition();
        // Skip this AI if not in a loaded chunk
        if (!worldProvider.isBlockRelevant(worldPos)) {
            continue;
        }
        SimpleAIComponent ai = entity.getComponent(SimpleAIComponent.class);
        Vector3f drive = new Vector3f();
        // TODO: shouldn't use local player, need some way to find nearest player
        if (localPlayer != null) {
            Vector3f dist = new Vector3f(worldPos);
            dist.sub(localPlayer.getPosition());
            double distanceToPlayer = dist.lengthSquared();
            if (distanceToPlayer > 6 && distanceToPlayer < 16) {
                // Head to player
                ai.movementTarget.set(localPlayer.getPosition());
                ai.followingPlayer = true;
                entity.saveComponent(ai);
            } else {
                // Random walk
                if (time.getGameTimeInMs() - ai.lastChangeOfDirectionAt > 12000 || ai.followingPlayer) {
                    ai.movementTarget.set(worldPos.x + random.nextFloat(-500.0f, 500.0f), worldPos.y, worldPos.z + random.nextFloat(-500.0f, 500.0f));
                    ai.lastChangeOfDirectionAt = time.getGameTimeInMs();
                    ai.followingPlayer = false;
                    entity.saveComponent(ai);
                }
            }
            Vector3f targetDirection = new Vector3f();
            targetDirection.sub(ai.movementTarget, worldPos);
            targetDirection.normalize();
            drive.set(targetDirection);
            float yaw = (float) Math.atan2(targetDirection.x, targetDirection.z);
            location.getLocalRotation().set(new Vector3f(0, 1, 0), yaw);
            entity.saveComponent(location);
        }
        entity.send(new CharacterMoveInputEvent(0, 0, 0, drive, false, false, time.getGameDeltaInMs()));
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) CharacterMoveInputEvent(org.terasology.logic.characters.CharacterMoveInputEvent) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 89 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class Vector3iTest method testOffsetConstructorWithNegatives.

@Test
public void testOffsetConstructorWithNegatives() {
    Vector3f vOrig = new Vector3f(-0.1f, -0.6f, -1.4f);
    Vector3i v = new Vector3i(vOrig, 0.5f);
    assertEquals(new Vector3i(0, -1, -1), v);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Test(org.junit.Test)

Example 90 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class StorageManagerTest method testEntitySurvivesStorageInChunkStore.

@Test
public void testEntitySurvivesStorageInChunkStore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, biomeManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    EntityRef entity = entityManager.create();
    long id = entity.getId();
    LocationComponent locationComponent = new LocationComponent();
    Vector3f positionInChunk = new Vector3f(chunk.getAABB().getMin());
    positionInChunk.x += 1;
    positionInChunk.y += 1;
    positionInChunk.z += 1;
    locationComponent.setWorldPosition(positionInChunk);
    entity.addComponent(locationComponent);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, false);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    restored.restoreEntities();
    EntityRef ref = newEntityManager.getEntity(id);
    assertTrue(ref.exists());
    assertTrue(ref.isActive());
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3f(org.terasology.math.geom.Vector3f) StorageManager(org.terasology.persistence.StorageManager) Chunk(org.terasology.world.chunks.Chunk) ChunkProvider(org.terasology.world.chunks.ChunkProvider) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Aggregations

Vector3f (org.terasology.math.geom.Vector3f)194 LocationComponent (org.terasology.logic.location.LocationComponent)45 EntityRef (org.terasology.entitySystem.entity.EntityRef)44 Quat4f (org.terasology.math.geom.Quat4f)33 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)26 Vector3i (org.terasology.math.geom.Vector3i)21 Test (org.junit.Test)20 ClientComponent (org.terasology.network.ClientComponent)15 Command (org.terasology.logic.console.commandSystem.annotations.Command)14 Matrix4f (org.terasology.math.geom.Matrix4f)13 BaseVector3f (org.terasology.math.geom.BaseVector3f)9 Block (org.terasology.world.block.Block)9 Vector2f (org.terasology.math.geom.Vector2f)8 HitResult (org.terasology.physics.HitResult)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 IOException (java.io.IOException)6 FloatBuffer (java.nio.FloatBuffer)6 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 AABB (org.terasology.math.AABB)5 ChunkMesh (org.terasology.rendering.primitives.ChunkMesh)5