Search in sources :

Example 71 with Transform

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

the class GImpactCollisionAlgorithm method gimpact_vs_shape_find_pairs.

protected void gimpact_vs_shape_find_pairs(Transform trans0, Transform trans1, GImpactShapeInterface shape0, CollisionShape shape1, IntArrayList collided_primitives) {
    Stack stack = Stack.enter();
    AABB boxshape = stack.allocAABB();
    if (shape0.hasBoxSet()) {
        Transform trans1to0 = stack.allocTransform();
        trans1to0.inverse(trans0);
        trans1to0.mul(trans1);
        shape1.getAabb(trans1to0, boxshape.min, boxshape.max);
        shape0.getBoxSet().boxQuery(boxshape, collided_primitives);
    } else {
        shape1.getAabb(trans1, boxshape.min, boxshape.max);
        AABB boxshape0 = stack.allocAABB();
        int i = shape0.getNumChildShapes();
        while ((i--) != 0) {
            shape0.getChildAabb(i, trans0, boxshape0.min, boxshape0.max);
            if (boxshape.has_collision(boxshape0)) {
                collided_primitives.add(i);
            }
        }
    }
    stack.leave();
}
Also used : Transform(com.bulletphysics.linearmath.Transform) AABB(com.bulletphysics.extras.gimpact.BoxCollision.AABB) Stack(com.bulletphysics.util.Stack)

Example 72 with Transform

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

the class GImpactCollisionAlgorithm method gimpact_vs_compoundshape.

public void gimpact_vs_compoundshape(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, CompoundShape shape1, boolean swapped) {
    Stack stack = Stack.enter();
    Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
    Transform childtrans1 = stack.allocTransform();
    Transform tmpTrans = stack.allocTransform();
    int i = shape1.getNumChildShapes();
    while ((i--) != 0) {
        CollisionShape colshape1 = shape1.getChildShape(i);
        childtrans1.mul(orgtrans1, shape1.getChildTransform(i, tmpTrans));
        body1.setWorldTransform(childtrans1);
        // collide child shape
        gimpact_vs_shape(body0, body1, shape0, colshape1, swapped);
        // restore transforms
        body1.setWorldTransform(orgtrans1);
    }
    stack.leave();
}
Also used : CollisionShape(com.bulletphysics.collision.shapes.CollisionShape) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 73 with Transform

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

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(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, GImpactMeshShapePart shape1, PairSet pairs, int pair_count) {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
    Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
    PrimitiveTriangle ptri0 = stack.allocPrimitiveTriangle();
    PrimitiveTriangle ptri1 = stack.allocPrimitiveTriangle();
    TriangleContact contact_data = stack.allocTriangleContact();
    shape0.lockChildShapes();
    shape1.lockChildShapes();
    int pair_pointer = 0;
    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);
        // build 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);
                }
            }
        }
    //#ifdef TRI_COLLISION_PROFILING
    //bt_end_gim02_tri_time();
    //#endif
    }
    shape0.unlockChildShapes();
    shape1.unlockChildShapes();
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 74 with Transform

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

the class GameObject method updateBody.

public void updateBody(Mesh mesh) {
    GameObject compParent = parent != null && parent.body.getCollisionShape().isCompound() ? parent : null;
    boolean isCompChild = compParent != null && !(currBodyType == BodyType.NO_COLLISION || currBodyType == BodyType.SENSOR);
    if (isCompChild) {
        parent(null);
    }
    Matrix4f transform = transform();
    Vector3f scale = scale();
    CollisionShape shape = body.getCollisionShape();
    body.setCollisionShape(Bullet.makeShape(mesh.model.meshes.first(), currBoundsType, shape.getMargin(), shape.isCompound()));
    Transform startTransform = new Transform();
    body.getMotionState().getWorldTransform(startTransform);
    Matrix4f originMatrix = new Matrix4f();
    originMatrix.set(origin);
    Transform centerOfMassTransform = new Transform();
    centerOfMassTransform.set(originMatrix);
    centerOfMassTransform.mul(startTransform);
    body.setCenterOfMassTransform(centerOfMassTransform);
    transform(transform);
    scale(scale);
    if (body.isInWorld()) {
        scene.world.updateSingleAabb(body);
    } else {
        // update Aabb hack for when not in world
        scene.world.addRigidBody(body);
        scene.world.updateSingleAabb(body);
        scene.world.removeRigidBody(body);
    }
    if (isCompChild) {
        parent(compParent);
    }
}
Also used : Matrix4f(javax.vecmath.Matrix4f) CollisionShape(com.bulletphysics.collision.shapes.CollisionShape) Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform)

Example 75 with Transform

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

the class GameObject method position.

public Vector3f position() {
    Transform t = new Transform();
    body.getWorldTransform(t);
    return new Vector3f(t.origin);
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform)

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