159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/*
259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2010 jMonkeyEngine
359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved.
459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without
659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are
759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met:
859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright
1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer.
1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright
1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer in the
1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   documentation and/or other materials provided with the distribution.
1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   may be used to endorse or promote products derived from this software
1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   without specific prior written permission.
1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */
3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage jme3test.post;
3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.InputManager;
3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.KeyInput;
3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.ActionListener;
3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.AnalogListener;
3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.KeyTrigger;
3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.post.ssao.SSAOFilter;
4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/**
4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author nehon
4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */
4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class SSAOUI {
4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    SSAOFilter filter;
4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public SSAOUI(InputManager inputManager, SSAOFilter filter) {
5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        this.filter = filter;
5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        init(inputManager);
5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void init(InputManager inputManager) {
5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        System.out.println("----------------- Water UI Debugger --------------------");
5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        System.out.println("-- Sample Radius : press Y to increase, H to decrease");
5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        System.out.println("-- AO Intensity : press U to increase, J to decrease");
5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        System.out.println("-- AO scale : press I to increase, K to decrease");
5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        System.out.println("-- AO bias : press O to increase, P to decrease");
6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        System.out.println("-- Toggle AO on/off : press space bar");
6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        System.out.println("-- Use only AO : press Num pad 0");
6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        System.out.println("-- Output config declaration : press P");
6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        System.out.println("-------------------------------------------------------");
6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("sampleRadiusUp", new KeyTrigger(KeyInput.KEY_Y));
6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("sampleRadiusDown", new KeyTrigger(KeyInput.KEY_H));
6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("intensityUp", new KeyTrigger(KeyInput.KEY_U));
6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("intensityDown", new KeyTrigger(KeyInput.KEY_J));
6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("scaleUp", new KeyTrigger(KeyInput.KEY_I));
7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("scaleDown", new KeyTrigger(KeyInput.KEY_K));
7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("biasUp", new KeyTrigger(KeyInput.KEY_O));
7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("biasDown", new KeyTrigger(KeyInput.KEY_L));
7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("outputConfig", new KeyTrigger(KeyInput.KEY_P));
7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("toggleUseAO", new KeyTrigger(KeyInput.KEY_SPACE));
7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("toggleUseOnlyAo", new KeyTrigger(KeyInput.KEY_NUMPAD0));
7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        ActionListener acl = new ActionListener() {
7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            public void onAction(String name, boolean keyPressed, float tpf) {
8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("toggleUseAO") && keyPressed) {
8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setEnabled(!filter.isEnabled());
8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    // filter.setUseAo(!filter.isUseAo());
8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("use AO : " + filter.isEnabled());
8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("toggleUseOnlyAo") && keyPressed) {
8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setUseOnlyAo(!filter.isUseOnlyAo());
8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("use Only AO : " + filter.isUseOnlyAo());
8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("outputConfig") && keyPressed) {
9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("new SSAOFilter(" + filter.getSampleRadius() + "f," + filter.getIntensity() + "f," + filter.getScale() + "f," + filter.getBias() + "f);");
9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        };
9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        AnalogListener anl = new AnalogListener() {
9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            public void onAnalog(String name, float value, float tpf) {
10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("sampleRadiusUp")) {
10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setSampleRadius(filter.getSampleRadius() + 0.01f);
10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("Sample Radius : " + filter.getSampleRadius());
10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("sampleRadiusDown")) {
10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setSampleRadius(filter.getSampleRadius() - 0.01f);
10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("Sample Radius : " + filter.getSampleRadius());
10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("intensityUp")) {
10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setIntensity(filter.getIntensity() + 0.01f);
11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("Intensity : " + filter.getIntensity());
11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("intensityDown")) {
11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setIntensity(filter.getIntensity() - 0.01f);
11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("Intensity : " + filter.getIntensity());
11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("scaleUp")) {
11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setScale(filter.getScale() + 0.01f);
11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("scale : " + filter.getScale());
11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("scaleDown")) {
12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setScale(filter.getScale() - 0.01f);
12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("scale : " + filter.getScale());
12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("biasUp")) {
12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setBias(filter.getBias() + 0.001f);
12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("bias : " + filter.getBias());
12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (name.equals("biasDown")) {
12959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    filter.setBias(filter.getBias() - 0.001f);
13059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    System.out.println("bias : " + filter.getBias());
13159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
13259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
13359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
13459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        };
13559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(acl, "toggleUseAO", "toggleUseOnlyAo", "outputConfig");
13659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(anl, "sampleRadiusUp", "sampleRadiusDown", "intensityUp", "intensityDown", "scaleUp", "scaleDown",
13759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                "biasUp", "biasDown");
13859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
13959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
14059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta}
141