Search in sources :

Example 36 with Transform

use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.

the class GImpactCollisionAlgorithm method gimpact_vs_concave.

public void gimpact_vs_concave(Collidable body0, Collidable body1, GImpactShape shape0, ConcaveShape shape1, boolean swapped) {
    // create the callback
    GImpactTriangleCallback tricallback = new GImpactTriangleCallback();
    tricallback.algorithm = this;
    tricallback.body0 = body0;
    tricallback.body1 = body1;
    tricallback.gimpactshape0 = shape0;
    tricallback.swapped = swapped;
    tricallback.margin = shape1.getMargin();
    // getting the trimesh AABB
    Transform gimpactInConcaveSpace = body1.transform;
    /*new Transform();

		body1.getWorldTransform(gimpactInConcaveSpace);*/
    gimpactInConcaveSpace.inverse();
    gimpactInConcaveSpace.mul(body0.transform);
    v3 minAABB = new v3(), maxAABB = new v3();
    shape0.getAabb(gimpactInConcaveSpace, minAABB, maxAABB);
    shape1.processAllTriangles(tricallback, minAABB, maxAABB);
}
Also used : Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 37 with Transform

use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.

the class GImpactCollisionAlgorithm method collide_sat_triangles.

/*
	protected void collide_gjk_triangles(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, GImpactMeshShapePart shape1, IntArrayList pairs, int pair_count) {
	}
	*/
void collide_sat_triangles(Collidable body0, Collidable body1, GImpactMeshShape.GImpactMeshShapePart shape0, GImpactMeshShape.GImpactMeshShapePart shape1, PairSet pairs, int pair_count) {
    v3 tmp = new v3();
    Transform orgtrans0 = body0.transform;
    Transform orgtrans1 = body1.transform;
    PrimitiveTriangle ptri0 = new PrimitiveTriangle();
    PrimitiveTriangle ptri1 = new PrimitiveTriangle();
    TriangleContact contact_data = new TriangleContact();
    shape0.lockChildShapes();
    shape1.lockChildShapes();
    int pair_pointer = 0;
    float breakingThresh = manifoldPtr.getContactBreakingThreshold();
    while ((pair_count--) != 0) {
        // triface0 = pairs.get(pair_pointer);
        // triface1 = pairs.get(pair_pointer + 1);
        // pair_pointer += 2;
        Pair pair = pairs.get(pair_pointer++);
        triface0 = pair.index1;
        triface1 = pair.index2;
        shape0.getPrimitiveTriangle(triface0, ptri0);
        shape1.getPrimitiveTriangle(triface1, ptri1);
        // #ifdef TRI_COLLISION_PROFILING
        // bt_begin_gim02_tri_time();
        // #endif
        ptri0.applyTransform(orgtrans0);
        ptri1.applyTransform(orgtrans1);
        // builder planes
        ptri0.buildTriPlane();
        ptri1.buildTriPlane();
        // test conservative
        if (ptri0.overlap_test_conservative(ptri1)) {
            if (ptri0.find_triangle_collision_clip_method(ptri1, contact_data)) {
                int j = contact_data.point_count;
                while ((j--) != 0) {
                    tmp.x = contact_data.separating_normal.x;
                    tmp.y = contact_data.separating_normal.y;
                    tmp.z = contact_data.separating_normal.z;
                    addContactPoint(body0, body1, contact_data.points[j], tmp, -contact_data.penetration_depth, breakingThresh);
                }
            }
        }
    // #ifdef TRI_COLLISION_PROFILING
    // bt_end_gim02_tri_time();
    // #endif
    }
    shape0.unlockChildShapes();
    shape1.unlockChildShapes();
}
Also used : Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 38 with Transform

use of spacegraph.space3d.phys.math.Transform 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 39 with Transform

use of spacegraph.space3d.phys.math.Transform 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 40 with Transform

use of spacegraph.space3d.phys.math.Transform 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)

Aggregations

Transform (spacegraph.space3d.phys.math.Transform)56 spacegraph.util.math.v3 (spacegraph.util.math.v3)41 Matrix3f (spacegraph.util.math.Matrix3f)11 Collidable (spacegraph.space3d.phys.Collidable)6 Body3D (spacegraph.space3d.phys.Body3D)3 CollisionShape (spacegraph.space3d.phys.shape.CollisionShape)3 Quat4f (spacegraph.util.math.Quat4f)3 CompoundShape (spacegraph.space3d.phys.shape.CompoundShape)2 ConvexShape (spacegraph.space3d.phys.shape.ConvexShape)2 Surface (spacegraph.space2d.Surface)1 SimpleSpatial (spacegraph.space3d.SimpleSpatial)1 ManifoldPoint (spacegraph.space3d.phys.collision.narrow.ManifoldPoint)1 VoronoiSimplexSolver (spacegraph.space3d.phys.collision.narrow.VoronoiSimplexSolver)1 ContactConstraint (spacegraph.space3d.phys.constraint.ContactConstraint)1 Point2PointConstraint (spacegraph.space3d.phys.constraint.Point2PointConstraint)1 SolverConstraint (spacegraph.space3d.phys.constraint.SolverConstraint)1 TypedConstraint (spacegraph.space3d.phys.constraint.TypedConstraint)1 Generic6DofConstraint (spacegraph.space3d.phys.constraint.generic.Generic6DofConstraint)1 CapsuleShape (spacegraph.space3d.phys.shape.CapsuleShape)1 ConcaveShape (spacegraph.space3d.phys.shape.ConcaveShape)1