Translate Particles relative to its origin

Hi,



Im doing a racing game and im doing a nitrous fire comming from the exhaust.

Then the Particle origin moves (translate) with the car but the particles doesnt`t and the effect doesnt look the way i want.

I want that the particles act like the is no translation of the origin, so, the particles must move based on the origin move.

Anybody knows a way to do that with the jME particle system?



Thanks!

is there a way to do this?

particles, once released, do not care about the nodes translation they are attached to.



For a nitro effect or maybe an afterburner it would be nice if the particles would move with the vehicle.

But i don't know either how to do it.

I knew I had read about a similar question earlier… here it is.



Do not think it is what you were looking for though…

hmm ok its possible with the ParticleInfluence, like Hamster mentioned in the other thread:



pMesh.addInfluence(new MyParticleInfluence(pMesh));




    class MyParticleInfluence extends ParticleInfluence {
       private ParticleMesh parent;
       public MyParticleInfluence(ParticleMesh parent) {
          this.parent = parent;
   }
       // Move the particles with the parent node
       @Override
       public void apply(float dt, Particle particle, int index) {
          parent.updateWorldVectors();
          particle.getPosition().addLocal(parent.getWorldTranslation());
       }
    }

I tried what you told me but with no success yet.

But will keep trying and post when i get it right!!



Thanks for the help!

i couldn't get it right myself either :), maybe there are other ways to achieve this

Particles as written are meant to be in world coordinate space.  I can add a switch to let it be in a local coordinate space.  Keep in mind that will only look right for specific applications (such as the mentioned propulsion thrust…)

I made my spaceship engine effect from a modified version of the jet engine example. To make it look right even while moving i reduced the lifetime and initial velocity of the particles. This way the effect doesn't stretch out to much.

In the 2.0 code I've added a new param to ParticleSystem that will allow the world translation and rotation of your system to apply to your particles.  To use it, call:


setParticlesInWorldCoords(boolean)



The default behavior is true.  Take a look at TestParticleSystem which is now setup to use this param and scenegraph coordinates (it was using origin offsets before.)  You can see the new local coord space by changing the setParticlesInWorldCoords to false.

Renanse, the switch could be implemented on 1.0 easily?

Maybe if i see how it works on 2.0 i can implement on 1.0.

The code is similar os totally diferent?

It would probably not be that hard.

I found the code on 2.0 and already translate to 1.0.

I will make an inheritance in order to not maintain an changed jme code.



Thank you all for the help!

or you could make a patch and post it :wink:

Yes, i will do it then!!



Where i can post it? Here or user code?

Finally here is the patch.

Index: ParticleGeometry.java
===================================================================
RCS file: /cvs/jme/src/com/jmex/effects/particles/ParticleGeometry.java,v
retrieving revision 1.11
diff -u -r1.11 ParticleGeometry.java
--- ParticleGeometry.java   21 Sep 2007 15:45:32 -0000   1.11
+++ ParticleGeometry.java   29 May 2008 01:16:22 -0000
@@ -94,6 +94,7 @@
     protected Ring psRing;
     protected boolean cameraFacing = true;
     protected boolean velocityAligned = false;
+    protected boolean particlesInWorldCoords = true;
    
     protected float startSize, endSize;
     protected ColorRGBA startColor;
@@ -959,6 +960,25 @@
     }
 
     /**
+    * @return true if the particles are already in world coordinate space
+    *         (default). When true, scene-graph transforms will only affect the
+    *         emission of particles, not particles that are already living.
+    */
+    public boolean isParticlesInWorldCoords() {
+      return particlesInWorldCoords;
+   }
+
+    /**
+     * true if the particles are already in world coordinate space
+    *         (default). When true, scene-graph transforms will only affect the
+    *         emission of particles, not particles that are already living.
+     * @param particlesInWorldCoords
+     */
+   public void setParticlesInWorldCoords(boolean particlesInWorldCoords) {
+      this.particlesInWorldCoords = particlesInWorldCoords;
+   }
+   
+    /**
      * Changes the number of particles in this particle mesh.
      *
      * @param count
@@ -988,13 +1008,17 @@
             }
         } else worldEmit.set(emissionDirection);
 
-        emitterTransform.set(worldRotation,
-            worldTranslation.divideLocal(worldScale));
-       
-        originCenter.set(worldTranslation).addLocal(originOffset);
-
-        getWorldTranslation().set(0,0,0);
-        getWorldRotation().set(0, 0, 0, 1);
+        if (particlesInWorldCoords) {
+           emitterTransform.set(worldRotation,
+               worldTranslation.divideLocal(worldScale));
+          
+           originCenter.set(worldTranslation).addLocal(originOffset);
+   
+           getWorldTranslation().set(0,0,0);
+           getWorldRotation().set(0, 0, 0, 1);
+        } else {
+           originCenter.set(originOffset);
+        }
     }
 
     public void write(JMEExporter e) throws IOException {
@@ -1076,5 +1100,4 @@
         rotMatrix = new Matrix3f();
         initializeParticles(numParticles);
     }
-
 }