Search in sources :

Example 6 with CollisionShape

use of com.bulletphysics.collision.shapes.CollisionShape in project bdx by GoranM.

the class GImpactCollisionAlgorithm method gimpact_vs_shape.

public void gimpact_vs_shape(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, CollisionShape shape1, boolean swapped) {
    if (shape0.getGImpactShapeType() == ShapeType.TRIMESH_SHAPE) {
        GImpactMeshShape meshshape0 = (GImpactMeshShape) shape0;
        part0 = meshshape0.getMeshPartCount();
        while ((part0--) != 0) {
            gimpact_vs_shape(body0, body1, meshshape0.getMeshPart(part0), shape1, swapped);
        }
        return;
    }
    //#ifdef GIMPACT_VS_PLANE_COLLISION
    if (shape0.getGImpactShapeType() == ShapeType.TRIMESH_SHAPE_PART && shape1.getShapeType() == BroadphaseNativeType.STATIC_PLANE_PROXYTYPE) {
        GImpactMeshShapePart shapepart = (GImpactMeshShapePart) shape0;
        StaticPlaneShape planeshape = (StaticPlaneShape) shape1;
        gimpacttrimeshpart_vs_plane_collision(body0, body1, shapepart, planeshape, swapped);
        return;
    }
    if (shape1.isCompound()) {
        CompoundShape compoundshape = (CompoundShape) shape1;
        gimpact_vs_compoundshape(body0, body1, shape0, compoundshape, swapped);
        return;
    } else if (shape1.isConcave()) {
        ConcaveShape concaveshape = (ConcaveShape) shape1;
        gimpact_vs_concave(body0, body1, shape0, concaveshape, swapped);
        return;
    }
    Stack stack = Stack.enter();
    Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
    Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
    IntArrayList collided_results = new IntArrayList();
    gimpact_vs_shape_find_pairs(orgtrans0, orgtrans1, shape0, shape1, collided_results);
    if (collided_results.size() == 0) {
        return;
    }
    shape0.lockChildShapes();
    GIM_ShapeRetriever retriever0 = new GIM_ShapeRetriever(shape0);
    boolean child_has_transform0 = shape0.childrenHasTransform();
    Transform tmpTrans = stack.allocTransform();
    int i = collided_results.size();
    while ((i--) != 0) {
        int child_index = collided_results.get(i);
        if (swapped) {
            triface1 = child_index;
        } else {
            triface0 = child_index;
        }
        CollisionShape colshape0 = retriever0.getChildShape(child_index);
        if (child_has_transform0) {
            tmpTrans.mul(orgtrans0, shape0.getChildTransform(child_index));
            body0.setWorldTransform(tmpTrans);
        }
        // collide two shapes
        if (swapped) {
            shape_vs_shape_collision(body1, body0, shape1, colshape0);
        } else {
            shape_vs_shape_collision(body0, body1, colshape0, shape1);
        }
        // restore transforms
        if (child_has_transform0) {
            body0.setWorldTransform(orgtrans0);
        }
    }
    shape0.unlockChildShapes();
    stack.leave();
}
Also used : CollisionShape(com.bulletphysics.collision.shapes.CollisionShape) ConcaveShape(com.bulletphysics.collision.shapes.ConcaveShape) StaticPlaneShape(com.bulletphysics.collision.shapes.StaticPlaneShape) CompoundShape(com.bulletphysics.collision.shapes.CompoundShape) Transform(com.bulletphysics.linearmath.Transform) IntArrayList(com.bulletphysics.util.IntArrayList) Stack(com.bulletphysics.util.Stack)

Example 7 with CollisionShape

use of com.bulletphysics.collision.shapes.CollisionShape in project bdx by GoranM.

the class GImpactCollisionAlgorithm method convex_vs_convex_collision.

protected void convex_vs_convex_collision(CollisionObject body0, CollisionObject body1, CollisionShape shape0, CollisionShape shape1) {
    CollisionShape tmpShape0 = body0.getCollisionShape();
    CollisionShape tmpShape1 = body1.getCollisionShape();
    body0.internalSetTemporaryCollisionShape(shape0);
    body1.internalSetTemporaryCollisionShape(shape1);
    resultOut.setShapeIdentifiers(part0, triface0, part1, triface1);
    checkConvexAlgorithm(body0, body1);
    convex_algorithm.processCollision(body0, body1, dispatchInfo, resultOut);
    body0.internalSetTemporaryCollisionShape(tmpShape0);
    body1.internalSetTemporaryCollisionShape(tmpShape1);
}
Also used : CollisionShape(com.bulletphysics.collision.shapes.CollisionShape)

Example 8 with CollisionShape

use of com.bulletphysics.collision.shapes.CollisionShape in project bdx by GoranM.

the class GameObject method boundsType.

public void boundsType(BoundsType boundsType) {
    com.badlogic.gdx.graphics.Mesh mesh = modelInstance.model.meshes.first();
    CollisionShape shape = body.getCollisionShape();
    shape = Bullet.makeShape(mesh, boundsType, shape.getMargin(), shape.isCompound());
    body.setCollisionShape(shape);
    currBoundsType = boundsType;
}
Also used : CollisionShape(com.bulletphysics.collision.shapes.CollisionShape)

Example 9 with CollisionShape

use of com.bulletphysics.collision.shapes.CollisionShape in project bdx by GoranM.

the class GameObject method scale.

public void scale(float x, float y, float z, boolean updateLocal) {
    activate();
    // Set unit scale
    Matrix4 t = modelInstance.transform;
    Matrix4 mat_scale = new Matrix4();
    Vector3 s = new Vector3();
    t.getScale(s);
    mat_scale.scl(1 / s.x, 1 / s.y, 1 / s.z);
    t.mul(mat_scale);
    scale.set(x, y, z);
    // Set target scale
    mat_scale.idt();
    mat_scale.scl(x, y, z);
    t.mul(mat_scale);
    // Relevant bullet body update
    CollisionShape cs = body.getCollisionShape();
    cs.setLocalScaling(new Vector3f(x, y, z));
    if (body.isInWorld() && body.isStaticOrKinematicObject())
        scene.world.updateSingleAabb(body);
    // Child propagation
    Vector3f ps = scale();
    Matrix4f pt = transform();
    Matrix4f ct = new Matrix4f();
    Matrix4f ms = new Matrix4f();
    ms.setIdentity();
    ms.m00 = ps.x;
    ms.m11 = ps.y;
    ms.m22 = ps.z;
    pt.mul(ms);
    for (GameObject c : children) {
        c.scale(scale().mul(c.localScale), false);
        ct.mul(pt, c.localTransform);
        c.transform(ct, false);
    }
    if (parent != null && updateLocal) {
        updateLocalScale();
    }
}
Also used : Matrix4f(javax.vecmath.Matrix4f) CollisionShape(com.bulletphysics.collision.shapes.CollisionShape) Vector3f(javax.vecmath.Vector3f) Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 10 with CollisionShape

use of com.bulletphysics.collision.shapes.CollisionShape 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)

Aggregations

CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)17 Transform (com.bulletphysics.linearmath.Transform)11 Stack (com.bulletphysics.util.Stack)10 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)7 Vector3f (javax.vecmath.Vector3f)7 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)3 CollisionAlgorithm (com.bulletphysics.collision.broadphase.CollisionAlgorithm)2 CastResult (com.bulletphysics.collision.narrowphase.ConvexCast.CastResult)2 SubsimplexConvexCast (com.bulletphysics.collision.narrowphase.SubsimplexConvexCast)2 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)2 BvhTriangleMeshShape (com.bulletphysics.collision.shapes.BvhTriangleMeshShape)2 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)2 SphereShape (com.bulletphysics.collision.shapes.SphereShape)2 Matrix4f (javax.vecmath.Matrix4f)2 Matrix4 (com.badlogic.gdx.math.Matrix4)1 Vector3 (com.badlogic.gdx.math.Vector3)1 ConvexCast (com.bulletphysics.collision.narrowphase.ConvexCast)1 GjkConvexCast (com.bulletphysics.collision.narrowphase.GjkConvexCast)1 GjkEpaPenetrationDepthSolver (com.bulletphysics.collision.narrowphase.GjkEpaPenetrationDepthSolver)1 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)1