Search in sources :

Example 51 with ActionListener

use of com.jme3.input.controls.ActionListener 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)

Example 52 with ActionListener

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

the class HelloInput method initKeys.

/** Custom Keybinding: Map named actions to inputs. */
private void initKeys() {
    /** You can map one or several inputs to one named mapping. */
    inputManager.addMapping("Pause", new KeyTrigger(keyInput.KEY_P));
    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_K));
    // spacebar!
    inputManager.addMapping(// spacebar!
    "Rotate", // spacebar!
    new KeyTrigger(KeyInput.KEY_SPACE), // left click!
    new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    /** Add the named mappings to the action listeners. */
    inputManager.addListener(actionListener, "Pause");
    inputManager.addListener(analogListener, "Left", "Right", "Rotate");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Example 53 with ActionListener

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

the class TestFog method initInputs.

private void initInputs() {
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("DensityUp", new KeyTrigger(KeyInput.KEY_Y));
    inputManager.addMapping("DensityDown", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("DistanceUp", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("DistanceDown", new KeyTrigger(KeyInput.KEY_J));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                if (enabled) {
                    enabled = false;
                    viewPort.removeProcessor(fpp);
                } else {
                    enabled = true;
                    viewPort.addProcessor(fpp);
                }
            }
        }
    };
    AnalogListener anl = new AnalogListener() {

        public void onAnalog(String name, float isPressed, float tpf) {
            if (name.equals("DensityUp")) {
                fog.setFogDensity(fog.getFogDensity() + 0.001f);
                System.out.println("Fog density : " + fog.getFogDensity());
            }
            if (name.equals("DensityDown")) {
                fog.setFogDensity(fog.getFogDensity() - 0.010f);
                System.out.println("Fog density : " + fog.getFogDensity());
            }
            if (name.equals("DistanceUp")) {
                fog.setFogDistance(fog.getFogDistance() + 0.5f);
                System.out.println("Fog Distance : " + fog.getFogDistance());
            }
            if (name.equals("DistanceDown")) {
                fog.setFogDistance(fog.getFogDistance() - 0.5f);
                System.out.println("Fog Distance : " + fog.getFogDistance());
            }
        }
    };
    inputManager.addListener(acl, "toggle");
    inputManager.addListener(anl, "DensityUp", "DensityDown", "DistanceUp", "DistanceDown");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 54 with ActionListener

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

the class SSAOUI method init.

private void init(InputManager inputManager) {
    System.out.println("----------------- SSAO UI Debugger --------------------");
    System.out.println("-- Sample Radius : press Y to increase, H to decrease");
    System.out.println("-- AO Intensity : press U to increase, J to decrease");
    System.out.println("-- AO scale : press I to increase, K to decrease");
    System.out.println("-- AO bias : press O to increase, P to decrease");
    System.out.println("-- Toggle AO on/off : press space bar");
    System.out.println("-- Use only AO : press Num pad 0");
    System.out.println("-- Output config declaration : press P");
    System.out.println("-------------------------------------------------------");
    inputManager.addMapping("sampleRadiusUp", new KeyTrigger(KeyInput.KEY_Y));
    inputManager.addMapping("sampleRadiusDown", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("intensityUp", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("intensityDown", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("scaleUp", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("scaleDown", new KeyTrigger(KeyInput.KEY_K));
    inputManager.addMapping("biasUp", new KeyTrigger(KeyInput.KEY_O));
    inputManager.addMapping("biasDown", new KeyTrigger(KeyInput.KEY_L));
    inputManager.addMapping("outputConfig", new KeyTrigger(KeyInput.KEY_P));
    inputManager.addMapping("toggleUseAO", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("toggleUseOnlyAo", new KeyTrigger(KeyInput.KEY_NUMPAD0));
    inputManager.addMapping("toggleApprox", new KeyTrigger(KeyInput.KEY_NUMPAD5));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggleUseAO") && keyPressed) {
                filter.setEnabled(!filter.isEnabled());
                // filter.setUseAo(!filter.isUseAo());
                System.out.println("use AO : " + filter.isEnabled());
            }
            if (name.equals("toggleApprox") && keyPressed) {
                filter.setApproximateNormals(!filter.isApproximateNormals());
                System.out.println("Approximate Normals : " + filter.isApproximateNormals());
            }
            if (name.equals("toggleUseOnlyAo") && keyPressed) {
                filter.setUseOnlyAo(!filter.isUseOnlyAo());
                System.out.println("use Only AO : " + filter.isUseOnlyAo());
            }
            if (name.equals("outputConfig") && keyPressed) {
                System.out.println("new SSAOFilter(" + filter.getSampleRadius() + "f," + filter.getIntensity() + "f," + filter.getScale() + "f," + filter.getBias() + "f);");
            }
        }
    };
    AnalogListener anl = new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("sampleRadiusUp")) {
                filter.setSampleRadius(filter.getSampleRadius() + 0.01f);
                System.out.println("Sample Radius : " + filter.getSampleRadius());
            }
            if (name.equals("sampleRadiusDown")) {
                filter.setSampleRadius(filter.getSampleRadius() - 0.01f);
                System.out.println("Sample Radius : " + filter.getSampleRadius());
            }
            if (name.equals("intensityUp")) {
                filter.setIntensity(filter.getIntensity() + 0.01f);
                System.out.println("Intensity : " + filter.getIntensity());
            }
            if (name.equals("intensityDown")) {
                filter.setIntensity(filter.getIntensity() - 0.01f);
                System.out.println("Intensity : " + filter.getIntensity());
            }
            if (name.equals("scaleUp")) {
                filter.setScale(filter.getScale() + 0.01f);
                System.out.println("scale : " + filter.getScale());
            }
            if (name.equals("scaleDown")) {
                filter.setScale(filter.getScale() - 0.01f);
                System.out.println("scale : " + filter.getScale());
            }
            if (name.equals("biasUp")) {
                filter.setBias(filter.getBias() + 0.001f);
                System.out.println("bias : " + filter.getBias());
            }
            if (name.equals("biasDown")) {
                filter.setBias(filter.getBias() - 0.001f);
                System.out.println("bias : " + filter.getBias());
            }
        }
    };
    inputManager.addListener(acl, "toggleUseAO", "toggleApprox", "toggleUseOnlyAo", "outputConfig");
    inputManager.addListener(anl, "sampleRadiusUp", "sampleRadiusDown", "intensityUp", "intensityDown", "scaleUp", "scaleDown", "biasUp", "biasDown");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 55 with ActionListener

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

the class TestBloomAlphaThreshold method initInputs.

private void initInputs() {
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    ActionListener acl = new ActionListener() {

        @Override
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                if (active) {
                    active = false;
                    viewPort.removeProcessor(fpp);
                } else {
                    active = true;
                    viewPort.addProcessor(fpp);
                }
            }
        }
    };
    inputManager.addListener(acl, "toggle");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)50 ActionListener (com.jme3.input.controls.ActionListener)44 Vector3f (com.jme3.math.Vector3f)27 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)18 Geometry (com.jme3.scene.Geometry)16 DirectionalLight (com.jme3.light.DirectionalLight)15 Material (com.jme3.material.Material)14 Spatial (com.jme3.scene.Spatial)13 AnalogListener (com.jme3.input.controls.AnalogListener)11 Quaternion (com.jme3.math.Quaternion)11 FilterPostProcessor (com.jme3.post.FilterPostProcessor)10 Node (com.jme3.scene.Node)10 Sphere (com.jme3.scene.shape.Sphere)10 Box (com.jme3.scene.shape.Box)9 AmbientLight (com.jme3.light.AmbientLight)7 BitmapText (com.jme3.font.BitmapText)6 MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)5 ChaseCamera (com.jme3.input.ChaseCamera)4 ColorRGBA (com.jme3.math.ColorRGBA)4 Vector2f (com.jme3.math.Vector2f)4