Hi,
I'm just writing a fireworks simulator. Until now, everything works fine but now I want to implement a rocket which explodes two times: after some time, the particles of the first Explosion should explode a second time.
For that I need to know the Localtranslations of every Particle in relation to the explosion center.
But when I grab them by using Explosion.getParticle(0).getPosition() for example, I get some weird coordinates that make no sense for me. The values in there are ten times bigger than the Localtranslation of the explosion itself.
How can I get my translation from these numbers or is there another way to archieve that?
cu
Cyre
as far as i know, particles are usually released into world coordinates, so they don't have a relationship with its particlesystem anymore.
But why do you need to localTranslation of the particle? You want to create another explosion at the location of the particle, so you need its world location anyway no?
The particle files are attached to a single node which holds the localTranslation, so it would be nice if I set the localTranslation of the secondary explosions. But that would not be the problem.
But now how can I set the world coordinates of a ParticleMesh/Node? I cannot find any function like "setWorldCoordinates" to do this. I just tried with ParticleMesh.setWorldEmit, but it seems not to have any effect.
I also tried to calculate the translation by subtracting the translation of the rocket-node (which is attached directly to the root-Node) from the particle position. But also this seems not to be correct, the coords are far away from the explosion.
maybe particlesMesh.setOriginOffset() helps.
if the particleMesh's local and worldtranslation is 0 (not attached to any moved node), you should be able to set the originoffset (or local translation sould work too i guess) to the particles world translation.
If it dosen't work out, try to make a simple as possible testcase,
Hi,
I just tried it out and it seems to work a bit better. The explosions are now inside the first explosion, but not at the right position. Maybe this is a scaling problem - but I dont know how to make the secondary explosions look smaller without scaling them.
I attached a testcase to this post, maybe this will help you…
The file is a .zip but I had to rename it to .txt so I could attach it here. Just download it and rename it back to .zip so it should work.
says its an corrupt zip file.
A simple (simplegame) testcase shouldn't be to big to post as code here tho.
The problem is that I'm using an external .jme file to load the particles, so you need that file too to make the testcase work.
I uploaded it now to a ftp server of mine, you can download the file archive here:
http://www.manzana.homepage.t-online.de/Manzanas/testcase.zip
I tried it out on my system (ubuntu 8.10) and I was able to download & unpack the files from there. Hope it works for you too…
the issue seems to be the downscaling of the secondaries.
You need to multiply the offset with 1/scale.
secondarys[i].setOriginOffset(pos.mult(1/secondaryScale));
There is another thing:
You are spawning a new thread where you attach a new explosion to the scene.
Thats usually a bad idea and can result in index out of bound exceptions and such.
Better use a Controller instead of the TimedTask.
This is a modified example, the location of the single particles still seems to be off a bit.
package particle;
import java.net.URISyntaxException;
import java.util.Timer;
import java.util.TimerTask;
import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.shape.Box;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.util.TextureManager;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleMesh;
import com.jmex.effects.particles.SimpleParticleInfluenceFactory;
public class TestFireworks extends SimpleGame {
float secondaryScale = 0.3f;
ParticleMesh primary;
ParticleMesh[] secondarys = new ParticleMesh[20];
Box[] secondaryPos = new Box[20];
protected void simpleInitGame() {
try {
ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(TestFireworks.class
.getResource("/jmetest/data/texture/")));
ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_PARTICLE,
new SimpleResourceLocator(TestFireworks.class
.getResource("/particle/")));
} catch (URISyntaxException e) {
e.printStackTrace();
}
loadParticles();
System.out.println(primary);
rootNode.attachChild(primary);
cam.setLocation(new Vector3f(0, -50, 200));
cam.update();
final Timer t = new Timer();
TimerTask task = new TimerTask() {
public void run() {
shoot();
}
};
t.schedule(task, 300, 4000);
}
private void shoot() {
primary.forceRespawn();
final Timer t = new Timer();
TimerTask task = new TimerTask() {
public void run() {
attachSecondarys();
t.cancel();
}
};
t.schedule(task, 2000, 200);
}
private void attachSecondarys() {
for (int i = 0; i < secondarys.length; i++) {
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
Vector3f pos = primary.getParticle(i).getPosition();
secondarys[i].setOriginOffset(pos.mult(1/secondaryScale));
// secondaryPos[i] = new Box("", pos, 0.5f, 0.5f, 0.5f);
// rootNode.attachChild(secondaryPos[i]);
rootNode.attachChild(secondarys[i]);
secondarys[i].forceRespawn();
rootNode.updateRenderState();
}
}
private void loadParticles() {
primary = createExplosion();
for (int i = 0; i < secondarys.length; i++) {
secondarys[i] = createExplosion();
secondarys[i].setLocalScale(secondaryScale);
}
}
public static void main(String[] args) {
SimpleGame app = new TestFireworks();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
private ParticleMesh createExplosion() {
BlendState blendState = display.getRenderer().createBlendState();
blendState.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
blendState.setDestinationFunction(BlendState.DestinationFunction.One);
blendState.setBlendEnabled(true);
TextureState texState = display.getRenderer().createTextureState();
Texture tex = TextureManager.loadTexture(ResourceLocatorTool.locateResource(
ResourceLocatorTool.TYPE_TEXTURE, "spark.jpg"));
texState.setTexture(tex);
ZBufferState zbufferState = display.getRenderer().createZBufferState();
zbufferState.setWritable(false);
final ParticleMesh particleGeom = ParticleFactory.buildParticles("explosion", 30);
// add a gravity effect to the particle effect
particleGeom.addInfluence(SimpleParticleInfluenceFactory.createBasicGravity(new Vector3f(0, -1.00f, 0), true));
particleGeom.setEmissionDirection(new Vector3f(0.0f, 1.0f, 0.0f));
// allow to shoot particles in all directions (360