Problems with rocket engines

hello jmonkey community,



I’ve a problem with the particle meshes.

I want to create an engine (for a spaceship), but I still get problems with the flame.

The engine isn’t showing particles on the x-z layers/axial.

As an example I edited the third-person-example (ParticleOnNodeTest.java)



Screenshots:











Can you tell me how to write it to show the whole flame on any axial?



ParticleOnNodeTest.java

/*
 * Copyright (c) 2003-2009 jMonkeyEngine
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.ImageIcon;

import jmetest.effects.TestParticleSystem;
import jmetest.terrain.TestTerrain;

import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.ChaseCamera;
import com.jme.input.InputSystem;
import com.jme.input.ThirdPersonHandler;
import com.jme.input.joystick.Joystick;
import com.jme.input.joystick.JoystickInput;
import com.jme.input.thirdperson.ThirdPersonJoystickPlugin;
import com.jme.light.DirectionalLight;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.CullState;
import com.jme.scene.state.FogState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleSystem;
import com.jmex.terrain.TerrainPage;
import com.jmex.terrain.util.FaultFractalHeightMap;
import com.jmex.terrain.util.ProceduralTextureGenerator;

/**
 * <code>TestThirdPersonController</code>
 *
 * @author Joshua Slack
 * @version $Revision: 1.21 $
 */
public class ParticleOnNodeTest extends SimpleGame {
   private static final Logger logger = Logger
         .getLogger(ParticleOnNodeTest.class.getName());

   private Node m_character;

   private ChaseCamera chaser;

   private TerrainPage page;

   /**
    * Entry point for the test,
    *
    * @param args
    */
   public static void main(String[] args) {
      try {
         JoystickInput.setProvider(InputSystem.INPUT_SYSTEM_LWJGL);
      } catch (Exception e) {
         logger.logp(Level.SEVERE, ParticleOnNodeTest.class.toString(),
               "main(args)", "Exception", e);
      }
      ParticleOnNodeTest app = new ParticleOnNodeTest();
      app.setConfigShowMode(ConfigShowMode.AlwaysShow);
      app.start();
   }

   /**
    * builds the scene.
    *
    * @see com.jme.app.SimpleGame#initGame()
    */
   protected void simpleInitGame() {
      display.setTitle("jME - 3rd person controller test");

      setupCharacter();
      setupTerrain();
      setupChaseCamera();
      setupInput();
      setupJoystick();
   }

   protected void simpleUpdate() {
      chaser.update(tpf);
      float camMinHeight = page.getHeight(cam.getLocation()) + 2f;
      if (!Float.isInfinite(camMinHeight) && !Float.isNaN(camMinHeight)
            && cam.getLocation().y <= camMinHeight) {
         cam.getLocation().y = camMinHeight;
         cam.update();
      }

      float characterMinHeight = page.getHeight(m_character
            .getLocalTranslation())
            + ((BoundingBox) m_character.getWorldBound()).yExtent;
      if (!Float.isInfinite(characterMinHeight)
            && !Float.isNaN(characterMinHeight)) {
         m_character.getLocalTranslation().y = characterMinHeight;
      }
   }

   private void setupCharacter() {
      Box b = new Box("box", new Vector3f(), 5, 5, 5);
      b.setModelBound(new BoundingBox());
      b.updateModelBound();
      m_character = new Node("char node");
      rootNode.attachChild(m_character);
      m_character.attachChild(b);
      m_character.updateWorldBound(); // We do this to allow the camera setup
      // access to the world bound in our
      // setup code.

      TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      ts.setTexture(TextureManager.loadTexture(
            ParticleOnNodeTest.class.getClassLoader().getResource(
                  "jmetest/data/images/Monkey.jpg"),
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear));

      // ####################################################
      // ParticleCode##############################

      ParticleSystem particles = ParticleFactory.buildParticles("particles",
            50);

      particles.setEmissionDirection(new Vector3f(1, 0, 0));

      particles.setStartSize(5f);
      particles.setEndSize(01f);
      particles.setLocalTranslation(0.6f, 0, 0);
      particles.setInitialVelocity(0.1f);
      particles.setMinimumLifeTime(100);
      particles.setMaximumLifeTime(200);
      particles.setStartColor(new ColorRGBA(1, 1, 1, 0.2f));
      particles.setEndColor(new ColorRGBA(1, 1, 0, 1));

      particles.setParticlesInWorldCoords(false);

      particles.getParticleController().setSpeed(0.75f);

      BlendState as1 = DisplaySystem.getDisplaySystem().getRenderer()
            .createBlendState();
      as1.setBlendEnabled(true);
      as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
      as1.setDestinationFunction(BlendState.DestinationFunction.One);
      as1.setEnabled(true);
      particles.setRenderState(as1);

      TextureState ts2 = DisplaySystem.getDisplaySystem().getRenderer()
            .createTextureState();
      ts2.setTexture(TextureManager.loadTexture(TestParticleSystem.class
            .getClassLoader().getResource(
                  "jmetest/data/texture/flaresmall.jpg"),
            Texture.MinificationFilter.Trilinear,
            Texture.MagnificationFilter.Bilinear));
      ts2.setEnabled(true);
      particles.setRenderState(ts2);

      ZBufferState zstate = DisplaySystem.getDisplaySystem().getRenderer()
            .createZBufferState();
      zstate.setEnabled(true);

      zstate
            .setFunction(com.jme.scene.state.ZBufferState.TestFunction.Always);
      particles.setRenderState(zstate);
      m_character.attachChild(particles);

      // #########################End Particle Code #################

      m_character.setRenderState(ts);
   }

   private void setupTerrain() {
      rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);

      display.getRenderer().setBackgroundColor(
            new ColorRGBA(0.5f, 0.5f, 0.5f, 1));

      DirectionalLight dr = new DirectionalLight();
      dr.setEnabled(true);
      dr.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
      dr.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
      dr.setDirection(new Vector3f(0.5f, -0.5f, 0));

      CullState cs = display.getRenderer().createCullState();
      cs.setCullFace(CullState.Face.Back);
      cs.setEnabled(true);
      rootNode.setRenderState(cs);

      lightState.detachAll();
      lightState.attach(dr);

      FaultFractalHeightMap heightMap = new FaultFractalHeightMap(257, 32, 0,
            255, 0.75f);
      Vector3f terrainScale = new Vector3f(10, 1, 10);
      heightMap.setHeightScale(0.001f);
      page = new TerrainPage("Terrain", 33, heightMap.getSize(),
            terrainScale, heightMap.getHeightMap());

      page.setDetailTexture(1, 16);
      rootNode.attachChild(page);

      ProceduralTextureGenerator pt = new ProceduralTextureGenerator(
            heightMap);
      pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader()
            .getResource("jmetest/data/texture/grassb.png")), -128, 0, 128);
      pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader()
            .getResource("jmetest/data/texture/dirt.jpg")), 0, 128, 255);
      pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader()
            .getResource("jmetest/data/texture/highest.jpg")), 128, 255,
            384);

      pt.createTexture(512);

      TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      Texture t1 = TextureManager.loadTexture(pt.getImageIcon().getImage(),
            Texture.MinificationFilter.Trilinear,
            Texture.MagnificationFilter.Bilinear, true);
      ts.setTexture(t1, 0);

      Texture t2 = TextureManager.loadTexture(ParticleOnNodeTest.class
            .getClassLoader()
            .getResource("jmetest/data/texture/Detail.jpg"),
            Texture.MinificationFilter.Trilinear,
            Texture.MagnificationFilter.Bilinear);
      ts.setTexture(t2, 1);
      t2.setWrap(Texture.WrapMode.Repeat);

      t1.setApply(Texture.ApplyMode.Combine);
      t1.setCombineFuncRGB(Texture.CombinerFunctionRGB.Modulate);
      t1.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
      t1.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
      t1.setCombineSrc1RGB(Texture.CombinerSource.PrimaryColor);
      t1.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);

      t2.setApply(Texture.ApplyMode.Combine);
      t2.setCombineFuncRGB(Texture.CombinerFunctionRGB.AddSigned);
      t2.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
      t2.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
      t2.setCombineSrc1RGB(Texture.CombinerSource.Previous);
      t2.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);
      rootNode.setRenderState(ts);

      FogState fs = display.getRenderer().createFogState();
      fs.setDensity(0.5f);
      fs.setEnabled(true);
      fs.setColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f));
      fs.setEnd(1000);
      fs.setStart(500);
      fs.setDensityFunction(FogState.DensityFunction.Linear);
      fs.setQuality(FogState.Quality.PerVertex);
      rootNode.setRenderState(fs);
   }

   private void setupChaseCamera() {
      Vector3f targetOffset = new Vector3f();
      targetOffset.y = ((BoundingBox) m_character.getWorldBound()).yExtent * 1.5f;
      chaser = new ChaseCamera(cam, m_character);
      chaser.setTargetOffset(targetOffset);
   }

   private void setupInput() {
      HashMap<String, Object> handlerProps = new HashMap<String, Object>();
      handlerProps.put(ThirdPersonHandler.PROP_DOGRADUAL, "true");
      handlerProps.put(ThirdPersonHandler.PROP_TURNSPEED, ""
            + (1.0f * FastMath.PI));
      handlerProps.put(ThirdPersonHandler.PROP_LOCKBACKWARDS, "false");
      handlerProps.put(ThirdPersonHandler.PROP_CAMERAALIGNEDMOVE, "true");
      input = new ThirdPersonHandler(m_character, cam, handlerProps);
      input.setActionSpeed(100f);
   }

   private void setupJoystick() {
      ArrayList<Joystick> joys = JoystickInput.get().findJoysticksByAxis(
            "X Axis", "Y Axis", "Z Axis", "Z Rotation");
      Joystick joy = joys.size() >= 1 ? joys.get(0) : null;
      if (joy != null) {
         ThirdPersonJoystickPlugin plugin = new ThirdPersonJoystickPlugin(
               joy, joy.findAxis("X Axis"), joy.findAxis("Y Axis"), joy
                     .findAxis("Z Axis"), joy.findAxis("Z Rotation"));
         ((ThirdPersonHandler) input).setJoystickPlugin(plugin);
         chaser.getMouseLook().setJoystickPlugin(plugin);
      }
   }
}

its easier to release the particles into world space.

also set he ZBuffer to non-writable.


particles.setParticlesInWorldCoords(true);
ZBufferState zstate = DisplaySystem.getDisplaySystem().getRenderer()
                .createZBufferState();
zstate.setWritable(false);
particles.setRenderState(zstate);

Thank you for your fast answer but with the particles.setParticlesInWorldCoords(true) method I get flickering



How can I stop the flickering?

i don't know what you mean with flickering.

Try to compare your code with the one of TestParticleSwarm to find differences.

Or with the Particle code generated by RenParticleEditor