Search in sources :

Example 21 with Vector2f

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

the class TessellatorHelper method addBlockMesh.

public static void addBlockMesh(Tessellator tessellator, Vector4f color, float size, float light1, float light2, float posX, float posY, float posZ) {
    Vector2f defaultSize = new Vector2f(1.0f, 1.0f);
    Vector2f defaultOffset = new Vector2f(0.0f, 0.0f);
    addBlockMesh(tessellator, color, defaultOffset, defaultSize, size, light1, light2, posX, posY, posZ);
}
Also used : Vector2f(org.terasology.math.geom.Vector2f)

Example 22 with Vector2f

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

the class ZoomableLayout method screenToWorld.

public Vector2f screenToWorld(Vector2i screenPos) {
    Vector2f world = new Vector2f(screenPos.x / pixelSize.x, screenPos.y / pixelSize.y);
    world.add(windowPosition);
    return world;
}
Also used : Vector2f(org.terasology.math.geom.Vector2f)

Example 23 with Vector2f

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

the class ZoomableLayout method zoom.

public void zoom(float zoomX, float zoomY, Vector2i mousePos) {
    Vector2f mouseBefore = screenToWorld(mousePos);
    windowSize.x *= zoomX;
    windowSize.y *= zoomY;
    calculateSizes();
    Vector2f mouseAfter = screenToWorld(mousePos);
    windowPosition.x -= mouseAfter.x - mouseBefore.x;
    windowPosition.y -= mouseAfter.y - mouseBefore.y;
}
Also used : Vector2f(org.terasology.math.geom.Vector2f)

Example 24 with Vector2f

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

the class Voronoi method getClosestPoints.

/**
 * @param at
 * @param numPoints Should be ≤ 5. The number of points to return
 * @return
 */
public VoronoiResult[] getClosestPoints(Vector2f at, int numPoints) {
    VoronoiResult[] results = new VoronoiResult[numPoints];
    for (VoronoiResult result : results) {
        result.distance = Float.MAX_VALUE;
    }
    at.scale(DENSITY_ADJUSTMENT);
    at.add(offset);
    int cellX = TeraMath.floorToInt(at.x);
    int cellY = TeraMath.floorToInt(at.y);
    processCell(cellX, cellY, at, results);
    Vector2f cellPos = new Vector2f(at);
    cellPos.x -= cellX;
    cellPos.y -= cellY;
    Vector2f distMax = new Vector2f(standardDistanceFunction(new Vector2f(1 - cellPos.x, 0)), standardDistanceFunction(new Vector2f(0, 1 - cellPos.y)));
    Vector2f distMin = new Vector2f(standardDistanceFunction(new Vector2f(cellPos.x, 0)), standardDistanceFunction(new Vector2f(0, cellPos.y)));
    // Test near cells
    if (distMin.x < results[results.length - 1].distance) {
        processCell(cellX - 1, cellY, at, results);
    }
    if (distMin.y < results[results.length - 1].distance) {
        processCell(cellX, cellY - 1, at, results);
    }
    if (distMax.x < results[results.length - 1].distance) {
        processCell(cellX + 1, cellY, at, results);
    }
    if (distMax.y < results[results.length - 1].distance) {
        processCell(cellX, cellY + 1, at, results);
    }
    // Test further cells
    if (distMin.x + distMin.y < results[results.length - 1].distance) {
        processCell(cellX - 1, cellY - 1, at, results);
    }
    if (distMax.x + distMax.y < results[results.length - 1].distance) {
        processCell(cellX + 1, cellY + 1, at, results);
    }
    if (distMin.x + distMax.y < results[results.length - 1].distance) {
        processCell(cellX - 1, cellY + 1, at, results);
    }
    if (distMax.x + distMin.y < results[results.length - 1].distance) {
        processCell(cellX + 1, cellY - 1, at, results);
    }
    for (VoronoiResult result : results) {
        result.delta.scale(INVERSE_DENSITY_ADJUSTMENT);
        result.distance *= INVERSE_DENSITY_ADJUSTMENT * INVERSE_DENSITY_ADJUSTMENT;
    }
    return results;
}
Also used : Vector2f(org.terasology.math.geom.Vector2f)

Example 25 with Vector2f

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

the class BlockMeshPart method mapTexCoords.

public BlockMeshPart mapTexCoords(Vector2f offset, float width) {
    float normalisedBorder = BORDER * width;
    Vector2f[] newTexCoords = new Vector2f[texCoords.length];
    for (int i = 0; i < newTexCoords.length; ++i) {
        newTexCoords[i] = new Vector2f(offset.x + normalisedBorder + texCoords[i].x * (width - 2 * normalisedBorder), offset.y + normalisedBorder + texCoords[i].y * (width - 2 * normalisedBorder));
    }
    return new BlockMeshPart(vertices, normals, newTexCoords, indices);
}
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