Search in sources :

Example 46 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class Dbvt method collideTT.

public static void collideTT(Node root0, Transform xform0, Node root1, Transform xform1, ICollide policy) {
    Stack stack = Stack.enter();
    Transform xform = stack.allocTransform();
    xform.inverse(xform0);
    xform.mul(xform1);
    collideTT(root0, root1, xform, policy);
    stack.leave();
}
Also used : Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 47 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class CompoundCollisionAlgorithm method calculateTimeOfImpact.

@Override
public float calculateTimeOfImpact(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
    Stack stack = Stack.enter();
    CollisionObject colObj = isSwapped ? body1 : body0;
    CollisionObject otherObj = isSwapped ? body0 : body1;
    assert (colObj.getCollisionShape().isCompound());
    CompoundShape compoundShape = (CompoundShape) colObj.getCollisionShape();
    // 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 = stack.allocTransform();
    Transform orgTrans = stack.allocTransform();
    Transform childTrans = stack.allocTransform();
    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.setWorldTransform(tmpTrans);
        CollisionShape tmpShape = colObj.getCollisionShape();
        colObj.internalSetTemporaryCollisionShape(childShape);
        float frac = childCollisionAlgorithms.getQuick(i).calculateTimeOfImpact(colObj, otherObj, dispatchInfo, resultOut);
        if (frac < hitFraction) {
            hitFraction = frac;
        }
        // revert back
        colObj.internalSetTemporaryCollisionShape(tmpShape);
        colObj.setWorldTransform(orgTrans);
    }
    stack.leave();
    return hitFraction;
}
Also used : CollisionShape(com.bulletphysics.collision.shapes.CollisionShape) CompoundShape(com.bulletphysics.collision.shapes.CompoundShape) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 48 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class ConvexConcaveCollisionAlgorithm method calculateTimeOfImpact.

@Override
public float calculateTimeOfImpact(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    CollisionObject convexbody = isSwapped ? body1 : body0;
    CollisionObject 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(stack.allocTransform()).origin, convexbody.getWorldTransform(stack.allocTransform()).origin);
    float squareMot0 = tmp.lengthSquared();
    if (squareMot0 < convexbody.getCcdSquareMotionThreshold()) {
        stack.leave();
        return 1f;
    }
    Transform tmpTrans = stack.allocTransform();
    //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(stack.allocTransform());
    triInv.inverse();
    Transform convexFromLocal = stack.allocTransform();
    convexFromLocal.mul(triInv, convexbody.getWorldTransform(tmpTrans));
    Transform convexToLocal = stack.allocTransform();
    convexToLocal.mul(triInv, convexbody.getInterpolationWorldTransform(tmpTrans));
    if (triBody.getCollisionShape().isConcave()) {
        Vector3f rayAabbMin = stack.alloc(convexFromLocal.origin);
        VectorUtil.setMin(rayAabbMin, convexToLocal.origin);
        Vector3f rayAabbMax = stack.alloc(convexFromLocal.origin);
        VectorUtil.setMax(rayAabbMax, convexToLocal.origin);
        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();
        CollisionObject concavebody = triBody;
        ConcaveShape triangleMesh = (ConcaveShape) concavebody.getCollisionShape();
        if (triangleMesh != null) {
            triangleMesh.processAllTriangles(raycastCallback, rayAabbMin, rayAabbMax);
        }
        if (raycastCallback.hitFraction < convexbody.getHitFraction()) {
            convexbody.setHitFraction(raycastCallback.hitFraction);
            stack.leave();
            return raycastCallback.hitFraction;
        }
    }
    stack.leave();
    return 1f;
}
Also used : Vector3f(javax.vecmath.Vector3f) ConcaveShape(com.bulletphysics.collision.shapes.ConcaveShape) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 49 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class ConvexTriangleCallback method processTriangle.

public void processTriangle(Vector3f[] triangle, int partId, int triangleIndex) {
    // just for debugging purposes
    //printf("triangle %d",m_triangleCount++);
    // aabb filter is already applied!	
    ci.dispatcher1 = dispatcher;
    CollisionObject ob = (CollisionObject) triBody;
    // debug drawing of the overlapping triangles
    if (dispatchInfoPtr != null && dispatchInfoPtr.debugDraw != null && dispatchInfoPtr.debugDraw.getDebugMode() > 0) {
        Stack stack = Stack.enter();
        Vector3f color = stack.allocVector3f();
        color.set(255, 255, 0);
        Transform tr = ob.getWorldTransform(stack.allocTransform());
        Vector3f tmp1 = stack.allocVector3f();
        Vector3f tmp2 = stack.allocVector3f();
        tmp1.set(triangle[0]);
        tr.transform(tmp1);
        tmp2.set(triangle[1]);
        tr.transform(tmp2);
        dispatchInfoPtr.debugDraw.drawLine(tmp1, tmp2, color);
        tmp1.set(triangle[1]);
        tr.transform(tmp1);
        tmp2.set(triangle[2]);
        tr.transform(tmp2);
        dispatchInfoPtr.debugDraw.drawLine(tmp1, tmp2, color);
        tmp1.set(triangle[2]);
        tr.transform(tmp1);
        tmp2.set(triangle[0]);
        tr.transform(tmp2);
        dispatchInfoPtr.debugDraw.drawLine(tmp1, tmp2, color);
        //btVector3 center = triangle[0] + triangle[1]+triangle[2];
        //center *= btScalar(0.333333);
        //m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(center),color);
        //m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(center),color);
        //m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(center),color);
        stack.leave();
    }
    if (convexBody.getCollisionShape().isConvex()) {
        tm.init(triangle[0], triangle[1], triangle[2]);
        tm.setMargin(collisionMarginTriangle);
        CollisionShape tmpShape = ob.getCollisionShape();
        ob.internalSetTemporaryCollisionShape(tm);
        CollisionAlgorithm colAlgo = ci.dispatcher1.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();
        ci.dispatcher1.freeCollisionAlgorithm(colAlgo);
        ob.internalSetTemporaryCollisionShape(tmpShape);
    }
}
Also used : CollisionShape(com.bulletphysics.collision.shapes.CollisionShape) CollisionAlgorithm(com.bulletphysics.collision.broadphase.CollisionAlgorithm) Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 50 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class GhostObject method rayTest.

public void rayTest(Vector3f rayFromWorld, Vector3f rayToWorld, CollisionWorld.RayResultCallback resultCallback) {
    Stack stack = Stack.enter();
    Transform rayFromTrans = stack.allocTransform();
    rayFromTrans.setIdentity();
    rayFromTrans.origin.set(rayFromWorld);
    Transform rayToTrans = stack.allocTransform();
    rayToTrans.setIdentity();
    rayToTrans.origin.set(rayToWorld);
    Transform tmpTrans = stack.allocTransform();
    for (int i = 0; i < overlappingObjects.size(); i++) {
        CollisionObject collisionObject = overlappingObjects.getQuick(i);
        // only perform raycast if filterMask matches
        if (resultCallback.needsCollision(collisionObject.getBroadphaseHandle())) {
            CollisionWorld.rayTestSingle(rayFromTrans, rayToTrans, collisionObject, collisionObject.getCollisionShape(), collisionObject.getWorldTransform(tmpTrans), resultCallback);
        }
    }
    stack.leave();
}
Also used : Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Aggregations

Transform (com.bulletphysics.linearmath.Transform)81 Stack (com.bulletphysics.util.Stack)65 Vector3f (javax.vecmath.Vector3f)53 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)11 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)10 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)10 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)9 Matrix3f (javax.vecmath.Matrix3f)8 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)7 SphereShape (com.bulletphysics.collision.shapes.SphereShape)5 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)4 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)3 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3 StaticPlaneShape (com.bulletphysics.collision.shapes.StaticPlaneShape)3 BroadphaseInterface (com.bulletphysics.collision.broadphase.BroadphaseInterface)2 ConvexCast (com.bulletphysics.collision.narrowphase.ConvexCast)2 CastResult (com.bulletphysics.collision.narrowphase.ConvexCast.CastResult)2 GjkConvexCast (com.bulletphysics.collision.narrowphase.GjkConvexCast)2 SubsimplexConvexCast (com.bulletphysics.collision.narrowphase.SubsimplexConvexCast)2