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
33package jme3test.helloworld;
34
35import com.jme3.app.SimpleApplication;
36import com.jme3.effect.ParticleEmitter;
37import com.jme3.effect.ParticleMesh;
38import com.jme3.material.Material;
39import com.jme3.math.ColorRGBA;
40import com.jme3.math.Vector3f;
41
42/** Sample 11 - how to create fire, water, and explosion effects. */
43public class HelloEffects extends SimpleApplication {
44
45  public static void main(String[] args) {
46    HelloEffects app = new HelloEffects();
47    app.start();
48  }
49
50  @Override
51  public void simpleInitApp() {
52    ParticleEmitter fire =
53            new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
54    Material mat_red = new Material(assetManager,
55            "Common/MatDefs/Misc/Particle.j3md");
56    mat_red.setTexture("Texture", assetManager.loadTexture(
57            "Effects/Explosion/flame.png"));
58    fire.setMaterial(mat_red);
59    fire.setImagesX(2);
60    fire.setImagesY(2); // 2x2 texture animation
61    fire.setEndColor(  new ColorRGBA(1f, 0f, 0f, 1f));   // red
62    fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow
63    fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
64    fire.setStartSize(1.5f);
65    fire.setEndSize(0.1f);
66    fire.setGravity(0, 0, 0);
67    fire.setLowLife(1f);
68    fire.setHighLife(3f);
69    fire.getParticleInfluencer().setVelocityVariation(0.3f);
70    rootNode.attachChild(fire);
71
72    ParticleEmitter debris =
73            new ParticleEmitter("Debris", ParticleMesh.Type.Triangle, 10);
74    Material debris_mat = new Material(assetManager,
75            "Common/MatDefs/Misc/Particle.j3md");
76    debris_mat.setTexture("Texture", assetManager.loadTexture(
77            "Effects/Explosion/Debris.png"));
78    debris.setMaterial(debris_mat);
79    debris.setImagesX(3);
80    debris.setImagesY(3); // 3x3 texture animation
81    debris.setSelectRandomImage(true);
82    debris.setRotateSpeed(4);
83    debris.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 4, 0));
84    debris.setStartColor(ColorRGBA.White);
85    debris.setGravity(0, 6, 0);
86    debris.getParticleInfluencer().setVelocityVariation(.60f);
87    rootNode.attachChild(debris);
88    debris.emitAllParticles();
89
90//    ParticleEmitter water =
91//            new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 20);
92//    Material mat_blue = new Material(assetManager,
93//            "Common/MatDefs/Misc/Particle.j3md");
94//    mat_blue.setTexture("Texture", assetManager.loadTexture(
95//            "Effects/Explosion/flame.png"));
96//    water.setMaterial(mat_blue);
97//    water.setImagesX(2);
98//    water.setImagesY(2); // 2x2 texture animation
99//    water.setStartColor( ColorRGBA.Blue);
100//    water.setEndColor( ColorRGBA.Cyan);
101//    water.getParticleInfluencer().setInitialVelocity(new Vector3f(0, -4, 0));
102//    water.setStartSize(1f);
103//    water.setEndSize(1.5f);
104//    water.setGravity(0,1,0);
105//    water.setLowLife(1f);
106//    water.setHighLife(1f);
107//    water.getParticleInfluencer().setVelocityVariation(0.1f);
108//    water.setLocalTranslation(0, 6, 0);
109//    rootNode.attachChild(water);
110
111  }
112}
113