Search in sources :

Example 6 with IntArray

use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.

the class ConvexHull method computeIndices.

/** Computes a hull the same as {@link #computePolygon(float[], int, int, boolean)} but returns indices of the specified points. */
public IntArray computeIndices(float[] points, int offset, int count, boolean sorted, boolean yDown) {
    int end = offset + count;
    if (!sorted) {
        if (sortedPoints == null || sortedPoints.length < count)
            sortedPoints = new float[count];
        System.arraycopy(points, offset, sortedPoints, 0, count);
        points = sortedPoints;
        offset = 0;
        sortWithIndices(points, count, yDown);
    }
    IntArray indices = this.indices;
    indices.clear();
    FloatArray hull = this.hull;
    hull.clear();
    // Lower hull.
    for (int i = offset, index = i / 2; i < end; i += 2, index++) {
        float x = points[i];
        float y = points[i + 1];
        while (hull.size >= 4 && ccw(x, y) <= 0) {
            hull.size -= 2;
            indices.size--;
        }
        hull.add(x);
        hull.add(y);
        indices.add(index);
    }
    // Upper hull.
    for (int i = end - 4, index = i / 2, t = hull.size + 2; i >= offset; i -= 2, index--) {
        float x = points[i];
        float y = points[i + 1];
        while (hull.size >= t && ccw(x, y) <= 0) {
            hull.size -= 2;
            indices.size--;
        }
        hull.add(x);
        hull.add(y);
        indices.add(index);
    }
    // Convert sorted to unsorted indices.
    if (!sorted) {
        short[] originalIndicesArray = originalIndices.items;
        int[] indicesArray = indices.items;
        for (int i = 0, n = indices.size; i < n; i++) indicesArray[i] = originalIndicesArray[indicesArray[i]];
    }
    return indices;
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray) IntArray(com.badlogic.gdx.utils.IntArray)

Example 7 with IntArray

use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.

the class ConvexHull method sortWithIndices.

/** Sorts x,y pairs of values by the x value, then the y value and stores unsorted original indices.
	 * @param count Number of indices, must be even. */
private void sortWithIndices(float[] values, int count, boolean yDown) {
    int pointCount = count / 2;
    originalIndices.clear();
    originalIndices.ensureCapacity(pointCount);
    short[] originalIndicesArray = originalIndices.items;
    for (short i = 0; i < pointCount; i++) originalIndicesArray[i] = i;
    int lower = 0;
    int upper = count - 1;
    IntArray stack = quicksortStack;
    stack.add(lower);
    stack.add(upper - 1);
    while (stack.size > 0) {
        upper = stack.pop();
        lower = stack.pop();
        if (upper <= lower)
            continue;
        int i = quicksortPartitionWithIndices(values, lower, upper, yDown, originalIndicesArray);
        if (i - lower > upper - i) {
            stack.add(lower);
            stack.add(i - 2);
        }
        stack.add(i + 2);
        stack.add(upper);
        if (upper - i >= i - lower) {
            stack.add(lower);
            stack.add(i - 2);
        }
    }
}
Also used : IntArray(com.badlogic.gdx.utils.IntArray)

Example 8 with IntArray

use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.

the class DelaunayTriangulator method sort.

/** Sorts x,y pairs of values by the x value.
	 * @param count Number of indices, must be even. */
private void sort(float[] values, int count) {
    int pointCount = count / 2;
    originalIndices.clear();
    originalIndices.ensureCapacity(pointCount);
    short[] originalIndicesArray = originalIndices.items;
    for (short i = 0; i < pointCount; i++) originalIndicesArray[i] = i;
    int lower = 0;
    int upper = count - 1;
    IntArray stack = quicksortStack;
    stack.add(lower);
    stack.add(upper - 1);
    while (stack.size > 0) {
        upper = stack.pop();
        lower = stack.pop();
        if (upper <= lower)
            continue;
        int i = quicksortPartition(values, lower, upper, originalIndicesArray);
        if (i - lower > upper - i) {
            stack.add(lower);
            stack.add(i - 2);
        }
        stack.add(i + 2);
        stack.add(upper);
        if (upper - i >= i - lower) {
            stack.add(lower);
            stack.add(i - 2);
        }
    }
}
Also used : IntArray(com.badlogic.gdx.utils.IntArray)

Example 9 with IntArray

use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.

the class EarClippingTriangulator method computeTriangles.

/** Triangulates the given (convex or concave) simple polygon to a list of triangle vertices.
	 * @param vertices pairs describing vertices of the polygon, in either clockwise or counterclockwise order.
	 * @return triples of triangle indices in clockwise order. Note the returned array is reused for later calls to the same
	 *         method. */
public ShortArray computeTriangles(float[] vertices, int offset, int count) {
    this.vertices = vertices;
    int vertexCount = this.vertexCount = count / 2;
    int vertexOffset = offset / 2;
    ShortArray indicesArray = this.indicesArray;
    indicesArray.clear();
    indicesArray.ensureCapacity(vertexCount);
    indicesArray.size = vertexCount;
    short[] indices = this.indices = indicesArray.items;
    if (areVerticesClockwise(vertices, offset, count)) {
        for (short i = 0; i < vertexCount; i++) indices[i] = (short) (vertexOffset + i);
    } else {
        for (int i = 0, n = vertexCount - 1; i < vertexCount; i++) // Reversed.
        indices[i] = (short) (vertexOffset + n - i);
    }
    IntArray vertexTypes = this.vertexTypes;
    vertexTypes.clear();
    vertexTypes.ensureCapacity(vertexCount);
    for (int i = 0, n = vertexCount; i < n; ++i) vertexTypes.add(classifyVertex(i));
    // A polygon with n vertices has a triangulation of n-2 triangles.
    ShortArray triangles = this.triangles;
    triangles.clear();
    triangles.ensureCapacity(Math.max(0, vertexCount - 2) * 3);
    triangulate();
    return triangles;
}
Also used : IntArray(com.badlogic.gdx.utils.IntArray) ShortArray(com.badlogic.gdx.utils.ShortArray)

Example 10 with IntArray

use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.

the class ParticleControllerInfluencer method load.

@Override
public void load(AssetManager manager, ResourceData resources) {
    SaveData data = resources.getSaveData();
    Array<IntArray> effectsIndices = data.load("indices");
    AssetDescriptor descriptor;
    Iterator<IntArray> iterator = effectsIndices.iterator();
    while ((descriptor = data.loadAsset()) != null) {
        ParticleEffect effect = (ParticleEffect) manager.get(descriptor);
        if (effect == null)
            throw new RuntimeException("Template is null");
        Array<ParticleController> effectControllers = effect.getControllers();
        IntArray effectIndices = iterator.next();
        for (int i = 0, n = effectIndices.size; i < n; i++) {
            templates.add(effectControllers.get(effectIndices.get(i)));
        }
    }
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g3d.particles.ParticleEffect) IntArray(com.badlogic.gdx.utils.IntArray) ParticleController(com.badlogic.gdx.graphics.g3d.particles.ParticleController) SaveData(com.badlogic.gdx.graphics.g3d.particles.ResourceData.SaveData) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Aggregations

IntArray (com.badlogic.gdx.utils.IntArray)22 IOException (java.io.IOException)4 FileHandle (com.badlogic.gdx.files.FileHandle)3 Array (com.badlogic.gdx.utils.Array)3 ParticleController (com.badlogic.gdx.graphics.g3d.particles.ParticleController)2 ParticleEffect (com.badlogic.gdx.graphics.g3d.particles.ParticleEffect)2 SaveData (com.badlogic.gdx.graphics.g3d.particles.ResourceData.SaveData)2 MapProperties (com.badlogic.gdx.maps.MapProperties)2 TiledMapTileSet (com.badlogic.gdx.maps.tiled.TiledMapTileSet)2 AnimatedTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile)2 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)2 FloatArray (com.badlogic.gdx.utils.FloatArray)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 ShortArray (com.badlogic.gdx.utils.ShortArray)2 Element (com.badlogic.gdx.utils.XmlReader.Element)2 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)1 Texture (com.badlogic.gdx.graphics.Texture)1 Glyph (com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)1 GlyphRun (com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1