Search in sources :

Example 21 with BulletAppState

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

the class TerrainTestCollision method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);
    setupKeys();
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
    matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex1", grass);
    matRock.setFloat("Tex1Scale", 64f);
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex2", dirt);
    matRock.setFloat("Tex2Scale", 32f);
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex3", rock);
    matRock.setFloat("Tex3Scale", 128f);
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
        heightmap.load();
    } catch (Exception e) {
    }
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
    // patch size, and a multiplier
    control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalScale(new Vector3f(2, 2, 2));
    // unlock it so we can edit the height
    terrain.setLocked(false);
    rootNode.attachChild(terrain);
    /**
         * Create PhysicsRigidBodyControl for collision
         */
    terrain.addControl(new RigidBodyControl(0));
    bulletAppState.getPhysicsSpace().addAll(terrain);
    // let them drop from the sky
    for (int i = 0; i < 5; i++) {
        float r = (float) (8 * Math.random());
        Geometry sphere = new Geometry("cannonball", new Sphere(10, 10, r));
        sphere.setMaterial(matWire);
        // random position
        float x = (float) (20 * Math.random()) - 40;
        // random position
        float y = (float) (20 * Math.random()) - 40;
        // random position
        float z = (float) (20 * Math.random()) - 40;
        sphere.setLocalTranslation(new Vector3f(x, 100 + y, z));
        sphere.addControl(new RigidBodyControl(new SphereCollisionShape(r), 2));
        rootNode.attachChild(sphere);
        bulletAppState.getPhysicsSpace().add(sphere);
    }
    collisionBox = new Geometry("collisionBox", new Box(2, 2, 2));
    collisionBox.setModelBound(new BoundingBox());
    collisionBox.setLocalTranslation(new Vector3f(20, 95, 30));
    collisionBox.setMaterial(matWire);
    rootNode.attachChild(collisionBox);
    selectedCollisionObject = collisionBox;
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
    rootNode.addLight(dl);
    cam.setLocation(new Vector3f(0, 25, -10));
    cam.lookAtDirection(new Vector3f(0, -1, 0).normalizeLocal(), Vector3f.UNIT_Y);
}
Also used : SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Material(com.jme3.material.Material) BoundingBox(com.jme3.bounding.BoundingBox) Box(com.jme3.scene.shape.Box) Texture(com.jme3.texture.Texture) DistanceLodCalculator(com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) ColorRGBA(com.jme3.math.ColorRGBA) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) DirectionalLight(com.jme3.light.DirectionalLight) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad)

Example 22 with BulletAppState

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

the class TestBatchNodeTower method simpleInitApp.

@Override
public void simpleInitApp() {
    timer = new NanoTimer();
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    //   bulletAppState.setEnabled(false);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);
    brick = new Box(brickWidth, brickHeight, brickDepth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    initMaterial();
    initTower();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 25f, 8f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(80);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    rootNode.setShadowMode(ShadowMode.Off);
    batchNode.batch();
    batchNode.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(batchNode);
    shadowRenderer = new DirectionalLightShadowFilter(assetManager, 1024, 2);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    shadowRenderer.setLight(dl);
    shadowRenderer.setLambda(0.55f);
    shadowRenderer.setShadowIntensity(0.6f);
    shadowRenderer.setShadowCompareMode(CompareMode.Hardware);
    shadowRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(shadowRenderer);
    viewPort.addProcessor(fpp);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) NanoTimer(com.jme3.system.NanoTimer) Vector2f(com.jme3.math.Vector2f) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Box(com.jme3.scene.shape.Box) FilterPostProcessor(com.jme3.post.FilterPostProcessor) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter)

Example 23 with BulletAppState

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

the class TestAttachDriver method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    setupKeys();
    setupFloor();
    buildPlayer();
}
Also used : BulletAppState(com.jme3.bullet.BulletAppState)

Example 24 with BulletAppState

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

the class TestAttachGhostObject method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    setupKeys();
    setupJoint();
}
Also used : BulletAppState(com.jme3.bullet.BulletAppState)

Example 25 with BulletAppState

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

the class TestBetterCharacter method simpleInitApp.

@Override
public void simpleInitApp() {
    //setup keyboard mapping
    setupKeys();
    // activate physics
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    // init a physics test scene
    PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());
    setupPlanet();
    // Create a node for the character model
    characterNode = new Node("character node");
    characterNode.setLocalTranslation(new Vector3f(4, 5, 2));
    // Add a character control to the node so we can add other things and
    // control the model rotation
    physicsCharacter = new BetterCharacterControl(0.3f, 2.5f, 8f);
    characterNode.addControl(physicsCharacter);
    getPhysicsSpace().add(physicsCharacter);
    // Load model, attach to character node
    Node model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o");
    model.setLocalScale(1.50f);
    characterNode.attachChild(model);
    // Add character node to the rootNode
    rootNode.attachChild(characterNode);
    // Set forward camera node that follows the character, only used when
    // view is "locked"
    camNode = new CameraNode("CamNode", cam);
    camNode.setControlDir(ControlDirection.SpatialToCamera);
    camNode.setLocalTranslation(new Vector3f(0, 2, -6));
    Quaternion quat = new Quaternion();
    // These coordinates are local, the camNode is attached to the character node!
    quat.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
    camNode.setLocalRotation(quat);
    characterNode.attachChild(camNode);
    // Disable by default, can be enabled via keyboard shortcut
    camNode.setEnabled(false);
}
Also used : Quaternion(com.jme3.math.Quaternion) BulletAppState(com.jme3.bullet.BulletAppState) Node(com.jme3.scene.Node) CameraNode(com.jme3.scene.CameraNode) Vector3f(com.jme3.math.Vector3f) CameraNode(com.jme3.scene.CameraNode) BetterCharacterControl(com.jme3.bullet.control.BetterCharacterControl)

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