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 
     33 package jme3test.post;
     34 
     35 import com.jme3.input.InputManager;
     36 import com.jme3.input.KeyInput;
     37 import com.jme3.input.controls.ActionListener;
     38 import com.jme3.input.controls.AnalogListener;
     39 import com.jme3.input.controls.KeyTrigger;
     40 import com.jme3.post.filters.LightScatteringFilter;
     41 
     42 /**
     43  *
     44  * @author nehon
     45  */
     46 public class LightScatteringUI {
     47     private LightScatteringFilter filter;
     48     public LightScatteringUI(InputManager inputManager, LightScatteringFilter proc) {
     49         filter=proc;
     50 
     51 
     52         System.out.println("----------------- LightScattering UI Debugger --------------------");
     53         System.out.println("-- Sample number : press Y to increase, H to decrease");
     54         System.out.println("-- blur start : press U to increase, J to decrease");
     55         System.out.println("-- blur width : press I to increase, K to decrease");
     56         System.out.println("-- Light density : press O to increase, P to decrease");
     57 //        System.out.println("-- Toggle AO on/off : press space bar");
     58 //        System.out.println("-- Use only AO : press Num pad 0");
     59 //        System.out.println("-- Output config declaration : press P");
     60         System.out.println("-------------------------------------------------------");
     61 
     62         inputManager.addMapping("sampleUp", new KeyTrigger(KeyInput.KEY_Y));
     63         inputManager.addMapping("sampleDown", new KeyTrigger(KeyInput.KEY_H));
     64         inputManager.addMapping("blurStartUp", new KeyTrigger(KeyInput.KEY_U));
     65         inputManager.addMapping("blurStartDown", new KeyTrigger(KeyInput.KEY_J));
     66         inputManager.addMapping("blurWidthUp", new KeyTrigger(KeyInput.KEY_I));
     67         inputManager.addMapping("blurWidthDown", new KeyTrigger(KeyInput.KEY_K));
     68         inputManager.addMapping("lightDensityUp", new KeyTrigger(KeyInput.KEY_O));
     69         inputManager.addMapping("lightDensityDown", new KeyTrigger(KeyInput.KEY_L));
     70         inputManager.addMapping("outputConfig", new KeyTrigger(KeyInput.KEY_P));
     71 //        inputManager.addMapping("toggleUseAO", new KeyTrigger(KeyInput.KEY_SPACE));
     72 //        inputManager.addMapping("toggleUseOnlyAo", new KeyTrigger(KeyInput.KEY_NUMPAD0));
     73 
     74         ActionListener acl = new ActionListener() {
     75 
     76             public void onAction(String name, boolean keyPressed, float tpf) {
     77 
     78                 if (name.equals("sampleUp")) {
     79                     filter.setNbSamples(filter.getNbSamples()+1);
     80                     System.out.println("Nb Samples : "+filter.getNbSamples());
     81                 }
     82                 if (name.equals("sampleDown")) {
     83                    filter.setNbSamples(filter.getNbSamples()-1);
     84                    System.out.println("Nb Samples : "+filter.getNbSamples());
     85                 }
     86                 if (name.equals("outputConfig") && keyPressed) {
     87                    System.out.println("lightScatteringFilter.setNbSamples("+filter.getNbSamples()+");");
     88                    System.out.println("lightScatteringFilter.setBlurStart("+filter.getBlurStart()+"f);");
     89                    System.out.println("lightScatteringFilter.setBlurWidth("+filter.getBlurWidth()+"f);");
     90                    System.out.println("lightScatteringFilter.setLightDensity("+filter.getLightDensity()+"f);");
     91                 }
     92 
     93 
     94             }
     95         };
     96 
     97          AnalogListener anl = new AnalogListener() {
     98 
     99             public void onAnalog(String name, float value, float tpf) {
    100 
    101                 if (name.equals("blurStartUp")) {
    102                     filter.setBlurStart(filter.getBlurStart()+0.001f);
    103                     System.out.println("Blur start : "+filter.getBlurStart());
    104                 }
    105                 if (name.equals("blurStartDown")) {
    106                     filter.setBlurStart(filter.getBlurStart()-0.001f);
    107                     System.out.println("Blur start : "+filter.getBlurStart());
    108                 }
    109                  if (name.equals("blurWidthUp")) {
    110                     filter.setBlurWidth(filter.getBlurWidth()+0.001f);
    111                     System.out.println("Blur Width : "+filter.getBlurWidth());
    112                 }
    113                 if (name.equals("blurWidthDown")) {
    114                     filter.setBlurWidth(filter.getBlurWidth()-0.001f);
    115                     System.out.println("Blur Width : "+filter.getBlurWidth());
    116                 }
    117                 if (name.equals("lightDensityUp")) {
    118                     filter.setLightDensity(filter.getLightDensity()+0.001f);
    119                     System.out.println("light Density : "+filter.getLightDensity());
    120                 }
    121                 if (name.equals("lightDensityDown")) {
    122                      filter.setLightDensity(filter.getLightDensity()-0.001f);
    123                     System.out.println("light Density : "+filter.getLightDensity());
    124                 }
    125 
    126             }
    127         };
    128         inputManager.addListener(acl,"sampleUp","sampleDown","outputConfig");
    129 
    130         inputManager.addListener(anl, "blurStartUp","blurStartDown","blurWidthUp", "blurWidthDown","lightDensityUp", "lightDensityDown");
    131 
    132     }
    133 
    134 
    135 
    136 }
    137