Home | History | Annotate | Download | only in post
      1 /*
      2  * Copyright (c) 2009-2010 jMonkeyEngine
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are
      7  * met:
      8  *
      9  * * Redistributions of source code must retain the above copyright
     10  *   notice, this list of conditions and the following disclaimer.
     11  *
     12  * * Redistributions in binary form must reproduce the above copyright
     13  *   notice, this list of conditions and the following disclaimer in the
     14  *   documentation and/or other materials provided with the distribution.
     15  *
     16  * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
     17  *   may be used to endorse or promote products derived from this software
     18  *   without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 package jme3test.post;
     33 
     34 import com.jme3.input.InputManager;
     35 import com.jme3.input.KeyInput;
     36 import com.jme3.input.controls.ActionListener;
     37 import com.jme3.input.controls.AnalogListener;
     38 import com.jme3.input.controls.KeyTrigger;
     39 import com.jme3.post.ssao.SSAOFilter;
     40 
     41 /**
     42  *
     43  * @author nehon
     44  */
     45 public class SSAOUI {
     46 
     47     SSAOFilter filter;
     48 
     49     public SSAOUI(InputManager inputManager, SSAOFilter filter) {
     50         this.filter = filter;
     51         init(inputManager);
     52     }
     53 
     54     private void init(InputManager inputManager) {
     55         System.out.println("----------------- Water UI Debugger --------------------");
     56         System.out.println("-- Sample Radius : press Y to increase, H to decrease");
     57         System.out.println("-- AO Intensity : press U to increase, J to decrease");
     58         System.out.println("-- AO scale : press I to increase, K to decrease");
     59         System.out.println("-- AO bias : press O to increase, P to decrease");
     60         System.out.println("-- Toggle AO on/off : press space bar");
     61         System.out.println("-- Use only AO : press Num pad 0");
     62         System.out.println("-- Output config declaration : press P");
     63         System.out.println("-------------------------------------------------------");
     64 
     65         inputManager.addMapping("sampleRadiusUp", new KeyTrigger(KeyInput.KEY_Y));
     66         inputManager.addMapping("sampleRadiusDown", new KeyTrigger(KeyInput.KEY_H));
     67         inputManager.addMapping("intensityUp", new KeyTrigger(KeyInput.KEY_U));
     68         inputManager.addMapping("intensityDown", new KeyTrigger(KeyInput.KEY_J));
     69         inputManager.addMapping("scaleUp", new KeyTrigger(KeyInput.KEY_I));
     70         inputManager.addMapping("scaleDown", new KeyTrigger(KeyInput.KEY_K));
     71         inputManager.addMapping("biasUp", new KeyTrigger(KeyInput.KEY_O));
     72         inputManager.addMapping("biasDown", new KeyTrigger(KeyInput.KEY_L));
     73         inputManager.addMapping("outputConfig", new KeyTrigger(KeyInput.KEY_P));
     74         inputManager.addMapping("toggleUseAO", new KeyTrigger(KeyInput.KEY_SPACE));
     75         inputManager.addMapping("toggleUseOnlyAo", new KeyTrigger(KeyInput.KEY_NUMPAD0));
     76 
     77         ActionListener acl = new ActionListener() {
     78 
     79             public void onAction(String name, boolean keyPressed, float tpf) {
     80 
     81                 if (name.equals("toggleUseAO") && keyPressed) {
     82                     filter.setEnabled(!filter.isEnabled());
     83                     // filter.setUseAo(!filter.isUseAo());
     84                     System.out.println("use AO : " + filter.isEnabled());
     85                 }
     86                 if (name.equals("toggleUseOnlyAo") && keyPressed) {
     87                     filter.setUseOnlyAo(!filter.isUseOnlyAo());
     88                     System.out.println("use Only AO : " + filter.isUseOnlyAo());
     89 
     90                 }
     91                 if (name.equals("outputConfig") && keyPressed) {
     92                     System.out.println("new SSAOFilter(" + filter.getSampleRadius() + "f," + filter.getIntensity() + "f," + filter.getScale() + "f," + filter.getBias() + "f);");
     93                 }
     94             }
     95         };
     96 
     97         AnalogListener anl = new AnalogListener() {
     98 
     99             public void onAnalog(String name, float value, float tpf) {
    100                 if (name.equals("sampleRadiusUp")) {
    101                     filter.setSampleRadius(filter.getSampleRadius() + 0.01f);
    102                     System.out.println("Sample Radius : " + filter.getSampleRadius());
    103                 }
    104                 if (name.equals("sampleRadiusDown")) {
    105                     filter.setSampleRadius(filter.getSampleRadius() - 0.01f);
    106                     System.out.println("Sample Radius : " + filter.getSampleRadius());
    107                 }
    108                 if (name.equals("intensityUp")) {
    109                     filter.setIntensity(filter.getIntensity() + 0.01f);
    110                     System.out.println("Intensity : " + filter.getIntensity());
    111                 }
    112                 if (name.equals("intensityDown")) {
    113                     filter.setIntensity(filter.getIntensity() - 0.01f);
    114                     System.out.println("Intensity : " + filter.getIntensity());
    115                 }
    116                 if (name.equals("scaleUp")) {
    117                     filter.setScale(filter.getScale() + 0.01f);
    118                     System.out.println("scale : " + filter.getScale());
    119                 }
    120                 if (name.equals("scaleDown")) {
    121                     filter.setScale(filter.getScale() - 0.01f);
    122                     System.out.println("scale : " + filter.getScale());
    123                 }
    124                 if (name.equals("biasUp")) {
    125                     filter.setBias(filter.getBias() + 0.001f);
    126                     System.out.println("bias : " + filter.getBias());
    127                 }
    128                 if (name.equals("biasDown")) {
    129                     filter.setBias(filter.getBias() - 0.001f);
    130                     System.out.println("bias : " + filter.getBias());
    131                 }
    132 
    133             }
    134         };
    135         inputManager.addListener(acl, "toggleUseAO", "toggleUseOnlyAo", "outputConfig");
    136         inputManager.addListener(anl, "sampleRadiusUp", "sampleRadiusDown", "intensityUp", "intensityDown", "scaleUp", "scaleDown",
    137                 "biasUp", "biasDown");
    138 
    139     }
    140 }
    141