Search in sources :

Example 16 with Collidable

use of spacegraph.space3d.phys.Collidable in project narchy by automenta.

the class GhostObject method rayTest.

public void rayTest(v3 rayFromWorld, v3 rayToWorld, Collisions.RayResultCallback resultCallback) {
    Transform rayFromTrans = new Transform();
    rayFromTrans.setIdentity();
    rayFromTrans.set(rayFromWorld);
    Transform rayToTrans = new Transform();
    rayToTrans.setIdentity();
    rayToTrans.set(rayToWorld);
    Transform tmpTrans = new Transform();
    VoronoiSimplexSolver solver = new VoronoiSimplexSolver();
    for (int i = 0; i < overlappingObjects.size(); i++) {
        // return array[index];
        Collidable collidable = overlappingObjects.get(i);
        // only perform raycast if filterMask matches
        if (resultCallback.needsCollision(collidable.broadphase)) {
            Collisions.rayTestSingle(rayFromTrans, rayToTrans, collidable, collidable.shape(), collidable.getWorldTransform(tmpTrans), solver, resultCallback);
        }
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) VoronoiSimplexSolver(spacegraph.space3d.phys.collision.narrow.VoronoiSimplexSolver) Transform(spacegraph.space3d.phys.math.Transform)

Example 17 with Collidable

use of spacegraph.space3d.phys.Collidable in project narchy by automenta.

the class Islands method findUnions.

public void findUnions(Collisions colWorld) {
    FasterList<BroadphasePair> pairPtr = colWorld.pairs().getOverlappingPairArray();
    int n = pairPtr.size();
    for (int i = 0; i < n; i++) {
        // return array[index];
        BroadphasePair collisionPair = pairPtr.get(i);
        Collidable colObj0 = collisionPair.pProxy0.data;
        if (colObj0 != null && ((colObj0).mergesSimulationIslands())) {
            Collidable colObj1 = collisionPair.pProxy1.data;
            if (colObj1 != null && ((colObj1).mergesSimulationIslands())) {
                find.unite((colObj0).tag(), (colObj1).tag());
            }
        }
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) BroadphasePair(spacegraph.space3d.phys.collision.broad.BroadphasePair)

Example 18 with Collidable

use of spacegraph.space3d.phys.Collidable in project narchy by automenta.

the class Islands method buildIslands.

public void buildIslands(Intersecter intersecter, List<Collidable> collidables) {
    // System.out.println("builder islands");
    islandmanifold.clearFast();
    // we are going to sort the unionfind array, and store the element id in the size
    // afterwards, we clean unionfind, to make sure no-one uses it anymore
    find.sortIslands();
    int numElem = find.size();
    int endIslandIndex = 1;
    int startIslandIndex;
    // update the sleeping state for bodies, if all are sleeping
    for (startIslandIndex = 0; startIslandIndex < numElem; startIslandIndex = endIslandIndex) {
        int islandId = find.id(startIslandIndex);
        for (endIslandIndex = startIslandIndex + 1; (endIslandIndex < numElem) && (find.id(endIslandIndex) == islandId); endIslandIndex++) {
        }
        // int numSleeping = 0;
        boolean allSleeping = true;
        int idx;
        for (idx = startIslandIndex; idx < endIslandIndex; idx++) {
            int i = find.sz(idx);
            // return array[index];
            final Collidable colObj0 = collidables.get(i);
            final int tag0 = colObj0.tag();
            if ((tag0 != islandId) && (tag0 != -1)) {
                islandError(colObj0);
                continue;
            }
            // assert ((tag0 == islandId) || (tag0 == -1));
            if (tag0 == islandId) {
                int s = colObj0.getActivationState();
                if (s == Collidable.ACTIVE_TAG || s == Collidable.DISABLE_DEACTIVATION) {
                    allSleeping = false;
                }
            }
        }
        if (allSleeping) {
            // int idx;
            for (idx = startIslandIndex; idx < endIslandIndex; idx++) {
                int i = find.sz(idx);
                // return array[index];
                final Collidable colObj0 = collidables.get(i);
                int tag0 = colObj0.tag();
                if ((tag0 != islandId) && (tag0 != -1)) {
                    islandError(colObj0);
                    continue;
                }
                if (tag0 == islandId) {
                    colObj0.setActivationState(Collidable.ISLAND_SLEEPING);
                }
            }
        } else {
            // int idx;
            for (idx = startIslandIndex; idx < endIslandIndex; idx++) {
                int i = find.sz(idx);
                // return array[index];
                Collidable colObj0 = collidables.get(i);
                int tag0 = colObj0.tag();
                if ((tag0 != islandId) && (tag0 != -1)) {
                    islandError(colObj0);
                    continue;
                }
                if (tag0 == islandId) {
                    if (colObj0.getActivationState() == Collidable.ISLAND_SLEEPING) {
                        colObj0.setActivationState(Collidable.WANTS_DEACTIVATION);
                    }
                }
            }
        }
    }
    int i;
    int maxNumManifolds = intersecter.manifoldCount();
    for (i = 0; i < maxNumManifolds; i++) {
        PersistentManifold manifold = intersecter.manifold(i);
        Collidable colObj0 = (Collidable) manifold.getBody0();
        if (colObj0 != null) {
            Collidable colObj1 = (Collidable) manifold.getBody1();
            if (colObj1 != null) {
                // todo: check sleeping conditions!
                int s0 = colObj0.getActivationState();
                int s1 = colObj1.getActivationState();
                if ((s0 != Collidable.ISLAND_SLEEPING) || (s1 != Collidable.ISLAND_SLEEPING)) {
                    // kinematic objects don't merge islands, but wake up all connected objects
                    if (s0 != Collidable.ISLAND_SLEEPING && colObj0.isKinematicObject()) {
                        colObj1.activate(true);
                    }
                    if (s1 != Collidable.ISLAND_SLEEPING && colObj1.isKinematicObject()) {
                        colObj0.activate(true);
                    }
                    // filtering for response
                    if (intersecter.needsResponse(colObj0, colObj1)) {
                        islandmanifold.add(manifold);
                    }
                // #endif //SPLIT_ISLANDS
                }
            }
        }
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) PersistentManifold(spacegraph.space3d.phys.collision.narrow.PersistentManifold)

Example 19 with Collidable

use of spacegraph.space3d.phys.Collidable in project narchy by automenta.

the class Islands method buildAndProcessIslands.

public <X> void buildAndProcessIslands(Intersecter intersecter, List<Collidable> collidables, IslandCallback callback) {
    buildIslands(intersecter, collidables);
    int endIslandIndex = 1;
    int startIslandIndex;
    int numElem = find.size();
    // #ifndef SPLIT_ISLANDS
    // btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer();
    // 
    // callback->ProcessIsland(&collisionObjects[0],collisionObjects.size(),manifold,maxNumManifolds, -1);
    // #else
    // Sort manifolds, based on islands
    // Sort the vector using predicate and std::sort
    // std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate);
    int numManifolds = islandmanifold.size();
    // we should do radix sort, it it much faster (O(n) instead of O (n log2(n))
    // islandmanifold.heapSort(btPersistentManifoldSortPredicate());
    // JAVA NOTE: memory optimized sorting with caching of temporary array
    // Collections.sort(islandmanifold, persistentManifoldComparator);
    MiscUtil.quickSort(islandmanifold, persistentManifoldComparator);
    // now process all active islands (sets of manifolds for now)
    int startManifoldIndex = 0;
    int endManifoldIndex = 1;
    // traverse the simulation islands, and call the solver, unless all objects are sleeping/deactivated
    for (startIslandIndex = 0; startIslandIndex < numElem; startIslandIndex = endIslandIndex) {
        int islandId = find.id(startIslandIndex);
        boolean islandSleeping = false;
        for (endIslandIndex = startIslandIndex; (endIslandIndex < numElem) && ((find.id(endIslandIndex) == islandId)); endIslandIndex++) {
            int i = find.sz(endIslandIndex);
            // return array[index];
            Collidable colObj0 = collidables.get(i);
            islandBodies.add(colObj0);
            if (!colObj0.isActive()) {
                islandSleeping = true;
            }
        }
        // find the accompanying contact manifold for this islandId
        int numIslandManifolds = 0;
        // ObjectArrayList<PersistentManifold> startManifold = null;
        int startManifold_idx = -1;
        if (startManifoldIndex < numManifolds) {
            // return array[index];
            int curIslandId = getIslandId(islandmanifold.get(startManifoldIndex));
            if (curIslandId == islandId) {
                // startManifold = &m_islandmanifold[startManifoldIndex];
                // startManifold = islandmanifold.subList(startManifoldIndex, islandmanifold.size());
                startManifold_idx = startManifoldIndex;
                // return array[index];
                for (endManifoldIndex = startManifoldIndex + 1; (endManifoldIndex < numManifolds) && (islandId == getIslandId(islandmanifold.get(endManifoldIndex))); endManifoldIndex++) {
                }
                // Process the actual simulation, only if not sleeping/deactivated
                numIslandManifolds = endManifoldIndex - startManifoldIndex;
            }
        }
        if (!islandSleeping) {
            callback.processIsland(islandBodies, islandmanifold, startManifold_idx, numIslandManifolds, islandId);
        // printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds);
        }
        if (numIslandManifolds != 0) {
            startManifoldIndex = endManifoldIndex;
        }
        islandBodies.clearFast();
    }
// #endif //SPLIT_ISLANDS
}
Also used : Collidable(spacegraph.space3d.phys.Collidable)

Example 20 with Collidable

use of spacegraph.space3d.phys.Collidable in project narchy by automenta.

the class Islands method getIslandId.

private static int getIslandId(PersistentManifold lhs) {
    Collidable rcolObj0 = (Collidable) lhs.getBody0();
    int t0 = rcolObj0.tag();
    if (t0 >= 0)
        return t0;
    Collidable rcolObj1 = (Collidable) lhs.getBody1();
    return rcolObj1.tag();
}
Also used : Collidable(spacegraph.space3d.phys.Collidable)

Aggregations

Collidable (spacegraph.space3d.phys.Collidable)26 Transform (spacegraph.space3d.phys.math.Transform)6 spacegraph.util.math.v3 (spacegraph.util.math.v3)6 CollisionShape (spacegraph.space3d.phys.shape.CollisionShape)4 PersistentManifold (spacegraph.space3d.phys.collision.narrow.PersistentManifold)3 CompoundShape (spacegraph.space3d.phys.shape.CompoundShape)3 Broadphasing (spacegraph.space3d.phys.collision.broad.Broadphasing)2 ManifoldPoint (spacegraph.space3d.phys.collision.narrow.ManifoldPoint)2 ConcaveShape (spacegraph.space3d.phys.shape.ConcaveShape)2 SimpleSpatial (spacegraph.space3d.SimpleSpatial)1 Spatial (spacegraph.space3d.Spatial)1 Body3D (spacegraph.space3d.phys.Body3D)1 ClosestRay (spacegraph.space3d.phys.collision.ClosestRay)1 BroadphasePair (spacegraph.space3d.phys.collision.broad.BroadphasePair)1 CollisionAlgorithm (spacegraph.space3d.phys.collision.broad.CollisionAlgorithm)1 VoronoiSimplexSolver (spacegraph.space3d.phys.collision.narrow.VoronoiSimplexSolver)1 ContactConstraint (spacegraph.space3d.phys.constraint.ContactConstraint)1 SolverConstraint (spacegraph.space3d.phys.constraint.SolverConstraint)1 TypedConstraint (spacegraph.space3d.phys.constraint.TypedConstraint)1 ConvexShape (spacegraph.space3d.phys.shape.ConvexShape)1