Search in sources :

Example 6 with CollisionShape

use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.

the class TestPhysicsRayCast method simpleInitApp.

@Override
public void simpleInitApp() {
    stateManager.attach(bulletAppState);
    initCrossHair();
    Spatial s = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
    s.setLocalScale(0.1f);
    CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(s);
    Node n = new Node("elephant");
    n.addControl(new RigidBodyControl(collisionShape, 1));
    n.getControl(RigidBodyControl.class).setKinematic(true);
    bulletAppState.getPhysicsSpace().add(n);
    rootNode.attachChild(n);
    bulletAppState.setDebugEnabled(true);
}
Also used : CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 7 with CollisionShape

use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.

the class ChildCollisionShape method read.

public void read(JmeImporter im) throws IOException {
    InputCapsule capsule = im.getCapsule(this);
    location = (Vector3f) capsule.readSavable("location", new Vector3f());
    rotation = (Matrix3f) capsule.readSavable("rotation", new Matrix3f());
    shape = (CollisionShape) capsule.readSavable("shape", new BoxCollisionShape(new Vector3f(1, 1, 1)));
}
Also used : Matrix3f(com.jme3.math.Matrix3f) Vector3f(com.jme3.math.Vector3f) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape)

Example 8 with CollisionShape

use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.

the class CompoundCollisionShape method addChildShape.

/**
     * adds a child shape at the given local translation
     * @param shape the child shape to add
     * @param location the local location of the child shape
     */
public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rotation) {
    if (shape instanceof CompoundCollisionShape) {
        throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!");
    }
    Transform transA = new Transform(Converter.convert(rotation));
    Converter.convert(location, transA.origin);
    Converter.convert(rotation, transA.basis);
    children.add(new ChildCollisionShape(location.clone(), rotation.clone(), shape));
    ((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
Also used : ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) CompoundShape(com.bulletphysics.collision.shapes.CompoundShape) Transform(com.bulletphysics.linearmath.Transform)

Example 9 with CollisionShape

use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.

the class TestFancyCar method buildPlayer.

private void buildPlayer() {
    //200=f1 car
    float stiffness = 120.0f;
    //(lower than damp!)
    float compValue = 0.2f;
    float dampValue = 0.3f;
    final float mass = 400;
    //Load model and get chassis Geometry
    carNode = (Node) assetManager.loadModel("Models/Ferrari/Car.scene");
    carNode.setShadowMode(ShadowMode.Cast);
    Geometry chasis = findGeom(carNode, "Car");
    BoundingBox box = (BoundingBox) chasis.getModelBound();
    //Create a hull collision shape for the chassis
    CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(chasis);
    //Create a vehicle control
    player = new VehicleControl(carHull, mass);
    carNode.addControl(player);
    //Setting default values for wheels
    player.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
    player.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
    player.setSuspensionStiffness(stiffness);
    player.setMaxSuspensionForce(10000);
    //Create four wheels and add them at their locations
    //note that our fancy car actually goes backwards..
    Vector3f wheelDirection = new Vector3f(0, -1, 0);
    Vector3f wheelAxle = new Vector3f(-1, 0, 0);
    Geometry wheel_fr = findGeom(carNode, "WheelFrontRight");
    wheel_fr.center();
    box = (BoundingBox) wheel_fr.getModelBound();
    wheelRadius = box.getYExtent();
    float back_wheel_h = (wheelRadius * 1.7f) - 1f;
    float front_wheel_h = (wheelRadius * 1.9f) - 1f;
    player.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
    Geometry wheel_fl = findGeom(carNode, "WheelFrontLeft");
    wheel_fl.center();
    box = (BoundingBox) wheel_fl.getModelBound();
    player.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
    Geometry wheel_br = findGeom(carNode, "WheelBackRight");
    wheel_br.center();
    box = (BoundingBox) wheel_br.getModelBound();
    player.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
    Geometry wheel_bl = findGeom(carNode, "WheelBackLeft");
    wheel_bl.center();
    box = (BoundingBox) wheel_bl.getModelBound();
    player.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
    player.getWheel(2).setFrictionSlip(4);
    player.getWheel(3).setFrictionSlip(4);
    rootNode.attachChild(carNode);
    getPhysicsSpace().add(player);
}
Also used : Geometry(com.jme3.scene.Geometry) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) VehicleControl(com.jme3.bullet.control.VehicleControl)

Example 10 with CollisionShape

use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.

the class BufferedTriangleCallback method getDebugShape.

/**
     * Creates a debug shape from the given collision shape. This is mostly used internally.<br>
     * To attach a debug shape to a physics object, call <code>attachDebugShape(AssetManager manager);</code> on it.
     * @param collisionShape
     * @return
     */
public static Spatial getDebugShape(CollisionShape collisionShape) {
    if (collisionShape == null) {
        return null;
    }
    Spatial debugShape;
    if (collisionShape instanceof CompoundCollisionShape) {
        CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape;
        List<ChildCollisionShape> children = shape.getChildren();
        Node node = new Node("DebugShapeNode");
        for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext(); ) {
            ChildCollisionShape childCollisionShape = it.next();
            CollisionShape ccollisionShape = childCollisionShape.shape;
            Geometry geometry = createDebugShape(ccollisionShape);
            // apply translation
            geometry.setLocalTranslation(childCollisionShape.location);
            // apply rotation
            TempVars vars = TempVars.get();
            Matrix3f tempRot = vars.tempMat3;
            tempRot.set(geometry.getLocalRotation());
            childCollisionShape.rotation.mult(tempRot, tempRot);
            geometry.setLocalRotation(tempRot);
            vars.release();
            node.attachChild(geometry);
        }
        debugShape = node;
    } else {
        debugShape = createDebugShape(collisionShape);
    }
    if (debugShape == null) {
        return null;
    }
    debugShape.updateGeometricState();
    return debugShape;
}
Also used : Geometry(com.jme3.scene.Geometry) CompoundCollisionShape(com.jme3.bullet.collision.shapes.CompoundCollisionShape) ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) CompoundCollisionShape(com.jme3.bullet.collision.shapes.CompoundCollisionShape) Spatial(com.jme3.scene.Spatial) Matrix3f(com.jme3.math.Matrix3f) Node(com.jme3.scene.Node) ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) TempVars(com.jme3.util.TempVars)

Aggregations

CollisionShape (com.jme3.bullet.collision.shapes.CollisionShape)8 Vector3f (com.jme3.math.Vector3f)7 ChildCollisionShape (com.jme3.bullet.collision.shapes.infos.ChildCollisionShape)6 Geometry (com.jme3.scene.Geometry)6 Node (com.jme3.scene.Node)6 Matrix3f (com.jme3.math.Matrix3f)5 BoxCollisionShape (com.jme3.bullet.collision.shapes.BoxCollisionShape)4 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)4 Spatial (com.jme3.scene.Spatial)4 CompoundCollisionShape (com.jme3.bullet.collision.shapes.CompoundCollisionShape)3 Mesh (com.jme3.scene.Mesh)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)2 Transform (com.bulletphysics.linearmath.Transform)2 BulletAppState (com.jme3.bullet.BulletAppState)2 CapsuleCollisionShape (com.jme3.bullet.collision.shapes.CapsuleCollisionShape)2 VehicleWheel (com.jme3.bullet.objects.VehicleWheel)2 Transform (com.jme3.math.Transform)2 Box (com.jme3.scene.shape.Box)2 TempVars (com.jme3.util.TempVars)2 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)1