Search in sources :

Example 31 with BulletAppState

use of com.jme3.bullet.BulletAppState in project jmonkeyengine by jMonkeyEngine.

the class TestCollisionListener method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());
    // add ourselves as collision listener
    getPhysicsSpace().addCollisionListener(this);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) BulletAppState(com.jme3.bullet.BulletAppState)

Example 32 with BulletAppState

use of com.jme3.bullet.BulletAppState in project jmonkeyengine by jMonkeyEngine.

the class TestCollisionShapeFactory method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    createMaterial();
    Node node = new Node("node1");
    attachRandomGeometry(node, mat1);
    randomizeTransform(node);
    Node node2 = new Node("node2");
    attachRandomGeometry(node2, mat2);
    randomizeTransform(node2);
    node.attachChild(node2);
    rootNode.attachChild(node);
    RigidBodyControl control = new RigidBodyControl(0);
    node.addControl(control);
    getPhysicsSpace().add(control);
    //test single geometry too
    Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1));
    myGeom.setMaterial(mat3);
    randomizeTransform(myGeom);
    rootNode.attachChild(myGeom);
    RigidBodyControl control3 = new RigidBodyControl(0);
    myGeom.addControl(control3);
    getPhysicsSpace().add(control3);
}
Also used : Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) BulletAppState(com.jme3.bullet.BulletAppState) Node(com.jme3.scene.Node) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 33 with BulletAppState

use of com.jme3.bullet.BulletAppState in project jmonkeyengine by jMonkeyEngine.

the class TestFancyCar method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    //        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    if (settings.getRenderer().startsWith("LWJGL")) {
        BasicShadowRenderer bsr = new BasicShadowRenderer(assetManager, 512);
        bsr.setDirection(new Vector3f(-0.5f, -0.3f, -0.3f).normalizeLocal());
    //   viewPort.addProcessor(bsr);
    }
    cam.setFrustumFar(150f);
    flyCam.setMoveSpeed(10);
    setupKeys();
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    //        setupFloor();
    buildPlayer();
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.5f, -1f, -0.3f).normalizeLocal());
    rootNode.addLight(dl);
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(0.5f, -0.1f, 0.3f).normalizeLocal());
//   rootNode.addLight(dl);
}
Also used : BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) BasicShadowRenderer(com.jme3.shadow.BasicShadowRenderer)

Example 34 with BulletAppState

use of com.jme3.bullet.BulletAppState 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 35 with BulletAppState

use of com.jme3.bullet.BulletAppState in project jmonkeyengine by jMonkeyEngine.

the class TestPhysicsCharacter method simpleInitApp.

@Override
public void simpleInitApp() {
    // activate physics
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    // init a physical test scene
    PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    setupKeys();
    // Add a physics character to the world
    physicsCharacter = new CharacterControl(new CapsuleCollisionShape(0.5f, 1.8f), .1f);
    physicsCharacter.setPhysicsLocation(new Vector3f(0, 1, 0));
    characterNode = new Node("character node");
    Spatial model = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
    model.scale(0.25f);
    characterNode.addControl(physicsCharacter);
    getPhysicsSpace().add(physicsCharacter);
    rootNode.attachChild(characterNode);
    characterNode.attachChild(model);
    // set forward camera node that follows the character
    camNode = new CameraNode("CamNode", cam);
    camNode.setControlDir(ControlDirection.SpatialToCamera);
    camNode.setLocalTranslation(new Vector3f(0, 1, -5));
    camNode.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y);
    characterNode.attachChild(camNode);
    //disable the default 1st-person flyCam (don't forget this!!)
    flyCam.setEnabled(false);
}
Also used : CharacterControl(com.jme3.bullet.control.CharacterControl) Spatial(com.jme3.scene.Spatial) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) CameraNode(com.jme3.scene.CameraNode) CameraNode(com.jme3.scene.CameraNode) CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape)

Aggregations

BulletAppState (com.jme3.bullet.BulletAppState)34 Vector3f (com.jme3.math.Vector3f)25 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)20 Node (com.jme3.scene.Node)14 Sphere (com.jme3.scene.shape.Sphere)13 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)11 CapsuleCollisionShape (com.jme3.bullet.collision.shapes.CapsuleCollisionShape)8 DirectionalLight (com.jme3.light.DirectionalLight)8 Material (com.jme3.material.Material)8 Box (com.jme3.scene.shape.Box)8 CharacterControl (com.jme3.bullet.control.CharacterControl)7 ColorRGBA (com.jme3.math.ColorRGBA)7 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)6 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)6 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)5 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)5 ScreenshotAppState (com.jme3.app.state.ScreenshotAppState)4 HeightfieldCollisionShape (com.jme3.bullet.collision.shapes.HeightfieldCollisionShape)4 Plane (com.jme3.math.Plane)4 Geometry (com.jme3.scene.Geometry)4