OSDN Git Service

a4b70b43f8c188cc8e31ba5add1efa4554240a90
[mikumikustudio/MikuMikuStudio.git] / src / jmetest / effects / TestLensFlare.java
1 /*
2  * Copyright (c) 2003-2009 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 jmetest.effects;
34
35 import com.jme.app.SimpleGame;
36 import com.jme.bounding.BoundingBox;
37 import com.jme.image.Image;
38 import com.jme.image.Texture;
39 import com.jme.light.LightNode;
40 import com.jme.light.PointLight;
41 import com.jme.math.Vector3f;
42 import com.jme.renderer.ColorRGBA;
43 import com.jme.scene.Spatial.LightCombineMode;
44 import com.jme.scene.shape.Box;
45 import com.jme.scene.state.TextureState;
46 import com.jme.util.TextureManager;
47 import com.jmex.effects.LensFlare;
48 import com.jmex.effects.LensFlareFactory;
49
50 /**
51  * <code>TestLensFlare</code> Test of the lens flare effect in jME. Notice
52  * that currently it doesn't do occlusion culling.
53  * 
54  * @author Joshua Slack
55  * @version $Id: TestLensFlare.java,v 1.17 2007/09/21 15:46:34 nca Exp $
56  */
57 public class TestLensFlare extends SimpleGame {
58
59     private LightNode lightNode;
60     LensFlare flare;
61
62     public static void main(String[] args) {
63         TestLensFlare app = new TestLensFlare();
64         app.setConfigShowMode(ConfigShowMode.AlwaysShow);
65         app.start();
66     }
67
68     protected void simpleInitGame() {
69
70         display.setTitle("Lens Flare!");
71         cam.setLocation(new Vector3f(0.0f, 0.0f, 200.0f));
72         cam.update();
73         lightState.detachAll();
74
75         PointLight dr = new PointLight();
76         dr.setEnabled(true);
77         dr.setDiffuse(ColorRGBA.white.clone());
78         dr.setAmbient(ColorRGBA.gray.clone());
79         dr.setLocation(new Vector3f(0f, 0f, 0f));
80
81         lightState.attach(dr);
82         lightState.setTwoSidedLighting(true);
83
84         lightNode = new LightNode("light");
85         lightNode.setLight(dr);
86
87         Vector3f min2 = new Vector3f(-0.5f, -0.5f, -0.5f);
88         Vector3f max2 = new Vector3f(0.5f, 0.5f, 0.5f);
89         Box lightBox = new Box("box", min2, max2);
90         lightBox.setModelBound(new BoundingBox());
91         lightBox.updateModelBound();
92         lightNode.attachChild(lightBox);
93         lightNode.setLocalTranslation(new Vector3f(-14f, 14f, -14f));
94
95         Box box2 = new Box("blocker", new Vector3f(-5, -5, -5), new Vector3f(5,
96                 5, 5));
97         box2.setModelBound(new BoundingBox());
98         box2.updateModelBound();
99         box2.setLocalTranslation(new Vector3f(100, 0, 0));
100         rootNode.attachChild(box2);
101
102         // clear the lights from this lightbox so the lightbox itself doesn't
103         // get affected by light:
104         lightBox.setLightCombineMode(LightCombineMode.Off);
105
106         // Setup the lensflare textures.
107         TextureState[] tex = new TextureState[4];
108         tex[0] = display.getRenderer().createTextureState();
109         tex[0].setTexture(TextureManager.loadTexture(LensFlare.class
110                 .getClassLoader()
111                 .getResource("jmetest/data/texture/flare1.png"),
112                 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear, Image.Format.RGBA8,
113                 0.0f, true));
114         tex[0].setEnabled(true);
115
116         tex[1] = display.getRenderer().createTextureState();
117         tex[1].setTexture(TextureManager.loadTexture(LensFlare.class
118                 .getClassLoader()
119                 .getResource("jmetest/data/texture/flare2.png"),
120                 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
121         tex[1].setEnabled(true);
122
123         tex[2] = display.getRenderer().createTextureState();
124         tex[2].setTexture(TextureManager.loadTexture(LensFlare.class
125                 .getClassLoader()
126                 .getResource("jmetest/data/texture/flare3.png"),
127                 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
128         tex[2].setEnabled(true);
129
130         tex[3] = display.getRenderer().createTextureState();
131         tex[3].setTexture(TextureManager.loadTexture(LensFlare.class
132                 .getClassLoader()
133                 .getResource("jmetest/data/texture/flare4.png"),
134                 Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
135         tex[3].setEnabled(true);
136
137         flare = LensFlareFactory.createBasicLensFlare("flare", tex);
138         flare.setRootNode(rootNode);
139         //lightNode.attachChild(flare);
140         Box box = new Box("my box", new Vector3f(0, 0, 0), 10, 10, 10);
141         box.setModelBound(new BoundingBox());
142         box.updateModelBound();
143         rootNode.attachChild(box);
144         rootNode.attachChild(lightNode);
145
146         // notice that it comes at the end
147         lightNode.attachChild(flare);
148
149     }
150
151 }