Search in sources :

Example 11 with Collidable

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

the class CompoundCollisionAlgorithm method calculateTimeOfImpact.

@Override
public float calculateTimeOfImpact(Collidable body0, Collidable body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
    Collidable colObj = isSwapped ? body1 : body0;
    Collidable otherObj = isSwapped ? body0 : body1;
    assert (colObj.shape().isCompound());
    CompoundShape compoundShape = (CompoundShape) colObj.shape();
    // We will use the OptimizedBVH, AABB tree to cull potential child-overlaps
    // If both proxies are Compound, we will deal with that directly, by performing sequential/parallel tree traversals
    // given Proxy0 and Proxy1, if both have a tree, Tree0 and Tree1, this means:
    // determine overlapping nodes of Proxy1 using Proxy0 AABB against Tree1
    // then use each overlapping node AABB against Tree0
    // and vise versa.
    Transform tmpTrans = new Transform();
    Transform orgTrans = new Transform();
    Transform childTrans = new Transform();
    float hitFraction = 1f;
    int numChildren = childCollisionAlgorithms.size();
    int i;
    for (i = 0; i < numChildren; i++) {
        // temporarily exchange parent btCollisionShape with childShape, and recurse
        CollisionShape childShape = compoundShape.getChildShape(i);
        // backup
        colObj.getWorldTransform(orgTrans);
        compoundShape.getChildTransform(i, childTrans);
        // btTransform	newChildWorldTrans = orgTrans*childTrans ;
        tmpTrans.set(orgTrans);
        tmpTrans.mul(childTrans);
        colObj.transform(tmpTrans);
        CollisionShape tmpShape = colObj.shape();
        colObj.internalSetTemporaryCollisionShape(childShape);
        // return array[index];
        float frac = childCollisionAlgorithms.get(i).calculateTimeOfImpact(colObj, otherObj, dispatchInfo, resultOut);
        if (frac < hitFraction) {
            hitFraction = frac;
        }
        // revert back
        colObj.internalSetTemporaryCollisionShape(tmpShape);
        colObj.transform(orgTrans);
    }
    return hitFraction;
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) CollisionShape(spacegraph.space3d.phys.shape.CollisionShape) CompoundShape(spacegraph.space3d.phys.shape.CompoundShape) Transform(spacegraph.space3d.phys.math.Transform)

Example 12 with Collidable

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

the class ConvexConcaveCollisionAlgorithm method processCollision.

@Override
public void processCollision(Collidable body0, Collidable body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
    Collidable convexBody = isSwapped ? body1 : body0;
    Collidable triBody = isSwapped ? body0 : body1;
    if (triBody.shape().isConcave()) {
        Collidable triOb = triBody;
        ConcaveShape concaveShape = (ConcaveShape) triOb.shape();
        if (convexBody.shape().isConvex()) {
            float collisionMarginTriangle = concaveShape.getMargin();
            resultOut.setPersistentManifold(btConvexTriangleCallback.manifoldPtr);
            btConvexTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle, dispatchInfo, resultOut);
            // Disable persistency. previously, some older algorithm calculated all contacts in one go, so you can clear it here.
            // m_dispatcher->clearManifold(m_btConvexTriangleCallback.m_manifoldPtr);
            btConvexTriangleCallback.manifoldPtr.setBodies(convexBody, triBody);
            concaveShape.processAllTriangles(btConvexTriangleCallback, btConvexTriangleCallback.getAabbMin(new v3()), btConvexTriangleCallback.getAabbMax(new v3()));
            resultOut.refreshContactPoints();
        }
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) ConcaveShape(spacegraph.space3d.phys.shape.ConcaveShape) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 13 with Collidable

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

the class ConvexPlaneCollisionAlgorithm method init.

public void init(PersistentManifold mf, CollisionAlgorithmConstructionInfo ci, Collidable col0, Collidable col1, boolean isSwapped) {
    super.init(ci);
    this.ownManifold = false;
    this.manifoldPtr = mf;
    this.isSwapped = isSwapped;
    Collidable convexObj = isSwapped ? col1 : col0;
    Collidable planeObj = isSwapped ? col0 : col1;
    if (manifoldPtr == null && intersecter.needsCollision(convexObj, planeObj)) {
        manifoldPtr = intersecter.getNewManifold(convexObj, planeObj);
        ownManifold = true;
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable)

Example 14 with Collidable

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

the class DefaultNearCallback method handleCollision.

@Override
public void handleCollision(BroadphasePair collisionPair, DefaultIntersecter dispatcher, DispatcherInfo dispatchInfo) {
    Collidable colObj0 = collisionPair.pProxy0.data;
    Collidable colObj1 = collisionPair.pProxy1.data;
    if (dispatcher.needsCollision(colObj0, colObj1)) {
        // dispatcher will keep algorithms persistent in the collision pair
        if (collisionPair.algorithm == null) {
            collisionPair.algorithm = dispatcher.findAlgorithm(colObj0, colObj1);
        }
        if (collisionPair.algorithm != null) {
            // ManifoldResult contactPointResult = new ManifoldResult(colObj0, colObj1);
            contactPointResult.init(colObj0, colObj1);
            if (dispatchInfo.dispatchFunc == DispatchFunc.DISPATCH_DISCRETE) {
                // discrete collision detection query
                collisionPair.algorithm.processCollision(colObj0, colObj1, dispatchInfo, contactPointResult);
            } else {
                // continuous collision detection query, time of impact (toi)
                float toi = collisionPair.algorithm.calculateTimeOfImpact(colObj0, colObj1, dispatchInfo, contactPointResult);
                if (dispatchInfo.timeOfImpact > toi) {
                    dispatchInfo.timeOfImpact = toi;
                }
            }
        }
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable)

Example 15 with Collidable

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

the class GhostObject method addOverlappingObjectInternal.

/**
 * This method is mainly for expert/internal use only.
 */
public void addOverlappingObjectInternal(Broadphasing otherProxy, Broadphasing thisProxy) {
    Collidable otherObject = otherProxy.data;
    assert (otherObject != null);
    // if this linearSearch becomes too slow (too many overlapping objects) we should add a more appropriate data structure
    int index = overlappingObjects.indexOf(otherObject);
    if (index == -1) {
        // not found
        overlappingObjects.add(otherObject);
    }
}
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