Search in sources :

Example 1 with Collidable

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

the class ConvexTriangleCallback method processTriangle.

@Override
public void processTriangle(v3[] triangle, int partId, int triangleIndex) {
    // just for debugging purposes
    // printf("triangle %d",m_triangleCount++);
    // aabb filter is already applied!
    ci.intersecter1 = intersecter;
    Collidable ob = triBody;
    if (convexBody.shape().isConvex()) {
        tm.init(triangle[0], triangle[1], triangle[2]);
        tm.setMargin(collisionMarginTriangle);
        CollisionShape tmpShape = ob.shape();
        ob.internalSetTemporaryCollisionShape(tm);
        CollisionAlgorithm colAlgo = ci.intersecter1.findAlgorithm(convexBody, triBody, manifoldPtr);
        // this should use the btDispatcher, so the actual registered algorithm is used
        // btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody);
        resultOut.setShapeIdentifiers(-1, -1, partId, triangleIndex);
        // cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
        // cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
        colAlgo.processCollision(convexBody, triBody, dispatchInfoPtr, resultOut);
        // colAlgo.destroy();
        Intersecter.freeCollisionAlgorithm(colAlgo);
        ob.internalSetTemporaryCollisionShape(tmpShape);
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) CollisionShape(spacegraph.space3d.phys.shape.CollisionShape) CollisionAlgorithm(spacegraph.space3d.phys.collision.broad.CollisionAlgorithm)

Example 2 with Collidable

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

the class GhostPairCallback method addOverlappingPair.

@Override
public BroadphasePair addOverlappingPair(Broadphasing proxy0, Broadphasing proxy1) {
    Collidable colObj0 = proxy0.data;
    Collidable colObj1 = proxy1.data;
    GhostObject ghost0 = GhostObject.upcast(colObj0);
    GhostObject ghost1 = GhostObject.upcast(colObj1);
    if (ghost0 != null) {
        ghost0.addOverlappingObjectInternal(proxy1, proxy0);
    }
    if (ghost1 != null) {
        ghost1.addOverlappingObjectInternal(proxy0, proxy1);
    }
    return null;
}
Also used : Collidable(spacegraph.space3d.phys.Collidable)

Example 3 with Collidable

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

the class EdgeDirected method solve.

@Override
public void solve(Broadphase b, List<Collidable> objects, float timeStep) {
    float a = attraction.floatValue();
    for (int i = 0, objectsSize = objects.size(); i < objectsSize; i++) {
        Collidable c = objects.get(i);
        Spatial A = ((Spatial) c.data());
        // TODO abstract the Edges as a feature to optionally add to a TermWidget, not just for ConceptWidgets
        if (A instanceof SpaceWidget) {
            ((SpaceWidget<?>) A).edges().forEach(e -> {
                float attraction = e.attraction;
                if (attraction > 0) {
                    SimpleSpatial B = e.tgt();
                    if ((B.body != null)) {
                        attract(c, B.body, a * attraction, e.attractionDist);
                    }
                }
            });
        }
    }
    super.solve(b, objects, timeStep);
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) SpaceWidget(spacegraph.space3d.widget.SpaceWidget) SimpleSpatial(spacegraph.space3d.SimpleSpatial) Spatial(spacegraph.space3d.Spatial) SimpleSpatial(spacegraph.space3d.SimpleSpatial)

Example 4 with Collidable

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

the class CompoundCollisionAlgorithm method init.

public void init(CollisionAlgorithmConstructionInfo ci, Collidable body0, Collidable body1, boolean isSwapped) {
    super.init(ci);
    this.isSwapped = isSwapped;
    Collidable colObj = isSwapped ? body1 : body0;
    Collidable otherObj = isSwapped ? body0 : body1;
    assert (colObj.shape().isCompound());
    CompoundShape compoundShape = (CompoundShape) colObj.shape();
    int numChildren = compoundShape.getNumChildShapes();
    int i;
    // childCollisionAlgorithms.resize(numChildren);
    for (i = 0; i < numChildren; i++) {
        CollisionShape tmpShape = colObj.shape();
        CollisionShape childShape = compoundShape.getChildShape(i);
        colObj.internalSetTemporaryCollisionShape(childShape);
        childCollisionAlgorithms.add(ci.intersecter1.findAlgorithm(colObj, otherObj));
        colObj.internalSetTemporaryCollisionShape(tmpShape);
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) CollisionShape(spacegraph.space3d.phys.shape.CollisionShape) CompoundShape(spacegraph.space3d.phys.shape.CompoundShape)

Example 5 with Collidable

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

the class ConvexConcaveCollisionAlgorithm method calculateTimeOfImpact.

@Override
public float calculateTimeOfImpact(Collidable body0, Collidable body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
    v3 tmp = new v3();
    Collidable convexbody = isSwapped ? body1 : body0;
    Collidable triBody = isSwapped ? body0 : body1;
    // quick approximation using raycast, todo: hook up to the continuous collision detection (one of the btConvexCast)
    // only perform CCD above a certain threshold, this prevents blocking on the long run
    // because object in a blocked ccd state (hitfraction<1) get their linear velocity halved each frame...
    tmp.sub(convexbody.getInterpolationWorldTransform(new Transform()), convexbody.getWorldTransform(new Transform()));
    float squareMot0 = tmp.lengthSquared();
    if (squareMot0 < convexbody.getCcdSquareMotionThreshold()) {
        return 1f;
    }
    Transform tmpTrans = new Transform();
    // const btVector3& from = convexbody->m_worldTransform.getOrigin();
    // btVector3 to = convexbody->m_interpolationWorldTransform.getOrigin();
    // todo: only do if the motion exceeds the 'radius'
    Transform triInv = triBody.getWorldTransform(new Transform());
    triInv.inverse();
    Transform convexFromLocal = new Transform();
    convexFromLocal.mul(triInv, convexbody.getWorldTransform(tmpTrans));
    Transform convexToLocal = new Transform();
    convexToLocal.mul(triInv, convexbody.getInterpolationWorldTransform(tmpTrans));
    if (triBody.shape().isConcave()) {
        v3 rayAabbMin = new v3(convexFromLocal);
        VectorUtil.setMin(rayAabbMin, convexToLocal);
        v3 rayAabbMax = new v3(convexFromLocal);
        VectorUtil.setMax(rayAabbMax, convexToLocal);
        float ccdRadius0 = convexbody.getCcdSweptSphereRadius();
        tmp.set(ccdRadius0, ccdRadius0, ccdRadius0);
        rayAabbMin.sub(tmp);
        rayAabbMax.add(tmp);
        // is this available?
        float curHitFraction = 1f;
        LocalTriangleSphereCastCallback raycastCallback = new LocalTriangleSphereCastCallback(convexFromLocal, convexToLocal, convexbody.getCcdSweptSphereRadius(), curHitFraction);
        raycastCallback.hitFraction = convexbody.getHitFraction();
        Collidable concavebody = triBody;
        ConcaveShape triangleMesh = (ConcaveShape) concavebody.shape();
        if (triangleMesh != null) {
            triangleMesh.processAllTriangles(raycastCallback, rayAabbMin, rayAabbMax);
        }
        if (raycastCallback.hitFraction < convexbody.getHitFraction()) {
            convexbody.setHitFraction(raycastCallback.hitFraction);
            return raycastCallback.hitFraction;
        }
    }
    return 1f;
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) ConcaveShape(spacegraph.space3d.phys.shape.ConcaveShape) Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3)

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