Search in sources :

Example 1 with IntArrayList

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

the class GImpactCollisionAlgorithm method gimpact_vs_shape.

public void gimpact_vs_shape(Collidable body0, Collidable body1, GImpactShape shape0, CollisionShape shape1, boolean swapped) {
    ShapeType s = shape0.getGImpactShapeType();
    if (s == ShapeType.TRIMESH_SHAPE) {
        GImpactMeshShape meshshape0 = (GImpactMeshShape) shape0;
        int part0 = meshshape0.getMeshPartCount();
        while ((part0--) != 0) {
            gimpact_vs_shape(body0, body1, meshshape0.getMeshPart(part0), shape1, swapped);
        }
        this.part0 = part0;
        return;
    }
    // #ifdef GIMPACT_VS_PLANE_COLLISION
    if (s == ShapeType.TRIMESH_SHAPE_PART && shape1.getShapeType() == BroadphaseNativeType.STATIC_PLANE_PROXYTYPE) {
        GImpactMeshShape.GImpactMeshShapePart shapepart = (GImpactMeshShape.GImpactMeshShapePart) shape0;
        StaticPlaneShape planeshape = (StaticPlaneShape) shape1;
        gimpacttrimeshpart_vs_plane_collision(body0, body1, shapepart, planeshape, swapped);
        return;
    }
    if (shape1.isCompound()) {
        CompoundShape compoundshape = (CompoundShape) shape1;
        gimpact_vs_compoundshape(body0, body1, shape0, compoundshape, swapped);
        return;
    } else if (shape1.isConcave()) {
        ConcaveShape concaveshape = (ConcaveShape) shape1;
        gimpact_vs_concave(body0, body1, shape0, concaveshape, swapped);
        return;
    }
    Transform orgtrans0 = body0.getWorldTransform(new Transform());
    Transform orgtrans1 = body1.getWorldTransform(new Transform());
    IntArrayList collided_results = new IntArrayList();
    gimpact_vs_shape_find_pairs(orgtrans0, orgtrans1, shape0, shape1, collided_results);
    int cr = collided_results.size();
    if (cr == 0) {
        return;
    }
    shape0.lockChildShapes();
    GIM_ShapeRetriever retriever0 = new GIM_ShapeRetriever(shape0);
    boolean child_has_transform0 = shape0.childrenHasTransform();
    Transform tmpTrans = new Transform();
    int i = cr;
    while ((i--) != 0) {
        int child_index = collided_results.get(i);
        if (swapped) {
            triface1 = child_index;
        } else {
            triface0 = child_index;
        }
        CollisionShape colshape0 = retriever0.getChildShape(child_index);
        if (child_has_transform0) {
            tmpTrans.mul(orgtrans0, shape0.getChildTransform(child_index));
            body0.transform(tmpTrans);
        }
        // collide two shapes
        if (swapped) {
            shape_vs_shape_collision(body1, body0, shape1, colshape0);
        } else {
            shape_vs_shape_collision(body0, body1, colshape0, shape1);
        }
        // restore transforms
        if (child_has_transform0) {
            body0.transform(orgtrans0);
        }
    }
    shape0.unlockChildShapes();
}
Also used : Transform(spacegraph.space3d.phys.math.Transform) IntArrayList(spacegraph.space3d.phys.util.IntArrayList)

Example 2 with IntArrayList

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

the class SequentialImpulseConstrainer method solveGroupCacheFriendlyIterations.

float solveGroupCacheFriendlyIterations(Collection<Collidable> bodies, int numBodies, Collection<PersistentManifold> manifoldPtr, int manifold_offset, int numManifolds, FasterList<TypedConstraint> constraints, int constraints_offset, int numConstraints, ContactSolverInfo infoGlobal) /*,btStackAlloc* stackAlloc*/
{
    int numConstraintPool = tmpSolverConstraintPool.size();
    int numFrictionPool = tmpSolverFrictionConstraintPool.size();
    // should traverse the contacts random order...
    int iteration;
    IntArrayList constraintPool = this.orderTmpConstraintPool;
    IntArrayList frictionPool = this.orderFrictionConstraintPool;
    for (iteration = 0; iteration < infoGlobal.numIterations; iteration++) {
        if ((infoGlobal.solverMode & SolverMode.SOLVER_RANDMIZE_ORDER) != 0) {
            if ((iteration & 7) == 0) {
                for (int j = 0; j < numConstraintPool; ++j) {
                    orderPool(j, constraintPool);
                }
                for (int j = 0; j < numFrictionPool; ++j) {
                    orderPool(j, frictionPool);
                }
            }
        }
        for (int j = 0; j < numConstraints; j++) {
            // return array[index];
            final TypedConstraint constraint = constraints.get(constraints_offset + j);
            // todo: use solver bodies, so we don't need to copy from/to btRigidBody
            final Body3D ca = constraint.getRigidBodyA();
            final int cai = ca.getCompanionId();
            if ((ca.tag() >= 0) && (cai >= 0)) {
                // return array[index];
                tmpSolverBodyPool.get(cai).writebackVelocity();
            }
            Body3D cb = constraint.getRigidBodyB();
            int cbi = cb.getCompanionId();
            if ((cb.tag() >= 0) && (cbi >= 0)) {
                // return array[index];
                tmpSolverBodyPool.get(cbi).writebackVelocity();
            }
            constraint.solveConstraint(infoGlobal.timeStep);
            if ((ca.tag() >= 0) && (cai >= 0)) {
                // return array[index];
                tmpSolverBodyPool.get(cai).readVelocity();
            }
            if ((cb.tag() >= 0) && (cbi >= 0)) {
                // return array[index];
                tmpSolverBodyPool.get(cbi).readVelocity();
            }
        }
        int numPoolConstraints = tmpSolverConstraintPool.size();
        for (int j = 0; j < numPoolConstraints; j++) {
            // return array[index];
            SolverConstraint solveManifold = tmpSolverConstraintPool.get(constraintPool.get(j));
            // return array[index];
            // return array[index];
            resolveSingleCollisionCombinedCacheFriendly(tmpSolverBodyPool.get(solveManifold.solverBodyIdA), tmpSolverBodyPool.get(solveManifold.solverBodyIdB), solveManifold, infoGlobal);
        }
        int numFrictionPoolConstraints = tmpSolverFrictionConstraintPool.size();
        for (int j = 0; j < numFrictionPoolConstraints; j++) {
            // return array[index];
            SolverConstraint solveManifold = tmpSolverFrictionConstraintPool.get(frictionPool.get(j));
            // return array[index];
            // return array[index];
            float totalImpulse = tmpSolverConstraintPool.get(solveManifold.frictionIndex).appliedImpulse + tmpSolverConstraintPool.get(solveManifold.frictionIndex).appliedPushImpulse;
            // return array[index];
            // return array[index];
            resolveSingleFrictionCacheFriendly(tmpSolverBodyPool.get(solveManifold.solverBodyIdA), tmpSolverBodyPool.get(solveManifold.solverBodyIdB), solveManifold, infoGlobal, totalImpulse);
        }
    }
    if (infoGlobal.splitImpulse) {
        for (iteration = 0; iteration < infoGlobal.numIterations; iteration++) {
            int numPoolConstraints = tmpSolverConstraintPool.size();
            for (int j = 0; j < numPoolConstraints; j++) {
                // return array[index];
                SolverConstraint solveManifold = tmpSolverConstraintPool.get(constraintPool.get(j));
                // return array[index];
                // return array[index];
                resolveSplitPenetrationImpulseCacheFriendly(tmpSolverBodyPool.get(solveManifold.solverBodyIdA), tmpSolverBodyPool.get(solveManifold.solverBodyIdB), solveManifold, infoGlobal);
            }
        }
    }
    return 0f;
}
Also used : Body3D(spacegraph.space3d.phys.Body3D) SolverConstraint(spacegraph.space3d.phys.constraint.SolverConstraint) IntArrayList(spacegraph.space3d.phys.util.IntArrayList) TypedConstraint(spacegraph.space3d.phys.constraint.TypedConstraint) TypedConstraint(spacegraph.space3d.phys.constraint.TypedConstraint) ContactConstraint(spacegraph.space3d.phys.constraint.ContactConstraint) ManifoldPoint(spacegraph.space3d.phys.collision.narrow.ManifoldPoint) SolverConstraint(spacegraph.space3d.phys.constraint.SolverConstraint)

Example 3 with IntArrayList

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

the class HullLibrary method calchullgen.

private int calchullgen(FasterList<v3> verts, int verts_count, int vlimit) {
    if (verts_count < 4)
        return 0;
    v3 tmp = new v3();
    v3 tmp1 = new v3();
    v3 tmp2 = new v3();
    if (vlimit == 0) {
        vlimit = 1000000000;
    }
    // int j;
    // return array[index];
    v3 bmin = new v3(verts.get(0));
    // return array[index];
    v3 bmax = new v3(verts.get(0));
    IntArrayList isextreme = new IntArrayList();
    // isextreme.reserve(verts_count);
    IntArrayList allow = new IntArrayList();
    for (int j = 0; j < verts_count; j++) {
        allow.add(1);
        isextreme.add(0);
        // return array[index];
        VectorUtil.setMin(bmin, verts.get(j));
        // return array[index];
        VectorUtil.setMax(bmax, verts.get(j));
    }
    tmp.sub(bmax, bmin);
    float epsilon = tmp.length() * 0.001f;
    assert (epsilon != 0f);
    Int4 p = findSimplex(verts, verts_count, allow, new Int4());
    if (p.x == -1) {
        // simplex failed
        return 0;
    // a valid interior point
    }
    v3 center = new v3();
    // return array[index];
    // return array[index];
    // return array[index];
    // return array[index];
    VectorUtil.add(center, verts.get(p.getCoord(0)), verts.get(p.getCoord(1)), verts.get(p.getCoord(2)), verts.get(p.getCoord(3)));
    center.scale(1f / 4f);
    Tri t0 = allocateTriangle(p.getCoord(2), p.getCoord(3), p.getCoord(1));
    t0.n.set(2, 3, 1);
    Tri t1 = allocateTriangle(p.getCoord(3), p.getCoord(2), p.getCoord(0));
    t1.n.set(3, 2, 0);
    Tri t2 = allocateTriangle(p.getCoord(0), p.getCoord(1), p.getCoord(3));
    t2.n.set(0, 1, 3);
    Tri t3 = allocateTriangle(p.getCoord(1), p.getCoord(0), p.getCoord(2));
    t3.n.set(1, 0, 2);
    isextreme.set(p.getCoord(0), 1);
    isextreme.set(p.getCoord(1), 1);
    isextreme.set(p.getCoord(2), 1);
    isextreme.set(p.getCoord(3), 1);
    checkit(t0);
    checkit(t1);
    checkit(t2);
    checkit(t3);
    v3 n = new v3();
    for (int j = 0; j < tris.size(); j++) {
        // return array[index];
        Tri t = tris.get(j);
        assert (t != null);
        assert (t.vmax < 0);
        // return array[index];
        // return array[index];
        // return array[index];
        triNormal(verts.get(t.getCoord(0)), verts.get(t.getCoord(1)), verts.get(t.getCoord(2)), n);
        t.vmax = maxdirsterid(verts, verts_count, n, allow);
        // return array[index];
        // return array[index];
        tmp.sub(verts.get(t.vmax), verts.get(t.getCoord(0)));
        t.rise = n.dot(tmp);
    }
    Tri te;
    vlimit -= 4;
    while (vlimit > 0 && ((te = extrudable(epsilon)) != null)) {
        Int3 ti = te;
        int v = te.vmax;
        assert (v != -1);
        // wtf we've already done this vertex
        assert (isextreme.get(v) == 0);
        isextreme.set(v, 1);
        // if(v==p0 || v==p1 || v==p2 || v==p3) continue; // done these already
        int j = tris.size();
        while ((j--) != 0) {
            // return array[index];
            if (tris.get(j) == null) {
                continue;
            }
            // return array[index];
            Int3 t = tris.get(j);
            // return array[index];
            if (above(verts, t, verts.get(v), 0.01f * epsilon)) {
                // return array[index];
                extrude(tris.get(j), v);
            }
        }
        // now check for those degenerate cases where we have a flipped triangle or a really skinny triangle
        j = tris.size();
        while ((j--) != 0) {
            // return array[index];
            if (tris.get(j) == null) {
                continue;
            }
            // return array[index];
            if (!hasvert(tris.get(j), v)) {
                break;
            }
            // return array[index];
            Int3 nt = tris.get(j);
            // return array[index];
            // return array[index];
            tmp1.sub(verts.get(nt.getCoord(1)), verts.get(nt.getCoord(0)));
            // return array[index];
            // return array[index];
            tmp2.sub(verts.get(nt.getCoord(2)), verts.get(nt.getCoord(1)));
            tmp.cross(tmp1, tmp2);
            if (above(verts, nt, center, 0.01f * epsilon) || tmp.length() < epsilon * epsilon * 0.1f) {
                // return array[index];
                // return array[index];
                Tri nb = tris.get(tris.get(j).n.getCoord(0));
                assert (nb != null);
                assert (!hasvert(nb, v));
                assert (nb.id < j);
                extrude(nb, v);
                j = tris.size();
            }
        }
        j = tris.size();
        while ((j--) != 0) {
            // return array[index];
            Tri t = tris.get(j);
            if (t == null) {
                continue;
            }
            if (t.vmax >= 0) {
                break;
            }
            // return array[index];
            // return array[index];
            // return array[index];
            triNormal(verts.get(t.getCoord(0)), verts.get(t.getCoord(1)), verts.get(t.getCoord(2)), n);
            t.vmax = maxdirsterid(verts, verts_count, n, allow);
            if (isextreme.get(t.vmax) != 0) {
                // already done that vertex - algorithm needs to be able to terminate.
                t.vmax = -1;
            } else {
                // return array[index];
                // return array[index];
                tmp.sub(verts.get(t.vmax), verts.get(t.getCoord(0)));
                t.rise = n.dot(tmp);
            }
        }
        vlimit--;
    }
    return 1;
}
Also used : IntArrayList(spacegraph.space3d.phys.util.IntArrayList) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 4 with IntArrayList

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

the class HullLibrary method createConvexHull.

/**
 * Converts point cloud to polygonal representation.
 *
 * @param desc   describes the input request
 * @param result contains the result
 * @return whether conversion was successful
 */
public boolean createConvexHull(HullDesc desc, HullResult result) {
    boolean ret = false;
    PHullResult hr = new PHullResult();
    int vcount = desc.vcount;
    if (vcount < 8)
        vcount = 8;
    FasterList<v3> vertexSource = new FasterList<>();
    MiscUtil.resize(vertexSource, vcount, v3.class);
    v3 scale = new v3();
    int[] ovcount = new int[1];
    // normalize point cloud, remove duplicates!
    boolean ok = cleanupVertices(desc.vcount, desc.vertices, desc.vertexStride, ovcount, vertexSource, desc.normalEpsilon, scale);
    if (ok) {
        // if ( 1 ) // scale vertices back to their original size.
        for (int i = 0; i < ovcount[0]; i++) {
            // return array[index];
            v3 v = vertexSource.get(i);
            VectorUtil.mul(v, v, scale);
        }
        ok = computeHull(ovcount[0], vertexSource, hr, desc.maxVertices);
        if (ok) {
            // re-index triangle mesh so it refers to only used vertices, rebuild a new vertex table.
            FasterList<v3> vertexScratch = new FasterList<>();
            MiscUtil.resize(vertexScratch, hr.vcount, v3.class);
            bringOutYourDead(hr.vertices, hr.vcount, vertexScratch, ovcount, hr.indices, hr.indexCount);
            ret = true;
            if (desc.hasHullFlag(HullFlags.TRIANGLES)) {
                // if he wants the results as triangle!
                result.polygons = false;
                result.numOutputVertices = ovcount[0];
                MiscUtil.resize(result.outputVertices, ovcount[0], v3.class);
                result.numFaces = hr.faceCount;
                result.numIndices = hr.indexCount;
                MiscUtil.resize(result.indices, hr.indexCount, 0);
                for (int i = 0; i < ovcount[0]; i++) {
                    // return array[index];
                    // return array[index];
                    result.outputVertices.get(i).set(vertexScratch.get(i));
                }
                if (desc.hasHullFlag(HullFlags.REVERSE_ORDER)) {
                    IntArrayList source_ptr = hr.indices;
                    int source_idx = 0;
                    IntArrayList dest_ptr = result.indices;
                    int dest_idx = 0;
                    for (int i = 0; i < hr.faceCount; i++) {
                        dest_ptr.set(dest_idx + 0, source_ptr.get(source_idx + 2));
                        dest_ptr.set(dest_idx + 1, source_ptr.get(source_idx + 1));
                        dest_ptr.set(dest_idx + 2, source_ptr.get(source_idx + 0));
                        dest_idx += 3;
                        source_idx += 3;
                    }
                } else {
                    for (int i = 0; i < hr.indexCount; i++) {
                        result.indices.set(i, hr.indices.get(i));
                    }
                }
            } else {
                result.polygons = true;
                result.numOutputVertices = ovcount[0];
                MiscUtil.resize(result.outputVertices, ovcount[0], v3.class);
                result.numFaces = hr.faceCount;
                result.numIndices = hr.indexCount + hr.faceCount;
                MiscUtil.resize(result.indices, result.numIndices, 0);
                for (int i = 0; i < ovcount[0]; i++) {
                    // return array[index];
                    // return array[index];
                    result.outputVertices.get(i).set(vertexScratch.get(i));
                }
                // if ( 1 )
                IntArrayList source_ptr = hr.indices;
                int source_idx = 0;
                IntArrayList dest_ptr = result.indices;
                int dest_idx = 0;
                for (int i = 0; i < hr.faceCount; i++) {
                    dest_ptr.set(dest_idx + 0, 3);
                    if (desc.hasHullFlag(HullFlags.REVERSE_ORDER)) {
                        dest_ptr.set(dest_idx + 1, source_ptr.get(source_idx + 2));
                        dest_ptr.set(dest_idx + 2, source_ptr.get(source_idx + 1));
                        dest_ptr.set(dest_idx + 3, source_ptr.get(source_idx + 0));
                    } else {
                        dest_ptr.set(dest_idx + 1, source_ptr.get(source_idx + 0));
                        dest_ptr.set(dest_idx + 2, source_ptr.get(source_idx + 1));
                        dest_ptr.set(dest_idx + 3, source_ptr.get(source_idx + 2));
                    }
                    dest_idx += 4;
                    source_idx += 3;
                }
            }
            releaseHull(hr);
        }
    }
    return ret;
}
Also used : FasterList(jcog.list.FasterList) IntArrayList(spacegraph.space3d.phys.util.IntArrayList) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 5 with IntArrayList

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

the class HullLibrary method calchull.

private int calchull(FasterList<v3> verts, int verts_count, IntArrayList tris_out, int[] tris_count, int vlimit) {
    int rc = calchullgen(verts, verts_count, vlimit);
    if (rc == 0)
        return 0;
    IntArrayList ts = new IntArrayList();
    for (int i = 0; i < tris.size(); i++) {
        // return array[index];
        if (tris.get(i) != null) {
            for (int j = 0; j < 3; j++) {
                // return array[index];
                ts.add((tris.get(i)).getCoord(j));
            }
            // return array[index];
            deAllocateTriangle(tris.get(i));
        }
    }
    tris_count[0] = ts.size() / 3;
    MiscUtil.resize(tris_out, ts.size(), 0);
    for (int i = 0; i < ts.size(); i++) {
        tris_out.set(i, ts.get(i));
    }
    MiscUtil.resize(tris, 0, Tri.class);
    return 1;
}
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