Search in sources :

Example 1 with CompoundShape

use of spacegraph.space3d.phys.shape.CompoundShape 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 2 with CompoundShape

use of spacegraph.space3d.phys.shape.CompoundShape in project narchy by automenta.

the class CompoundCollisionAlgorithm method processCollision.

@Override
public void processCollision(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();
    Transform orgInterpolationTrans = new Transform();
    Transform newChildWorldTrans = new Transform();
    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);
        colObj.getInterpolationWorldTransform(orgInterpolationTrans);
        compoundShape.getChildTransform(i, childTrans);
        newChildWorldTrans.mul(orgTrans, childTrans);
        colObj.transform(newChildWorldTrans);
        colObj.setInterpolationWorldTransform(newChildWorldTrans);
        // the contactpoint is still projected back using the original inverted worldtrans
        CollisionShape tmpShape = colObj.shape();
        colObj.internalSetTemporaryCollisionShape(childShape);
        // return array[index];
        childCollisionAlgorithms.get(i).processCollision(colObj, otherObj, dispatchInfo, resultOut);
        // revert back
        colObj.internalSetTemporaryCollisionShape(tmpShape);
        colObj.transform(orgTrans);
        colObj.setInterpolationWorldTransform(orgInterpolationTrans);
    }
}
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 3 with CompoundShape

use of spacegraph.space3d.phys.shape.CompoundShape 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)

Aggregations

Collidable (spacegraph.space3d.phys.Collidable)3 CollisionShape (spacegraph.space3d.phys.shape.CollisionShape)3 CompoundShape (spacegraph.space3d.phys.shape.CompoundShape)3 Transform (spacegraph.space3d.phys.math.Transform)2