Search in sources :

Example 11 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class DbvtAabbMm method swap.

public static void swap(DbvtAabbMm p1, DbvtAabbMm p2) {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    tmp.set(p1.mi);
    p1.mi.set(p2.mi);
    p2.mi.set(tmp);
    tmp.set(p1.mx);
    p1.mx.set(p2.mx);
    p2.mx.set(tmp);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 12 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class DbvtAabbMm method Intersect.

public static boolean Intersect(DbvtAabbMm a, DbvtAabbMm b, Transform xform) {
    Stack stack = Stack.enter();
    Vector3f d0 = stack.allocVector3f();
    Vector3f d1 = stack.allocVector3f();
    Vector3f tmp = stack.allocVector3f();
    // JAVA NOTE: check
    b.Center(d0);
    xform.transform(d0);
    d0.sub(a.Center(tmp));
    MatrixUtil.transposeTransform(d1, d0, xform.basis);
    float[] s0 = new float[] { 0, 0 };
    float[] s1 = new float[2];
    s1[0] = xform.origin.dot(d0);
    s1[1] = s1[0];
    a.AddSpan(d0, s0, 0, s0, 1);
    b.AddSpan(d1, s1, 0, s1, 1);
    if (s0[0] > (s1[1])) {
        stack.leave();
        return false;
    }
    if (s0[1] < (s1[0])) {
        stack.leave();
        return false;
    }
    stack.leave();
    return true;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 13 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class DbvtAabbMm method Proximity.

public static float Proximity(DbvtAabbMm a, DbvtAabbMm b) {
    Stack stack = Stack.enter();
    Vector3f d = stack.allocVector3f();
    Vector3f tmp = stack.allocVector3f();
    d.add(a.mi, a.mx);
    tmp.add(b.mi, b.mx);
    d.sub(tmp);
    float result = Math.abs(d.x) + Math.abs(d.y) + Math.abs(d.z);
    stack.leave();
    return result;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 14 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class CollisionWorld method updateSingleAabb.

// JAVA NOTE: ported from 2.74, missing contact threshold stuff
public void updateSingleAabb(CollisionObject colObj) {
    Stack stack = Stack.enter();
    Vector3f minAabb = stack.allocVector3f(), maxAabb = stack.allocVector3f();
    Vector3f tmp = stack.allocVector3f();
    Transform tmpTrans = stack.allocTransform();
    colObj.getCollisionShape().getAabb(colObj.getWorldTransform(tmpTrans), minAabb, maxAabb);
    // need to increase the aabb for contact thresholds
    Vector3f contactThreshold = stack.allocVector3f();
    contactThreshold.set(BulletGlobals.getContactBreakingThreshold(), BulletGlobals.getContactBreakingThreshold(), BulletGlobals.getContactBreakingThreshold());
    minAabb.sub(contactThreshold);
    maxAabb.add(contactThreshold);
    BroadphaseInterface bp = broadphasePairCache;
    // moving objects should be moderately sized, probably something wrong if not
    // TODO: optimize
    tmp.sub(maxAabb, minAabb);
    if (colObj.isStaticObject() || (tmp.lengthSquared() < 1e12f)) {
        bp.setAabb(colObj.getBroadphaseHandle(), minAabb, maxAabb, dispatcher1);
    } else {
        // something went wrong, investigate
        // this assert is unwanted in 3D modelers (danger of loosing work)
        colObj.setActivationState(CollisionObject.DISABLE_SIMULATION);
        if (updateAabbs_reportMe && debugDrawer != null) {
            updateAabbs_reportMe = false;
            debugDrawer.reportErrorWarning("Overflow in AABB, object removed from simulation");
            debugDrawer.reportErrorWarning("If you can reproduce this, please email bugs@continuousphysics.com\n");
            debugDrawer.reportErrorWarning("Please include above information, your Platform, version of OS.\n");
            debugDrawer.reportErrorWarning("Thanks.\n");
        }
    }
    stack.leave();
}
Also used : BroadphaseInterface(com.bulletphysics.collision.broadphase.BroadphaseInterface) Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 15 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class CollisionWorld method rayTestSingle.

// TODO
public static void rayTestSingle(Transform rayFromTrans, Transform rayToTrans, CollisionObject collisionObject, CollisionShape collisionShape, Transform colObjWorldTransform, RayResultCallback resultCallback) {
    Stack stack = Stack.enter();
    SphereShape pointShape = new SphereShape(0f);
    pointShape.setMargin(0f);
    ConvexShape castShape = pointShape;
    if (collisionShape.isConvex()) {
        CastResult castResult = new CastResult();
        castResult.fraction = resultCallback.closestHitFraction;
        ConvexShape convexShape = (ConvexShape) collisionShape;
        VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver();
        //#define USE_SUBSIMPLEX_CONVEX_CAST 1
        //#ifdef USE_SUBSIMPLEX_CONVEX_CAST
        SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(castShape, convexShape, simplexSolver);
        if (convexCaster.calcTimeOfImpact(rayFromTrans, rayToTrans, colObjWorldTransform, colObjWorldTransform, castResult)) {
            //add hit
            if (castResult.normal.lengthSquared() > 0.0001f) {
                if (castResult.fraction < resultCallback.closestHitFraction) {
                    //#ifdef USE_SUBSIMPLEX_CONVEX_CAST
                    //rotate normal into worldspace
                    rayFromTrans.basis.transform(castResult.normal);
                    //#endif //USE_SUBSIMPLEX_CONVEX_CAST
                    castResult.normal.normalize();
                    LocalRayResult localRayResult = new LocalRayResult(collisionObject, null, castResult.normal, castResult.fraction);
                    boolean normalInWorldSpace = true;
                    resultCallback.addSingleResult(localRayResult, normalInWorldSpace);
                }
            }
        }
    } else {
        if (collisionShape.isConcave()) {
            if (collisionShape.getShapeType() == BroadphaseNativeType.TRIANGLE_MESH_SHAPE_PROXYTYPE) {
                // optimized version for BvhTriangleMeshShape
                BvhTriangleMeshShape triangleMesh = (BvhTriangleMeshShape) collisionShape;
                Transform worldTocollisionObject = stack.allocTransform();
                worldTocollisionObject.inverse(colObjWorldTransform);
                Vector3f rayFromLocal = stack.alloc(rayFromTrans.origin);
                worldTocollisionObject.transform(rayFromLocal);
                Vector3f rayToLocal = stack.alloc(rayToTrans.origin);
                worldTocollisionObject.transform(rayToLocal);
                BridgeTriangleRaycastCallback rcb = new BridgeTriangleRaycastCallback(rayFromLocal, rayToLocal, resultCallback, collisionObject, triangleMesh);
                rcb.hitFraction = resultCallback.closestHitFraction;
                triangleMesh.performRaycast(rcb, rayFromLocal, rayToLocal);
            } else {
                ConcaveShape triangleMesh = (ConcaveShape) collisionShape;
                Transform worldTocollisionObject = stack.allocTransform();
                worldTocollisionObject.inverse(colObjWorldTransform);
                Vector3f rayFromLocal = stack.alloc(rayFromTrans.origin);
                worldTocollisionObject.transform(rayFromLocal);
                Vector3f rayToLocal = stack.alloc(rayToTrans.origin);
                worldTocollisionObject.transform(rayToLocal);
                BridgeTriangleRaycastCallback rcb = new BridgeTriangleRaycastCallback(rayFromLocal, rayToLocal, resultCallback, collisionObject, triangleMesh);
                rcb.hitFraction = resultCallback.closestHitFraction;
                Vector3f rayAabbMinLocal = stack.alloc(rayFromLocal);
                VectorUtil.setMin(rayAabbMinLocal, rayToLocal);
                Vector3f rayAabbMaxLocal = stack.alloc(rayFromLocal);
                VectorUtil.setMax(rayAabbMaxLocal, rayToLocal);
                triangleMesh.processAllTriangles(rcb, rayAabbMinLocal, rayAabbMaxLocal);
            }
        } else {
            // todo: use AABB tree or other BVH acceleration structure!
            if (collisionShape.isCompound()) {
                CompoundShape compoundShape = (CompoundShape) collisionShape;
                int i = 0;
                Transform childTrans = stack.allocTransform();
                for (i = 0; i < compoundShape.getNumChildShapes(); i++) {
                    compoundShape.getChildTransform(i, childTrans);
                    CollisionShape childCollisionShape = compoundShape.getChildShape(i);
                    Transform childWorldTrans = stack.alloc(colObjWorldTransform);
                    childWorldTrans.mul(childTrans);
                    // replace collision shape so that callback can determine the triangle
                    CollisionShape saveCollisionShape = collisionObject.getCollisionShape();
                    collisionObject.internalSetTemporaryCollisionShape(childCollisionShape);
                    rayTestSingle(rayFromTrans, rayToTrans, collisionObject, childCollisionShape, childWorldTrans, resultCallback);
                    // restore
                    collisionObject.internalSetTemporaryCollisionShape(saveCollisionShape);
                }
            }
        }
    }
    stack.leave();
}
Also used : CollisionShape(com.bulletphysics.collision.shapes.CollisionShape) ConcaveShape(com.bulletphysics.collision.shapes.ConcaveShape) CompoundShape(com.bulletphysics.collision.shapes.CompoundShape) Stack(com.bulletphysics.util.Stack) CastResult(com.bulletphysics.collision.narrowphase.ConvexCast.CastResult) BvhTriangleMeshShape(com.bulletphysics.collision.shapes.BvhTriangleMeshShape) VoronoiSimplexSolver(com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver) Vector3f(javax.vecmath.Vector3f) ConvexShape(com.bulletphysics.collision.shapes.ConvexShape) SphereShape(com.bulletphysics.collision.shapes.SphereShape) Transform(com.bulletphysics.linearmath.Transform) SubsimplexConvexCast(com.bulletphysics.collision.narrowphase.SubsimplexConvexCast)

Aggregations

Vector3f (javax.vecmath.Vector3f)266 Stack (com.bulletphysics.util.Stack)197 Transform (com.bulletphysics.linearmath.Transform)53 Matrix3f (javax.vecmath.Matrix3f)25 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)14 StaticAlloc (com.bulletphysics.util.StaticAlloc)12 Matrix4f (javax.vecmath.Matrix4f)10 Vector4f (javax.vecmath.Vector4f)8 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)7 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)7 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)6 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)5 Quat4f (javax.vecmath.Quat4f)5 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 SphereShape (com.bulletphysics.collision.shapes.SphereShape)4 RigidBody (com.bulletphysics.dynamics.RigidBody)4 HashMap (java.util.HashMap)4 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)3 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)3