Search in sources :

Example 21 with Vector3i

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

the class Region3i method createFromCenterExtents.

/**
 * Create a region with center point and x,y,z coordinate extents size
 * @param center the center point of region
 * @param extents the extents size of each side of region
 * @return a new region base on the center point and extents size
 */
public static Region3i createFromCenterExtents(BaseVector3f center, BaseVector3f extents) {
    Vector3f min = new Vector3f(center.x() - extents.x(), center.y() - extents.y(), center.z() - extents.z());
    Vector3f max = new Vector3f(center.x() + extents.x(), center.y() + extents.y(), center.z() + extents.z());
    max.x = max.x - Math.ulp(max.x);
    max.y = max.y - Math.ulp(max.y);
    max.z = max.z - Math.ulp(max.z);
    return createFromMinMax(new Vector3i(min), new Vector3i(max));
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BaseVector3f(org.terasology.math.geom.BaseVector3f) BaseVector3i(org.terasology.math.geom.BaseVector3i) Vector3i(org.terasology.math.geom.Vector3i)

Example 22 with Vector3i

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

the class Region3i method max.

/**
 * @return The largest vector in the region
 */
public Vector3i max() {
    Vector3i max = new Vector3i(min);
    max.add(size);
    max.sub(1, 1, 1);
    return max;
}
Also used : BaseVector3i(org.terasology.math.geom.BaseVector3i) Vector3i(org.terasology.math.geom.Vector3i)

Example 23 with Vector3i

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

the class ChunkMonitorDisplay method mouseToChunkPos.

private Vector3i mouseToChunkPos(Point p) {
    Preconditions.checkNotNull(p, "The parameter 'p' must not be null");
    int x = (p.x - centerOffsetX - offsetX) / chunkSize;
    int z = (p.y - centerOffsetY - offsetY) / chunkSize;
    return new Vector3i(x - 1, renderY, z);
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Point(java.awt.Point)

Example 24 with Vector3i

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

the class ObjMeshFormat method processData.

private MeshData processData(List<Vector3f> rawVertices, List<Vector3f> rawNormals, List<Vector2f> rawTexCoords, List<Vector3i[]> rawIndices) throws IOException {
    MeshData result = new MeshData();
    TFloatList vertices = result.getVertices();
    TFloatList texCoord0 = result.getTexCoord0();
    TFloatList normals = result.getNormals();
    TIntList indices = result.getIndices();
    int vertCount = 0;
    for (Vector3i[] face : rawIndices) {
        for (Vector3i indexSet : face) {
            if (indexSet.x > rawVertices.size()) {
                throw new IOException("Vertex index out of range: " + indexSet.x);
            }
            Vector3f vertex = rawVertices.get(indexSet.x - 1);
            vertices.add(vertex.x);
            vertices.add(vertex.y);
            vertices.add(vertex.z);
            if (indexSet.y != -1) {
                if (indexSet.y > rawTexCoords.size()) {
                    throw new IOException("TexCoord index out of range: " + indexSet.y);
                }
                Vector2f texCoord = rawTexCoords.get(indexSet.y - 1);
                texCoord0.add(texCoord.x);
                texCoord0.add(1 - texCoord.y);
            }
            if (indexSet.z != -1) {
                if (indexSet.z > rawNormals.size()) {
                    throw new IOException("Normal index out of range: " + indexSet.z);
                }
                Vector3f normal = rawNormals.get(indexSet.z - 1);
                normals.add(normal.x);
                normals.add(normal.y);
                normals.add(normal.z);
            }
        }
        for (int i = 0; i < face.length - 2; ++i) {
            indices.add(vertCount);
            indices.add(vertCount + i + 1);
            indices.add(vertCount + i + 2);
        }
        vertCount += face.length;
    }
    return result;
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector3f(org.terasology.math.geom.Vector3f) TFloatList(gnu.trove.list.TFloatList) Vector3i(org.terasology.math.geom.Vector3i) IOException(java.io.IOException) TIntList(gnu.trove.list.TIntList)

Example 25 with Vector3i

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

the class CharacterSoundSystem method onFootstep.

@ReceiveEvent
public void onFootstep(FootstepEvent event, EntityRef entity, LocationComponent locationComponent, CharacterSoundComponent characterSounds) {
    List<StaticSound> footstepSounds = characterSounds.footstepSounds;
    // Check if the block the character is standing on has footstep sounds
    Vector3i blockPos = new Vector3i(locationComponent.getLocalPosition());
    // The block *below* the character's feet is interesting to us
    blockPos.y--;
    Block block = worldProvider.getBlock(blockPos);
    if (block != null) {
        if (block.getSounds() == null) {
            logger.error("Block '{}' has no sounds", block.getURI());
        } else if (!block.getSounds().getStepSounds().isEmpty()) {
            footstepSounds = block.getSounds().getStepSounds();
        }
    }
    if (footstepSounds.size() > 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = random.nextItem(footstepSounds);
        entity.send(new PlaySoundEvent(entity, sound, characterSounds.footstepVolume));
        characterSounds.lastSoundTime = time.getGameTimeInMs();
        entity.saveComponent(characterSounds);
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)249 Test (org.junit.Test)94 EntityRef (org.terasology.entitySystem.entity.EntityRef)34 Block (org.terasology.world.block.Block)32 Chunk (org.terasology.world.chunks.Chunk)30 Vector3f (org.terasology.math.geom.Vector3f)21 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)17 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)17 Region3i (org.terasology.math.Region3i)15 BaseVector3i (org.terasology.math.geom.BaseVector3i)15 LocationComponent (org.terasology.logic.location.LocationComponent)14 BlockComponent (org.terasology.world.block.BlockComponent)10 Side (org.terasology.math.Side)9 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Before (org.junit.Before)7 Biome (org.terasology.world.biomes.Biome)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CoreChunk (org.terasology.world.chunks.CoreChunk)6 RenderableChunk (org.terasology.world.chunks.RenderableChunk)6