• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.water;
33 
34 import com.jme3.app.SimpleApplication;
35 import com.jme3.asset.plugins.HttpZipLocator;
36 import com.jme3.asset.plugins.ZipLocator;
37 import com.jme3.input.controls.ActionListener;
38 import com.jme3.input.controls.KeyTrigger;
39 import com.jme3.light.DirectionalLight;
40 import com.jme3.math.ColorRGBA;
41 import com.jme3.math.Vector3f;
42 import com.jme3.post.FilterPostProcessor;
43 import com.jme3.scene.Spatial;
44 import com.jme3.util.SkyFactory;
45 import com.jme3.water.WaterFilter;
46 import java.io.File;
47 
48 public class TestPostWaterLake extends SimpleApplication {
49 
50     // set default for applets
51     private static boolean useHttp = true;
52 
main(String[] args)53     public static void main(String[] args) {
54 
55         TestPostWaterLake app = new TestPostWaterLake();
56         app.start();
57     }
58 
simpleInitApp()59     public void simpleInitApp() {
60         this.flyCam.setMoveSpeed(10);
61         cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
62       //  cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));
63 
64         // load sky
65         rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
66 
67         File file = new File("wildhouse.zip");
68 
69         if (file.exists()) {
70             useHttp = false;
71         }
72         // create the geometry and attach it
73         // load the level from zip or http zip
74         if (useHttp) {
75             assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class.getName());
76         } else {
77             assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName());
78         }
79         Spatial scene = assetManager.loadModel("main.scene");
80         rootNode.attachChild(scene);
81 
82         DirectionalLight sun = new DirectionalLight();
83         Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
84         sun.setDirection(lightDir);
85         sun.setColor(ColorRGBA.White.clone().multLocal(2));
86         scene.addLight(sun);
87 
88         FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
89         final WaterFilter water = new WaterFilter(rootNode, lightDir);
90         water.setWaterHeight(-20);
91         water.setUseFoam(false);
92         water.setUseRipples(false);
93         water.setDeepWaterColor(ColorRGBA.Brown);
94         water.setWaterColor(ColorRGBA.Brown.mult(2.0f));
95         water.setWaterTransparency(0.2f);
96         water.setMaxAmplitude(0.3f);
97         water.setWaveScale(0.008f);
98         water.setSpeed(0.7f);
99         water.setShoreHardness(1.0f);
100         water.setRefractionConstant(0.2f);
101         water.setShininess(0.3f);
102         water.setSunScale(1.0f);
103         water.setColorExtinction(new Vector3f(10.0f, 20.0f, 30.0f));
104         fpp.addFilter(water);
105         viewPort.addProcessor(fpp);
106 
107         inputManager.addListener(new ActionListener() {
108 
109             public void onAction(String name, boolean isPressed, float tpf) {
110               if(isPressed){
111                   if(water.isUseHQShoreline()){
112                       water.setUseHQShoreline(false);
113                   }else{
114                       water.setUseHQShoreline(true);
115                   }
116               }
117             }
118         }, "HQ");
119 
120         inputManager.addMapping("HQ", new KeyTrigger(keyInput.KEY_SPACE));
121     }
122 }
123