Search in sources :

Example 16 with CollisionShape

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

the class GImpactShapeInterface method setMargin.

@Override
public void setMargin(float margin) {
    collisionMargin = margin;
    int i = getNumChildShapes();
    while ((i--) != 0) {
        CollisionShape child = getChildShape(i);
        child.setMargin(margin);
    }
    needs_update = true;
}
Also used : CollisionShape(com.bulletphysics.collision.shapes.CollisionShape)

Example 17 with CollisionShape

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

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