Search in sources :

Example 31 with ActionListener

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

the class TestCameraMotionPath method initInputs.

private void initInputs() {
    inputManager.addMapping("display_hidePath", new KeyTrigger(KeyInput.KEY_P));
    inputManager.addMapping("SwitchPathInterpolation", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("tensionUp", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("tensionDown", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("play_stop", new KeyTrigger(KeyInput.KEY_SPACE));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("display_hidePath") && keyPressed) {
                if (active) {
                    active = false;
                    path.disableDebugShape();
                } else {
                    active = true;
                    path.enableDebugShape(assetManager, rootNode);
                }
            }
            if (name.equals("play_stop") && keyPressed) {
                if (playing) {
                    playing = false;
                    cameraMotionControl.stop();
                    chaser.setEnabled(true);
                    camNode.setEnabled(false);
                } else {
                    playing = true;
                    chaser.setEnabled(false);
                    camNode.setEnabled(true);
                    cameraMotionControl.play();
                }
            }
            if (name.equals("SwitchPathInterpolation") && keyPressed) {
                if (path.getPathSplineType() == SplineType.CatmullRom) {
                    path.setPathSplineType(SplineType.Linear);
                } else {
                    path.setPathSplineType(SplineType.CatmullRom);
                }
            }
            if (name.equals("tensionUp") && keyPressed) {
                path.setCurveTension(path.getCurveTension() + 0.1f);
                System.err.println("Tension : " + path.getCurveTension());
            }
            if (name.equals("tensionDown") && keyPressed) {
                path.setCurveTension(path.getCurveTension() - 0.1f);
                System.err.println("Tension : " + path.getCurveTension());
            }
        }
    };
    inputManager.addListener(acl, "display_hidePath", "play_stop", "SwitchPathInterpolation", "tensionUp", "tensionDown");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 32 with ActionListener

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

the class TestJaime method setupInput.

public void setupInput() {
    inputManager.addMapping("start", new KeyTrigger(KeyInput.KEY_PAUSE));
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("start") && isPressed) {
                if (cinematic.getPlayState() != PlayState.Playing) {
                    cinematic.play();
                } else {
                    cinematic.pause();
                }
            }
        }
    }, "start");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 33 with ActionListener

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

the class TestMotionPath method initInputs.

private void initInputs() {
    inputManager.addMapping("display_hidePath", new KeyTrigger(KeyInput.KEY_P));
    inputManager.addMapping("SwitchPathInterpolation", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("tensionUp", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("tensionDown", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("play_stop", new KeyTrigger(KeyInput.KEY_SPACE));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("display_hidePath") && keyPressed) {
                if (active) {
                    active = false;
                    path.disableDebugShape();
                } else {
                    active = true;
                    path.enableDebugShape(assetManager, rootNode);
                }
            }
            if (name.equals("play_stop") && keyPressed) {
                if (playing) {
                    playing = false;
                    motionControl.stop();
                } else {
                    playing = true;
                    motionControl.play();
                }
            }
            if (name.equals("SwitchPathInterpolation") && keyPressed) {
                if (path.getPathSplineType() == SplineType.CatmullRom) {
                    path.setPathSplineType(SplineType.Linear);
                } else {
                    path.setPathSplineType(SplineType.CatmullRom);
                }
            }
            if (name.equals("tensionUp") && keyPressed) {
                path.setCurveTension(path.getCurveTension() + 0.1f);
                System.err.println("Tension : " + path.getCurveTension());
            }
            if (name.equals("tensionDown") && keyPressed) {
                path.setCurveTension(path.getCurveTension() - 0.1f);
                System.err.println("Tension : " + path.getCurveTension());
            }
        }
    };
    inputManager.addListener(acl, "display_hidePath", "play_stop", "SwitchPathInterpolation", "tensionUp", "tensionDown");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 34 with ActionListener

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

the class TestSoftParticles method simpleInitApp.

@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(-7.2221026f, 4.1183004f, 7.759811f));
    cam.setRotation(new Quaternion(0.06152846f, 0.91236454f, -0.1492115f, 0.37621948f));
    flyCam.setMoveSpeed(10);
    // -------- floor
    Box b = new Box(10, 0.1f, 10);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Gray);
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
    Box b2 = new Box(1, 1, 1);
    Geometry geom2 = new Geometry("Box", b2);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setColor("Color", ColorRGBA.DarkGray);
    geom2.setMaterial(mat2);
    rootNode.attachChild(geom2);
    geom2.setLocalScale(0.1f, 0.2f, 1);
    fpp = new FilterPostProcessor(assetManager);
    tbf = new TranslucentBucketFilter(true);
    fpp.addFilter(tbf);
    int samples = context.getSettings().getSamples();
    if (samples > 0) {
        fpp.setNumSamples(samples);
    }
    viewPort.addProcessor(fpp);
    particleNode = new Node("particleNode");
    rootNode.attachChild(particleNode);
    createParticles();
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed && name.equals("toggle")) {
                //     tbf.setEnabled(!tbf.isEnabled());     
                softParticles = !softParticles;
                if (softParticles) {
                    viewPort.addProcessor(fpp);
                } else {
                    viewPort.removeProcessor(fpp);
                }
            }
        }
    }, "toggle");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    // emit again
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed && name.equals("refire")) {
                //fpp.removeFilter(tbf); // <-- add back in to fix
                particleNode.detachAllChildren();
                createParticles();
            //fpp.addFilter(tbf);
            }
        }
    }, "refire");
    inputManager.addMapping("refire", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
}
Also used : TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Vector3f(com.jme3.math.Vector3f) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Example 35 with ActionListener

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

the class HelloAudio method initKeys.

/** Declaring "Shoot" action, mapping it to a trigger (mouse left click). */
private void initKeys() {
    inputManager.addMapping("Shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "Shoot");
}
Also used : MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)48 ActionListener (com.jme3.input.controls.ActionListener)39 Vector3f (com.jme3.math.Vector3f)21 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)14 DirectionalLight (com.jme3.light.DirectionalLight)14 Geometry (com.jme3.scene.Geometry)13 Material (com.jme3.material.Material)12 Spatial (com.jme3.scene.Spatial)10 Sphere (com.jme3.scene.shape.Sphere)10 Quaternion (com.jme3.math.Quaternion)9 FilterPostProcessor (com.jme3.post.FilterPostProcessor)9 Node (com.jme3.scene.Node)8 Box (com.jme3.scene.shape.Box)8 AnalogListener (com.jme3.input.controls.AnalogListener)7 AmbientLight (com.jme3.light.AmbientLight)7 BitmapText (com.jme3.font.BitmapText)5 BulletAppState (com.jme3.bullet.BulletAppState)4 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)4 Vector2f (com.jme3.math.Vector2f)4 ParticleEmitter (com.jme3.effect.ParticleEmitter)3