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.AnalogListener;
     37 import com.jme3.input.controls.KeyTrigger;
     38 import com.jme3.post.filters.BloomFilter;
     39 
     40 /**
     41  *
     42  * @author nehon
     43  */
     44 public class BloomUI {
     45 
     46     public BloomUI(InputManager inputManager, final BloomFilter filter) {
     47 
     48         System.out.println("----------------- Bloom UI Debugger --------------------");
     49         System.out.println("-- blur Scale : press Y to increase, H to decrease");
     50         System.out.println("-- exposure Power : press U to increase, J to decrease");
     51         System.out.println("-- exposure CutOff : press I to increase, K to decrease");
     52         System.out.println("-- bloom Intensity : press O to increase, P to decrease");
     53         System.out.println("-------------------------------------------------------");
     54 
     55         inputManager.addMapping("blurScaleUp", new KeyTrigger(KeyInput.KEY_Y));
     56         inputManager.addMapping("blurScaleDown", new KeyTrigger(KeyInput.KEY_H));
     57         inputManager.addMapping("exposurePowerUp", new KeyTrigger(KeyInput.KEY_U));
     58         inputManager.addMapping("exposurePowerDown", new KeyTrigger(KeyInput.KEY_J));
     59         inputManager.addMapping("exposureCutOffUp", new KeyTrigger(KeyInput.KEY_I));
     60         inputManager.addMapping("exposureCutOffDown", new KeyTrigger(KeyInput.KEY_K));
     61         inputManager.addMapping("bloomIntensityUp", new KeyTrigger(KeyInput.KEY_O));
     62         inputManager.addMapping("bloomIntensityDown", new KeyTrigger(KeyInput.KEY_L));
     63 
     64 
     65         AnalogListener anl = new AnalogListener() {
     66 
     67             public void onAnalog(String name, float value, float tpf) {
     68                 if (name.equals("blurScaleUp")) {
     69                     filter.setBlurScale(filter.getBlurScale() + 0.01f);
     70                     System.out.println("blurScale : " + filter.getBlurScale());
     71                 }
     72                 if (name.equals("blurScaleDown")) {
     73                     filter.setBlurScale(filter.getBlurScale() - 0.01f);
     74                     System.out.println("blurScale : " + filter.getBlurScale());
     75                 }
     76                 if (name.equals("exposurePowerUp")) {
     77                     filter.setExposurePower(filter.getExposurePower() + 0.01f);
     78                     System.out.println("exposurePower : " + filter.getExposurePower());
     79                 }
     80                 if (name.equals("exposurePowerDown")) {
     81                     filter.setExposurePower(filter.getExposurePower() - 0.01f);
     82                     System.out.println("exposurePower : " + filter.getExposurePower());
     83                 }
     84                 if (name.equals("exposureCutOffUp")) {
     85                     filter.setExposureCutOff(Math.min(1.0f, Math.max(0.0f, filter.getExposureCutOff() + 0.001f)));
     86                     System.out.println("exposure CutOff : " + filter.getExposureCutOff());
     87                 }
     88                 if (name.equals("exposureCutOffDown")) {
     89                     filter.setExposureCutOff(Math.min(1.0f, Math.max(0.0f, filter.getExposureCutOff() - 0.001f)));
     90                     System.out.println("exposure CutOff : " + filter.getExposureCutOff());
     91                 }
     92                 if (name.equals("bloomIntensityUp")) {
     93                     filter.setBloomIntensity(filter.getBloomIntensity() + 0.01f);
     94                     System.out.println("bloom Intensity : " + filter.getBloomIntensity());
     95                 }
     96                 if (name.equals("bloomIntensityDown")) {
     97                     filter.setBloomIntensity(filter.getBloomIntensity() - 0.01f);
     98                     System.out.println("bloom Intensity : " + filter.getBloomIntensity());
     99                 }
    100 
    101 
    102             }
    103         };
    104 
    105         inputManager.addListener(anl, "blurScaleUp", "blurScaleDown", "exposurePowerUp", "exposurePowerDown",
    106                 "exposureCutOffUp", "exposureCutOffDown", "bloomIntensityUp", "bloomIntensityDown");
    107 
    108     }
    109 }
    110