Search in sources :

Example 1 with KeyTrigger

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

the class DetailedProfilerState method initialize.

@Override
protected void initialize(Application app) {
    Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f));
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    Geometry darkenStats = new Geometry("StatsDarken", new Quad(PANEL_WIDTH, app.getCamera().getHeight()));
    darkenStats.setMaterial(mat);
    darkenStats.setLocalTranslation(0, -app.getCamera().getHeight(), -1);
    ui.attachChild(darkenStats);
    ui.setLocalTranslation(app.getCamera().getWidth() - PANEL_WIDTH, app.getCamera().getHeight(), 0);
    font = app.getAssetManager().loadFont("Interface/Fonts/Console.fnt");
    bigFont = app.getAssetManager().loadFont("Interface/Fonts/Default.fnt");
    prof.setRenderer(app.getRenderer());
    rootLine = new StatLineView("Frame");
    rootLine.attachTo(ui);
    BitmapText frameLabel = new BitmapText(bigFont);
    frameLabel.setText("Total Frame Time: ");
    ui.attachChild(frameLabel);
    frameLabel.setLocalTranslation(new Vector3f(PANEL_WIDTH / 2 - bigFont.getLineWidth(frameLabel.getText()), -PADDING, 0));
    BitmapText cpuLabel = new BitmapText(bigFont);
    cpuLabel.setText("CPU");
    ui.attachChild(cpuLabel);
    cpuLabel.setLocalTranslation(PANEL_WIDTH / 4 - bigFont.getLineWidth(cpuLabel.getText()) / 2, -PADDING - 30, 0);
    BitmapText gpuLabel = new BitmapText(bigFont);
    gpuLabel.setText("GPU");
    ui.attachChild(gpuLabel);
    gpuLabel.setLocalTranslation(3 * PANEL_WIDTH / 4 - bigFont.getLineWidth(gpuLabel.getText()) / 2, -PADDING - 30, 0);
    frameTimeValue = new BitmapText(bigFont);
    frameCpuTimeValue = new BitmapText(bigFont);
    frameGpuTimeValue = new BitmapText(bigFont);
    selectedField = new BitmapText(font);
    selectedField.setText("Selected: ");
    selectedField.setLocalTranslation(PANEL_WIDTH / 2, -PADDING - 75, 0);
    selectedField.setColor(ColorRGBA.Yellow);
    ui.attachChild(frameTimeValue);
    ui.attachChild(frameCpuTimeValue);
    ui.attachChild(frameGpuTimeValue);
    ui.attachChild(selectedField);
    hideInsignificantField = new BitmapText(font);
    hideInsignificantField.setText("O " + INSIGNIFICANT);
    hideInsignificantField.setLocalTranslation(PADDING, -PADDING - 75, 0);
    ui.attachChild(hideInsignificantField);
    final InputManager inputManager = app.getInputManager();
    if (inputManager != null) {
        inputManager.addMapping(TOGGLE_KEY, new KeyTrigger(KeyInput.KEY_F6));
        inputManager.addMapping(CLICK_KEY, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
        inputManager.addListener(new ActionListener() {

            @Override
            public void onAction(String name, boolean isPressed, float tpf) {
                if (name.equals(TOGGLE_KEY) && isPressed) {
                    setEnabled(!isEnabled());
                }
                if (isEnabled() && name.equals(CLICK_KEY) && isPressed) {
                    handleClick(inputManager.getCursorPosition());
                }
            }
        }, TOGGLE_KEY, CLICK_KEY);
    }
}
Also used : Quad(com.jme3.scene.shape.Quad) Material(com.jme3.material.Material) BitmapText(com.jme3.font.BitmapText)

Example 2 with KeyTrigger

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

the class TestDepthOfField method simpleInitApp.

@Override
public void simpleInitApp() {
    Node mainScene = new Node("Main Scene");
    rootNode.attachChild(mainScene);
    createTerrain(mainScene);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(1.7f));
    mainScene.addLight(sun);
    DirectionalLight l = new DirectionalLight();
    l.setDirection(Vector3f.UNIT_Y.mult(-1));
    l.setColor(ColorRGBA.White.clone().multLocal(0.3f));
    mainScene.addLight(l);
    flyCam.setMoveSpeed(50);
    cam.setFrustumFar(3000);
    cam.setLocation(new Vector3f(-700, 100, 300));
    cam.setRotation(new Quaternion().fromAngles(new float[] { FastMath.PI * 0.06f, FastMath.PI * 0.65f, 0 }));
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    mainScene.attachChild(sky);
    fpp = new FilterPostProcessor(assetManager);
    //     fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    dofFilter = new DepthOfFieldFilter();
    dofFilter.setFocusDistance(0);
    dofFilter.setFocusRange(50);
    dofFilter.setBlurScale(1.4f);
    fpp.addFilter(dofFilter);
    viewPort.addProcessor(fpp);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (name.equals("toggle")) {
                    dofFilter.setEnabled(!dofFilter.isEnabled());
                }
            }
        }
    }, "toggle");
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("blurScaleUp")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() + 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("blurScaleDown")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() - 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("focusRangeUp")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() + 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusRangeDown")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() - 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusDistanceUp")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() + 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
            if (name.equals("focusDistanceDown")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() - 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
        }
    }, "blurScaleUp", "blurScaleDown", "focusRangeUp", "focusRangeDown", "focusDistanceUp", "focusDistanceDown");
    inputManager.addMapping("toggle", new KeyTrigger(keyInput.KEY_SPACE));
    inputManager.addMapping("blurScaleUp", new KeyTrigger(keyInput.KEY_U));
    inputManager.addMapping("blurScaleDown", new KeyTrigger(keyInput.KEY_J));
    inputManager.addMapping("focusRangeUp", new KeyTrigger(keyInput.KEY_I));
    inputManager.addMapping("focusRangeDown", new KeyTrigger(keyInput.KEY_K));
    inputManager.addMapping("focusDistanceUp", new KeyTrigger(keyInput.KEY_O));
    inputManager.addMapping("focusDistanceDown", new KeyTrigger(keyInput.KEY_L));
}
Also used : Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DepthOfFieldFilter(com.jme3.post.filters.DepthOfFieldFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 3 with KeyTrigger

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

the class TestMultiViewsFilters method simpleInitApp.

public void simpleInitApp() {
    // create the geometry and attach it
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teaGeom.scale(3);
    teaGeom.getMaterial().setColor("GlowColor", ColorRGBA.Green);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);
    // Setup first view      
    cam.setViewPort(.5f, 1f, 0f, 0.5f);
    cam.setLocation(new Vector3f(3.3212643f, 4.484704f, 4.2812433f));
    cam.setRotation(new Quaternion(-0.07680723f, 0.92299235f, -0.2564353f, -0.27645364f));
    // Setup second view
    Camera cam2 = cam.clone();
    cam2.setViewPort(0f, 0.5f, 0f, 0.5f);
    cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f));
    cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f));
    final ViewPort view2 = renderManager.createMainView("Bottom Left", cam2);
    view2.setClearFlags(true, true, true);
    view2.attachScene(rootNode);
    // Setup third view
    Camera cam3 = cam.clone();
    cam3.setName("cam3");
    cam3.setViewPort(0f, .5f, .5f, 1f);
    cam3.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f));
    cam3.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f));
    final ViewPort view3 = renderManager.createMainView("Top Left", cam3);
    view3.setClearFlags(true, true, true);
    view3.attachScene(rootNode);
    // Setup fourth view
    Camera cam4 = cam.clone();
    cam4.setName("cam4");
    cam4.setViewPort(.5f, 1f, .5f, 1f);
    cam4.setLocation(new Vector3f(4.775564f, 1.4548365f, 0.11491505f));
    cam4.setRotation(new Quaternion(0.02356979f, -0.74957186f, 0.026729556f, 0.66096294f));
    final ViewPort view4 = renderManager.createMainView("Top Right", cam4);
    view4.setClearFlags(true, true, true);
    view4.attachScene(rootNode);
    //        Camera cam5 = new Camera(200, 200);
    //        cam5.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);
    //        cam5.setName("cam5");
    //        cam5.setViewPort(5.23f, 6.33f, 0.56f, 1.66f);
    //          this.setViewPortAreas(5.23f, 6.33f, 0.56f, 1.66f);
    //          this.setViewPortCamSize(200, 200);
    //          1046,1266,112,332
    Camera cam5 = cam.clone();
    cam5.setName("cam5");
    cam5.setViewPort(1046f / settings.getWidth(), 1266f / settings.getWidth(), 112f / settings.getHeight(), 332f / settings.getHeight());
    cam5.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f));
    cam5.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f));
    final ViewPort view5 = renderManager.createMainView("center", cam5);
    view5.setClearFlags(true, true, true);
    view5.attachScene(rootNode);
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    final FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    final FilterPostProcessor fpp2 = new FilterPostProcessor(assetManager);
    final FilterPostProcessor fpp3 = new FilterPostProcessor(assetManager);
    final FilterPostProcessor fpp4 = new FilterPostProcessor(assetManager);
    final FilterPostProcessor fpp5 = new FilterPostProcessor(assetManager);
    //  fpp.addFilter(new WaterFilter(rootNode, Vector3f.UNIT_Y.mult(-1)));
    fpp3.addFilter(new CartoonEdgeFilter());
    fpp2.addFilter(new CrossHatchFilter());
    final FogFilter ff = new FogFilter(ColorRGBA.Yellow, 0.7f, 2);
    fpp.addFilter(ff);
    final RadialBlurFilter rbf = new RadialBlurFilter(1, 10);
    //    rbf.setEnabled(false);
    fpp.addFilter(rbf);
    SSAOFilter f = new SSAOFilter(1.8899765f, 20.490374f, 0.4699998f, 0.1f);
    ;
    fpp4.addFilter(f);
    SSAOUI ui = new SSAOUI(inputManager, f);
    fpp5.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
    viewPort.addProcessor(fpp);
    view2.addProcessor(fpp2);
    view3.addProcessor(fpp3);
    view4.addProcessor(fpp4);
    view5.addProcessor(fpp5);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("press") && isPressed) {
                if (filterEnabled) {
                    viewPort.removeProcessor(fpp);
                    view2.removeProcessor(fpp2);
                    view3.removeProcessor(fpp3);
                    view4.removeProcessor(fpp4);
                    view5.removeProcessor(fpp5);
                } else {
                    viewPort.addProcessor(fpp);
                    view2.addProcessor(fpp2);
                    view3.addProcessor(fpp3);
                    view4.addProcessor(fpp4);
                    view5.addProcessor(fpp5);
                }
                filterEnabled = !filterEnabled;
            }
            if (name.equals("filter") && isPressed) {
                ff.setEnabled(!ff.isEnabled());
                rbf.setEnabled(!rbf.isEnabled());
            }
        }
    }, "press", "filter");
    inputManager.addMapping("press", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("filter", new KeyTrigger(KeyInput.KEY_F));
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) ViewPort(com.jme3.renderer.ViewPort) Camera(com.jme3.renderer.Camera)

Example 4 with KeyTrigger

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

the class TestMultiplesFilters method simpleInitApp.

public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(6.0344796f, 1.5054002f, 55.572033f));
    cam.setRotation(new Quaternion(0.0016069f, 0.9810479f, -0.008143323f, 0.19358753f));
    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
    }
    Spatial scene = assetManager.loadModel("main.scene");
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f));
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);
    fpp = new FilterPostProcessor(assetManager);
    //  fpp.setNumSamples(4);
    ssaoFilter = new SSAOFilter(0.92f, 2.2f, 0.46f, 0.2f);
    final WaterFilter water = new WaterFilter(rootNode, new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f));
    water.setWaterHeight(-20);
    SSAOUI ui = new SSAOUI(inputManager, ssaoFilter);
    final BloomFilter bloom = new BloomFilter();
    final ColorOverlayFilter overlay = new ColorOverlayFilter(ColorRGBA.LightGray);
    fpp.addFilter(ssaoFilter);
    fpp.addFilter(water);
    fpp.addFilter(bloom);
    fpp.addFilter(overlay);
    viewPort.addProcessor(fpp);
    rootNode.attachChild(scene);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if ("toggleSSAO".equals(name) && isPressed) {
                if (ssaoFilter.isEnabled()) {
                    ssaoFilter.setEnabled(false);
                } else {
                    ssaoFilter.setEnabled(true);
                }
            }
            if ("toggleWater".equals(name) && isPressed) {
                if (water.isEnabled()) {
                    water.setEnabled(false);
                } else {
                    water.setEnabled(true);
                }
            }
            if ("toggleBloom".equals(name) && isPressed) {
                if (bloom.isEnabled()) {
                    bloom.setEnabled(false);
                } else {
                    bloom.setEnabled(true);
                }
            }
            if ("toggleOverlay".equals(name) && isPressed) {
                if (overlay.isEnabled()) {
                    overlay.setEnabled(false);
                } else {
                    overlay.setEnabled(true);
                }
            }
        }
    }, "toggleSSAO", "toggleBloom", "toggleWater", "toggleOverlay");
    inputManager.addMapping("toggleSSAO", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addMapping("toggleWater", new KeyTrigger(KeyInput.KEY_2));
    inputManager.addMapping("toggleBloom", new KeyTrigger(KeyInput.KEY_3));
    inputManager.addMapping("toggleOverlay", new KeyTrigger(KeyInput.KEY_4));
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter) ColorOverlayFilter(com.jme3.post.filters.ColorOverlayFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WaterFilter(com.jme3.water.WaterFilter) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight)

Example 5 with KeyTrigger

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

the class TestPostFilters method initInput.

protected void initInput() {
    flyCam.setMoveSpeed(50);
    //init input
    inputManager.addMapping("fadein", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addListener(this, "fadein");
    inputManager.addMapping("fadeout", new KeyTrigger(KeyInput.KEY_O));
    inputManager.addListener(this, "fadeout");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger)

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