Example usage for com.badlogic.gdx.utils Bits set

List of usage examples for com.badlogic.gdx.utils Bits set

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils Bits set.

Prototype

public void set(int index) 

Source Link

Usage

From source file:com.badlogic.ashley.core.ComponentType.java

License:Apache License

/**
 * @param componentTypes list of {@link Component} classes
 * @return Bits representing the collection of components for quick comparison and matching. See
 *         {@link Family#getFor(Bits, Bits, Bits)}.
 *///from   w  w w  . j  av  a 2  s.  c o  m
public static Bits getBitsFor(Class<? extends Component>... componentTypes) {
    Bits bits = new Bits();

    int typesLength = componentTypes.length;
    for (int i = 0; i < typesLength; i++) {
        bits.set(ComponentType.getIndexFor(componentTypes[i]));
    }

    return bits;
}

From source file:com.mygdx.game.pathfinding.NavMeshGraph.java

License:Apache License

/**
 * Get an array of the vertex indices from the mesh. Any vertices which share the same position will be counted
 * as a single vertex and share the same index. That is, position duplicates will be filtered out.
 *
 * @param mesh//from w  w w. j a  v  a 2s . co m
 * @return
 */
private static short[] getUniquePositionVertexIndices(Mesh mesh) {
    FloatBuffer verticesBuffer = mesh.getVerticesBuffer();
    int positionOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4;
    // Number of array elements which make up a vertex
    int vertexSize = mesh.getVertexSize() / 4;
    // The indices tell us which vertices are part of a triangle.
    short[] indices = new short[mesh.getNumIndices()];
    mesh.getIndices(indices);
    // Marks true if an index has already been compared to avoid unnecessary comparisons
    Bits handledIndices = new Bits(mesh.getNumIndices());

    for (int i = 0; i < indices.length; i++) {
        short indexI = indices[i];
        if (handledIndices.get(indexI)) {
            // Index handled in an earlier iteration
            continue;
        }
        int vBufIndexI = indexI * vertexSize + positionOffset;
        float xi = verticesBuffer.get(vBufIndexI++);
        float yi = verticesBuffer.get(vBufIndexI++);
        float zi = verticesBuffer.get(vBufIndexI++);
        for (int j = i + 1; j < indices.length; j++) {
            short indexJ = indices[j];
            int vBufIndexJ = indexJ * vertexSize + positionOffset;
            float xj = verticesBuffer.get(vBufIndexJ++);
            float yj = verticesBuffer.get(vBufIndexJ++);
            float zj = verticesBuffer.get(vBufIndexJ++);
            if (xi == xj && yi == yj && zi == zj) {
                indices[j] = indexI;
            }
        }
        handledIndices.set(indexI);
    }
    return indices;
}