Search in sources :

Example 71 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestControls method simpleInitApp.

@Override
public void simpleInitApp() {
    // Test multiple inputs per mapping
    inputManager.addMapping("My Action", new KeyTrigger(KeyInput.KEY_SPACE), new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
    // Test multiple listeners per mapping
    inputManager.addListener(actionListener, "My Action");
    inputManager.addListener(analogListener, "My Action");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger)

Example 72 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class HelloTerrainCollision method setUpKeys.

/** We over-write some navigational key mappings here, so we can
   * add physics-controlled walking and jumping: */
private void setUpKeys() {
    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(this, "Left");
    inputManager.addListener(this, "Right");
    inputManager.addListener(this, "Up");
    inputManager.addListener(this, "Down");
    inputManager.addListener(this, "Jump");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 73 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestComboMoves method simpleInitApp.

@Override
public void simpleInitApp() {
    setDisplayFps(false);
    setDisplayStatView(false);
    // Create debug text
    BitmapText helpText = new BitmapText(guiFont);
    helpText.setLocalTranslation(0, settings.getHeight(), 0);
    helpText.setText("Moves:\n" + "Fireball: Down, Down+Right, Right\n" + "Shuriken: Left, Down, Attack1(Z)\n" + "Jab: Attack1(Z)\n" + "Punch: Attack1(Z), Attack1(Z)\n");
    guiNode.attachChild(helpText);
    fireballText = new BitmapText(guiFont);
    fireballText.setColor(ColorRGBA.Orange);
    fireballText.setLocalTranslation(0, fireballText.getLineHeight(), 0);
    guiNode.attachChild(fireballText);
    shurikenText = new BitmapText(guiFont);
    shurikenText.setColor(ColorRGBA.Cyan);
    shurikenText.setLocalTranslation(0, shurikenText.getLineHeight() * 2f, 0);
    guiNode.attachChild(shurikenText);
    jabText = new BitmapText(guiFont);
    jabText.setColor(ColorRGBA.Red);
    jabText.setLocalTranslation(0, jabText.getLineHeight() * 3f, 0);
    guiNode.attachChild(jabText);
    punchText = new BitmapText(guiFont);
    punchText.setColor(ColorRGBA.Green);
    punchText.setLocalTranslation(0, punchText.getLineHeight() * 4f, 0);
    guiNode.attachChild(punchText);
    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Attack1", new KeyTrigger(KeyInput.KEY_Z));
    inputManager.addListener(this, "Left", "Right", "Up", "Down", "Attack1");
    fireball = new ComboMove("Fireball");
    fireball.press("Down").notPress("Right").done();
    fireball.press("Right", "Down").done();
    fireball.press("Right").notPress("Down").done();
    fireball.notPress("Right", "Down").done();
    // no waiting on final state
    fireball.setUseFinalState(false);
    shuriken = new ComboMove("Shuriken");
    shuriken.press("Left").notPress("Down", "Attack1").done();
    shuriken.press("Down").notPress("Attack1").timeElapsed(0.11f).done();
    shuriken.press("Attack1").notPress("Left").timeElapsed(0.11f).done();
    shuriken.notPress("Left", "Down", "Attack1").done();
    jab = new ComboMove("Jab");
    // make jab less important than other moves
    jab.setPriority(0.5f);
    jab.press("Attack1").done();
    punch = new ComboMove("Punch");
    punch.press("Attack1").done();
    punch.notPress("Attack1").done();
    punch.press("Attack1").done();
    fireballExec = new ComboMoveExecution(fireball);
    shurikenExec = new ComboMoveExecution(shuriken);
    jabExec = new ComboMoveExecution(jab);
    punchExec = new ComboMoveExecution(punch);
}
Also used : BitmapText(com.jme3.font.BitmapText) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 74 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class RefEnv method simpleInitApp.

@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(-2.3324413f, 2.9567573f, 4.6054406f));
    cam.setRotation(new Quaternion(0.06310794f, 0.9321281f, -0.29613864f, 0.1986369f));
    Spatial sc = assetManager.loadModel("Scenes/PBR/spheres.j3o");
    rootNode.attachChild(sc);
    rootNode.getChild("Scene").setCullHint(Spatial.CullHint.Always);
    ref = new Node("reference pictures");
    refDE = new Picture("refDE");
    refDE.setHeight(cam.getHeight());
    refDE.setWidth(cam.getWidth());
    refDE.setImage(assetManager, "jme3test/light/pbr/spheresRefDE.png", false);
    refM = new Picture("refM");
    refM.setImage(assetManager, "jme3test/light/pbr/spheresRefM.png", false);
    refM.setHeight(cam.getHeight());
    refM.setWidth(cam.getWidth());
    ref.attachChild(refDE);
    stateManager.attach(new EnvironmentCamera());
    inputManager.addMapping("tex", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("switch", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("ref", new KeyTrigger(KeyInput.KEY_R));
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("tex") && isPressed) {
                if (tex == null) {
                    return;
                }
                if (tex.getParent() == null) {
                    guiNode.attachChild(tex);
                } else {
                    tex.removeFromParent();
                }
            }
            if (name.equals("switch") && isPressed) {
                switchMat(rootNode.getChild("Scene"));
            }
            if (name.equals("ref") && isPressed) {
                if (ref.getParent() == null) {
                    guiNode.attachChild(ref);
                } else {
                    ref.removeFromParent();
                }
            }
        }
    }, "tex", "switch", "ref");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) Quaternion(com.jme3.math.Quaternion) Spatial(com.jme3.scene.Spatial) EnvironmentCamera(com.jme3.environment.EnvironmentCamera) Picture(com.jme3.ui.Picture) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 75 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestPBRLighting method simpleInitApp.

@Override
public void simpleInitApp() {
    assetManager.registerLoader(KTXLoader.class, "ktx");
    viewPort.setBackgroundColor(ColorRGBA.White);
    modelNode = (Node) new Node("modelNode");
    model = (Geometry) assetManager.loadModel("Models/Tank/tank.j3o");
    MikktspaceTangentGenerator.generate(model);
    modelNode.attachChild(model);
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    dl.setColor(ColorRGBA.White);
    rootNode.attachChild(modelNode);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    //        fpp.addFilter(new FXAAFilter());
    fpp.addFilter(new ToneMapFilter(Vector3f.UNIT_XYZ.mult(4.0f)));
    //        fpp.addFilter(new SSAOFilter(0.5f, 3, 0.2f, 0.2f));
    viewPort.addProcessor(fpp);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Sky_Cloudy.hdr", SkyFactory.EnvMapType.EquirectMap);
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", SkyFactory.EnvMapType.CubeMap);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/road.hdr", SkyFactory.EnvMapType.EquirectMap);
    rootNode.attachChild(sky);
    pbrMat = assetManager.loadMaterial("Models/Tank/tank.j3m");
    model.setMaterial(pbrMat);
    final EnvironmentCamera envCam = new EnvironmentCamera(128, new Vector3f(0, 3f, 0));
    stateManager.attach(envCam);
    //        EnvironmentManager envManager = new EnvironmentManager();
    //        stateManager.attach(envManager);
    //       envManager.setScene(rootNode);
    LightsDebugState debugState = new LightsDebugState();
    stateManager.attach(debugState);
    ChaseCamera chaser = new ChaseCamera(cam, modelNode, inputManager);
    chaser.setDragToRotate(true);
    chaser.setMinVerticalRotation(-FastMath.HALF_PI);
    chaser.setMaxDistance(1000);
    chaser.setSmoothMotion(true);
    chaser.setRotationSensitivity(10);
    chaser.setZoomSensitivity(5);
    flyCam.setEnabled(false);
    //flyCam.setMoveSpeed(100);
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("debug") && isPressed) {
                if (tex == null) {
                    return;
                }
                if (tex.getParent() == null && tex2.getParent() == null) {
                    guiNode.attachChild(tex);
                } else if (tex2.getParent() == null) {
                    tex.removeFromParent();
                    guiNode.attachChild(tex2);
                } else {
                    tex2.removeFromParent();
                }
            }
            if (name.equals("up") && isPressed) {
                model.move(0, tpf * 100f, 0);
            }
            if (name.equals("down") && isPressed) {
                model.move(0, -tpf * 100f, 0);
            }
            if (name.equals("left") && isPressed) {
                model.move(0, 0, tpf * 100f);
            }
            if (name.equals("right") && isPressed) {
                model.move(0, 0, -tpf * 100f);
            }
            if (name.equals("light") && isPressed) {
                dl.setDirection(cam.getDirection().normalize());
            }
        }
    }, "toggle", "light", "up", "down", "left", "right", "debug");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("light", new KeyTrigger(KeyInput.KEY_F));
    inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("debug", new KeyTrigger(KeyInput.KEY_D));
    MaterialDebugAppState debug = new MaterialDebugAppState();
    debug.registerBinding("Common/MatDefs/Light/PBRLighting.frag", rootNode);
    getStateManager().attach(debug);
}
Also used : MaterialDebugAppState(com.jme3.util.MaterialDebugAppState) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) ChaseCamera(com.jme3.input.ChaseCamera) FilterPostProcessor(com.jme3.post.FilterPostProcessor) ToneMapFilter(com.jme3.post.filters.ToneMapFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) EnvironmentCamera(com.jme3.environment.EnvironmentCamera) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)93 ActionListener (com.jme3.input.controls.ActionListener)36 Vector3f (com.jme3.math.Vector3f)30 Geometry (com.jme3.scene.Geometry)23 Material (com.jme3.material.Material)22 DirectionalLight (com.jme3.light.DirectionalLight)21 Quaternion (com.jme3.math.Quaternion)18 Spatial (com.jme3.scene.Spatial)13 FilterPostProcessor (com.jme3.post.FilterPostProcessor)11 Box (com.jme3.scene.shape.Box)11 BitmapText (com.jme3.font.BitmapText)10 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)10 Node (com.jme3.scene.Node)10 AnalogListener (com.jme3.input.controls.AnalogListener)9 ColorRGBA (com.jme3.math.ColorRGBA)9 Sphere (com.jme3.scene.shape.Sphere)8 AmbientLight (com.jme3.light.AmbientLight)7 Quad (com.jme3.scene.shape.Quad)6 ChaseCamera (com.jme3.input.ChaseCamera)4 BulletAppState (com.jme3.bullet.BulletAppState)3