2 * Copyright (c) 2003-2009 jMonkeyEngine
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
33 package jmetest.effects;
35 import com.jme.app.SimpleGame;
36 import com.jme.bounding.BoundingSphere;
37 import com.jme.image.Texture;
38 import com.jme.math.FastMath;
39 import com.jme.math.Vector3f;
40 import com.jme.renderer.ColorRGBA;
41 import com.jme.scene.state.BlendState;
42 import com.jme.scene.state.TextureState;
43 import com.jme.scene.state.ZBufferState;
44 import com.jme.util.TextureManager;
45 import com.jmex.effects.particles.ParticleFactory;
46 import com.jmex.effects.particles.ParticleMesh;
49 * @author Joshua Slack
50 * @version $Id: TestParticleSystem.java,v 1.34 2006/07/06 22:22:18 nca Exp $
52 public class TestParticleSystem extends SimpleGame {
54 private ParticleMesh pMesh;
55 private Vector3f currentPos = new Vector3f(), newPos = new Vector3f();
56 private float frameRate = 0;
58 public static void main(String[] args) {
59 TestParticleSystem app = new TestParticleSystem();
60 app.setConfigShowMode(ConfigShowMode.AlwaysShow);
64 protected void simpleUpdate() {
65 if (tpf > 1f) tpf = 1.0f; // do this to prevent a long pause at start
67 if ( (int) currentPos.x == (int) newPos.x
68 && (int) currentPos.y == (int) newPos.y
69 && (int) currentPos.z == (int) newPos.z) {
70 newPos.x = (float) Math.random() * 50 - 25;
71 newPos.y = (float) Math.random() * 50 - 25;
72 newPos.z = (float) Math.random() * 50 - 150;
75 frameRate = timer.getFrameRate() / 2;
76 currentPos.x -= (currentPos.x - newPos.x)
78 currentPos.y -= (currentPos.y - newPos.y)
80 currentPos.z -= (currentPos.z - newPos.z)
83 rootNode.setLocalTranslation(currentPos);
87 protected void simpleInitGame() {
88 display.setTitle("Particle System");
89 lightState.setEnabled(false);
91 BlendState as1 = display.getRenderer().createBlendState();
92 as1.setBlendEnabled(true);
93 as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
94 as1.setDestinationFunction(BlendState.DestinationFunction.One);
95 as1.setTestEnabled(true);
96 as1.setTestFunction(BlendState.TestFunction.GreaterThan);
100 TextureState ts = display.getRenderer().createTextureState();
102 TextureManager.loadTexture(
103 TestParticleSystem.class.getClassLoader().getResource(
104 "jmetest/data/texture/flaresmall.jpg"),
105 Texture.MinificationFilter.Trilinear,
106 Texture.MagnificationFilter.Bilinear));
109 pMesh = ParticleFactory.buildParticles("particles", 300);
110 pMesh.setEmissionDirection(new Vector3f(0,1,0));
111 pMesh.setInitialVelocity(.006f);
112 pMesh.setStartSize(2.5f);
113 pMesh.setEndSize(.5f);
114 pMesh.setMinimumLifeTime(1200f);
115 pMesh.setMaximumLifeTime(1400f);
116 pMesh.setStartColor(new ColorRGBA(1, 0, 0, 1));
117 pMesh.setEndColor(new ColorRGBA(0, 1, 0, 0));
118 pMesh.setMaximumAngle(360f * FastMath.DEG_TO_RAD);
119 pMesh.getParticleController().setControlFlow(false);
120 pMesh.setParticlesInWorldCoords(true);
123 rootNode.setRenderState(ts);
124 rootNode.setRenderState(as1);
125 ZBufferState zstate = display.getRenderer().createZBufferState();
126 zstate.setEnabled(false);
127 pMesh.setRenderState(zstate);
128 pMesh.setModelBound(new BoundingSphere());
129 pMesh.updateModelBound();
131 rootNode.attachChild(pMesh);