Search in sources :

Example 6 with IntArrayList

use of spacegraph.space3d.phys.util.IntArrayList in project narchy by automenta.

the class HullLibrary method bringOutYourDead.

// private ConvexH test_cube();
// BringOutYourDead (John Ratcliff): When you create a convex hull you hand it a large input set of vertices forming a 'point cloud'.
// After the hull is generated it give you back a set of polygon faces which index the *original* point cloud.
// The thing is, often times, there are many 'dead vertices' in the point cloud that are on longer referenced by the hull.
// The routine 'BringOutYourDead' find only the referenced vertices, copies them to an new buffer, and re-indexes the hull so that it is a minimal representation.
private void bringOutYourDead(FasterList<v3> verts, int vcount, FasterList<v3> overts, int[] ocount, IntArrayList indices, int indexcount) {
    int vs = vertexIndexMapping.size();
    IntArrayList tmpIndices = new IntArrayList(vs);
    for (int i = 0; i < vs; i++) {
        tmpIndices.add(vs);
    }
    IntArrayList usedIndices = new IntArrayList();
    MiscUtil.resize(usedIndices, vcount, 0);
    /*
		JAVA NOTE: redudant
		for (int i=0; i<vcount; i++) {
		usedIndices.set(i, 0);
		}
		*/
    ocount[0] = 0;
    for (int i = 0; i < indexcount; i++) {
        // original array index
        int v = indices.get(i);
        assert (v >= 0 && v < vcount);
        if (usedIndices.get(v) != 0) {
            // if already remapped
            // index to new array
            indices.set(i, usedIndices.get(v) - 1);
        } else {
            // new index mapping
            indices.set(i, ocount[0]);
            // return array[index];
            // return array[index];
            // copy old vert to new vert array
            overts.get(ocount[0]).set(verts.get(v));
            for (int k = 0; k < vertexIndexMapping.size(); k++) {
                if (tmpIndices.get(k) == v) {
                    vertexIndexMapping.set(k, ocount[0]);
                }
            }
            // increment output vert count
            ocount[0]++;
            assert (ocount[0] >= 0 && ocount[0] <= vcount);
            // assign new index remapping
            usedIndices.set(v, ocount[0]);
        }
    }
}
Also used : IntArrayList(spacegraph.space3d.phys.util.IntArrayList)

Example 7 with IntArrayList

use of spacegraph.space3d.phys.util.IntArrayList in project narchy by automenta.

the class Dbvt method collideOCL.

public static void collideOCL(Node root, v3[] normals, float[] offsets, v3 sortaxis, int count, ICollide policy, boolean fullsort) {
    // DBVT_CHECKTYPE
    if (root != null) {
        int srtsgns = (sortaxis.x >= 0 ? 1 : 0) + (sortaxis.y >= 0 ? 2 : 0) + (sortaxis.z >= 0 ? 4 : 0);
        int inside = (1 << count) - 1;
        OArrayList<sStkNPS> stock = new OArrayList<>();
        IntArrayList ifree = new IntArrayList();
        IntArrayList stack = new IntArrayList();
        int[] signs = new int[/*sizeof(unsigned)*8*/
        4 * 8];
        assert (count < (/*sizeof(signs)*/
        128 / /*sizeof(signs[0])*/
        4));
        for (int i = 0; i < count; i++) {
            signs[i] = ((normals[i].x >= 0) ? 1 : 0) + ((normals[i].y >= 0) ? 2 : 0) + ((normals[i].z >= 0) ? 4 : 0);
        }
        // stock.reserve(SIMPLE_STACKSIZE);
        // stack.reserve(SIMPLE_STACKSIZE);
        // ifree.reserve(SIMPLE_STACKSIZE);
        stack.add(allocate(ifree, stock, new sStkNPS(root, 0, root.volume.ProjectMinimum(sortaxis, srtsgns))));
        do {
            // JAVA NOTE: check
            int id = stack.remove(stack.size() - 1);
            // return array[index];
            sStkNPS se = stock.get(id);
            ifree.add(id);
            if (se.mask != inside) {
                boolean out = false;
                for (int i = 0, j = 1; (!out) && (i < count); ++i, j <<= 1) {
                    if (0 == (se.mask & j)) {
                        int side = se.node.volume.Classify(normals[i], offsets[i], signs[i]);
                        switch(side) {
                            case -1:
                                out = true;
                                break;
                            case +1:
                                se.mask |= j;
                                break;
                        }
                    }
                }
                if (out) {
                    continue;
                }
            }
            if (ICollide.Descent(se.node)) {
                if (se.node.isinternal()) {
                    Node[] pns = { se.node.childs[0], se.node.childs[1] };
                    sStkNPS[] nes = { new sStkNPS(pns[0], se.mask, pns[0].volume.ProjectMinimum(sortaxis, srtsgns)), new sStkNPS(pns[1], se.mask, pns[1].volume.ProjectMinimum(sortaxis, srtsgns)) };
                    int q = nes[0].value < nes[1].value ? 1 : 0;
                    int j = stack.size();
                    if (fullsort && (j > 0)) {
                        /* Insert 0	*/
                        j = nearest(stack, stock, nes[q].value, 0, stack.size());
                        stack.add(0);
                        // #else
                        for (int k = stack.size() - 1; k > j; --k) {
                            stack.set(k, stack.get(k - 1));
                        // #endif
                        }
                        stack.set(j, allocate(ifree, stock, nes[q]));
                        /* Insert 1	*/
                        j = nearest(stack, stock, nes[1 - q].value, j, stack.size());
                        stack.add(0);
                        // #else
                        for (int k = stack.size() - 1; k > j; --k) {
                            stack.set(k, stack.get(k - 1));
                        // #endif
                        }
                        stack.set(j, allocate(ifree, stock, nes[1 - q]));
                    } else {
                        stack.add(allocate(ifree, stock, nes[q]));
                        stack.add(allocate(ifree, stock, nes[1 - q]));
                    }
                } else {
                    policy.process(se.node, se.value);
                }
            }
        } while (stack.size() != 0);
    }
}
Also used : OArrayList(spacegraph.space3d.phys.util.OArrayList) IntArrayList(spacegraph.space3d.phys.util.IntArrayList)

Example 8 with IntArrayList

use of spacegraph.space3d.phys.util.IntArrayList in project narchy by automenta.

the class HashedOverlappingPairCache method findPair.

@Override
public BroadphasePair findPair(Broadphasing proxy0, Broadphasing proxy1) {
    BulletStats.gFindPairs++;
    if (proxy0.uid > proxy1.uid) {
        Broadphasing tmp = proxy0;
        proxy0 = proxy1;
        proxy1 = tmp;
    }
    int proxyId1 = proxy0.uid;
    int proxyId2 = proxy1.uid;
    /*if (proxyId1 > proxyId2)
			btSwap(proxyId1, proxyId2);*/
    int hash = getHash(proxyId1, proxyId2) & (overlappingPairArray.capacity() - 1);
    IntArrayList table = this.hashTable;
    if (hash >= table.size()) {
        return null;
    }
    int index = table.get(hash);
    // return array[index];
    while (index != NULL_PAIR && !equalsPair(overlappingPairArray.get(index), proxyId1, proxyId2)) {
        index = next.get(index);
    }
    if (index == NULL_PAIR) {
        return null;
    }
    assert (index < overlappingPairArray.size());
    return overlappingPairArray.get(index);
// return array[index];
}
Also used : IntArrayList(spacegraph.space3d.phys.util.IntArrayList)

Aggregations

IntArrayList (spacegraph.space3d.phys.util.IntArrayList)8 spacegraph.util.math.v3 (spacegraph.util.math.v3)2 FasterList (jcog.list.FasterList)1 Body3D (spacegraph.space3d.phys.Body3D)1 ManifoldPoint (spacegraph.space3d.phys.collision.narrow.ManifoldPoint)1 ContactConstraint (spacegraph.space3d.phys.constraint.ContactConstraint)1 SolverConstraint (spacegraph.space3d.phys.constraint.SolverConstraint)1 TypedConstraint (spacegraph.space3d.phys.constraint.TypedConstraint)1 Transform (spacegraph.space3d.phys.math.Transform)1 OArrayList (spacegraph.space3d.phys.util.OArrayList)1