Search in sources :

Example 16 with Vector2f

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

the class Voronoi method processCell.

private void processCell(int cellX, int cellY, Vector2f at, VoronoiResult[] results) {
    long seed = (702395077 * cellX + 915488749 * cellY);
    // Number of features
    int count = poissonCount[(int) (seed >> 24)];
    seed = incrementSeed(seed);
    for (int point = 0; point < count; point++) {
        long id = seed;
        seed = incrementSeed(seed);
        float x = (seed + 0.5f) / 4294967296.0f;
        seed = incrementSeed(seed);
        float y = (seed + 0.5f) / 4294967296.0f;
        seed = incrementSeed(seed);
        Vector2f innerPos = new Vector2f(x, y);
        Vector2f delta = new Vector2f(cellX + innerPos.x - at.x, cellY + innerPos.y - at.y);
        float dist = standardDistanceFunction(delta);
        if (dist < results[results.length - 1].distance) {
            int index = results.length - 1;
            while (index > 0 && dist < results[index - 1].distance) {
                index--;
            }
            for (int i = results.length - 1; i > index; i--) {
                results[i] = results[i - 1];
            }
            results[index].distance = dist;
            results[index].delta = new Vector2f(delta);
            results[index].id = (int) id;
        }
    }
}
Also used : Vector2f(org.terasology.math.geom.Vector2f)

Example 17 with Vector2f

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

the class BlockBuilder method createAppearance.

private BlockAppearance createAppearance(BlockShape shape, Map<BlockPart, BlockTile> tiles, Rotation rot) {
    Map<BlockPart, BlockMeshPart> meshParts = Maps.newEnumMap(BlockPart.class);
    Map<BlockPart, Vector2f> textureAtlasPositions = Maps.newEnumMap(BlockPart.class);
    for (BlockPart part : BlockPart.values()) {
        // TODO: Need to be more sensible with the texture atlas. Because things like block particles read from a part that may not exist, we're being fairly lenient
        Vector2f atlasPos;
        if (tiles.get(part) == null) {
            atlasPos = new Vector2f();
        } else {
            atlasPos = worldAtlas.getTexCoords(tiles.get(part), shape.getMeshPart(part) != null);
        }
        BlockPart targetPart = part.rotate(rot);
        textureAtlasPositions.put(targetPart, atlasPos);
        if (shape.getMeshPart(part) != null) {
            meshParts.put(targetPart, shape.getMeshPart(part).rotate(rot.getQuat4f()).mapTexCoords(atlasPos, worldAtlas.getRelativeTileSize()));
        }
    }
    return new BlockAppearance(meshParts, textureAtlasPositions);
}
Also used : BlockPart(org.terasology.world.block.BlockPart) BlockAppearance(org.terasology.world.block.BlockAppearance) Vector2f(org.terasology.math.geom.Vector2f) BlockMeshPart(org.terasology.world.block.shapes.BlockMeshPart)

Example 18 with Vector2f

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

the class BlockMeshPart method appendTo.

public void appendTo(ChunkMesh chunk, int offsetX, int offsetY, int offsetZ, Vector4f colorOffset, ChunkMesh.RenderType renderType, ChunkVertexFlag flags) {
    ChunkMesh.VertexElements elements = chunk.getVertexElements(renderType);
    for (Vector2f texCoord : texCoords) {
        elements.tex.add(texCoord.x);
        elements.tex.add(texCoord.y);
    }
    int nextIndex = elements.vertexCount;
    for (int vIdx = 0; vIdx < vertices.length; ++vIdx) {
        elements.color.add(colorOffset.x);
        elements.color.add(colorOffset.y);
        elements.color.add(colorOffset.z);
        elements.color.add(colorOffset.w);
        elements.vertices.add(vertices[vIdx].x + offsetX);
        elements.vertices.add(vertices[vIdx].y + offsetY);
        elements.vertices.add(vertices[vIdx].z + offsetZ);
        elements.normals.add(normals[vIdx].x);
        elements.normals.add(normals[vIdx].y);
        elements.normals.add(normals[vIdx].z);
        elements.flags.add(flags.getValue());
    }
    elements.vertexCount += vertices.length;
    for (int index : indices) {
        elements.indices.add(index + nextIndex);
    }
}
Also used : ChunkMesh(org.terasology.rendering.primitives.ChunkMesh) Vector2f(org.terasology.math.geom.Vector2f)

Example 19 with Vector2f

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

the class BehaviorEditor method drawConnection.

private void drawConnection(Canvas canvas, Port from, Port to, Color color) {
    Vector2f start = new Vector2f(from.node.getPosition());
    start.add(from.mid());
    Vector2f end = new Vector2f(to.node.getPosition());
    end.add(to.mid());
    drawConnection(canvas, start, end, color);
}
Also used : Vector2f(org.terasology.math.geom.Vector2f)

Example 20 with Vector2f

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

the class BehaviorEditor method drawConnection.

private void drawConnection(Canvas canvas, Port from, Vector2f to, Color color) {
    Vector2f start = new Vector2f(from.node.getPosition());
    start.add(from.mid());
    drawConnection(canvas, start, to, color);
}
Also used : Vector2f(org.terasology.math.geom.Vector2f)

Aggregations

Vector2f (org.terasology.math.geom.Vector2f)41 Vector3f (org.terasology.math.geom.Vector3f)8 IOException (java.io.IOException)5 TIntList (gnu.trove.list.TIntList)4 Vector2i (org.terasology.math.geom.Vector2i)4 TFloatList (gnu.trove.list.TFloatList)3 Map (java.util.Map)3 Test (org.junit.Test)3 Name (org.terasology.naming.Name)3 SubtextureData (org.terasology.rendering.assets.texture.subtexture.SubtextureData)3 BrownianNoise (org.terasology.utilities.procedural.BrownianNoise)3 PerlinNoise (org.terasology.utilities.procedural.PerlinNoise)3 SubSampledNoise (org.terasology.utilities.procedural.SubSampledNoise)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 InputStream (java.io.InputStream)2 Vector4f (org.terasology.math.geom.Vector4f)2 Bone (org.terasology.rendering.assets.skeletalmesh.Bone)2 BoneWeight (org.terasology.rendering.assets.skeletalmesh.BoneWeight)2 SkeletalMeshDataBuilder (org.terasology.rendering.assets.skeletalmesh.SkeletalMeshDataBuilder)2 BlockAppearance (org.terasology.world.block.BlockAppearance)2