Search in sources :

Example 11 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 12 with CollisionShape

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

the class PhysicsTestHelper method createPhysicsTestNode.

/**
     * creates an empty node with a RigidBodyControl
     * @param manager
     * @param shape
     * @param mass
     * @return
     */
public static Node createPhysicsTestNode(AssetManager manager, CollisionShape shape, float mass) {
    Node node = new Node("PhysicsNode");
    RigidBodyControl control = new RigidBodyControl(shape, mass);
    node.addControl(control);
    return node;
}
Also used : Node(com.jme3.scene.Node) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 13 with CollisionShape

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

the class TestHoveringTank method buildPlayer.

private void buildPlayer() {
    spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
    CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft);
    spaceCraft.setShadowMode(ShadowMode.CastAndReceive);
    spaceCraft.setLocalTranslation(new Vector3f(-140, 50, -23));
    spaceCraft.setLocalRotation(new Quaternion(new float[] { 0, 0.01f, 0 }));
    hoverControl = new PhysicsHoverControl(colShape, 500);
    spaceCraft.addControl(hoverControl);
    rootNode.attachChild(spaceCraft);
    getPhysicsSpace().add(hoverControl);
    hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
    spaceCraft.addControl(chaseCam);
    flyCam.setEnabled(false);
}
Also used : BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) ChaseCamera(com.jme3.input.ChaseCamera)

Example 14 with CollisionShape

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

the class TestGhostObject method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    // Mesh to be shared across several boxes.
    Box boxGeom = new Box(1f, 1f, 1f);
    // CollisionShape to be shared across several boxes.
    CollisionShape shape = new BoxCollisionShape(new Vector3f(1, 1, 1));
    Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox.setName("box0");
    physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
    rootNode.attachChild(physicsBox);
    getPhysicsSpace().add(physicsBox);
    Node physicsBox1 = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox1.setName("box1");
    physicsBox1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0, 40, 0));
    rootNode.attachChild(physicsBox1);
    getPhysicsSpace().add(physicsBox1);
    Node physicsBox2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
    physicsBox2.setName("box0");
    physicsBox2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.5f, 80, -.8f));
    rootNode.attachChild(physicsBox2);
    getPhysicsSpace().add(physicsBox2);
    // the floor, does not move (mass=0)
    Node node = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(100, 1, 100)), 0);
    node.setName("floor");
    node.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node);
    getPhysicsSpace().add(node);
    initGhostObject();
}
Also used : BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 15 with CollisionShape

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

the class BetterCharacterControl method getShape.

/**
     * Gets a new collision shape based on the current scale parameter. The
     * created collisionshape is a capsule collision shape that is attached to a
     * compound collision shape with an offset to set the object center at the
     * bottom of the capsule.
     *
     * @return
     */
protected CollisionShape getShape() {
    //TODO: cleanup size mess..
    CapsuleCollisionShape capsuleCollisionShape = new CapsuleCollisionShape(getFinalRadius(), (getFinalHeight() - (2 * getFinalRadius())));
    CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape();
    Vector3f addLocation = new Vector3f(0, (getFinalHeight() / 2.0f), 0);
    compoundCollisionShape.addChildShape(capsuleCollisionShape, addLocation);
    return compoundCollisionShape;
}
Also used : CompoundCollisionShape(com.jme3.bullet.collision.shapes.CompoundCollisionShape) Vector3f(com.jme3.math.Vector3f) CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape)

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