Particle system child moving away

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
levante
Posts: 13
Joined: Wed Oct 11, 2006 1:03 pm
Contact:

Particle system child moving away

Post by levante »

Hello, I am trying to make very simple thing: a missile with his fire-thruster as a particle system. Though I think Irrlicht particle system is acting strange and I can't see my fault. Here is simple code I made for testing about this strange behaviour:

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace std;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

int main()
{

	IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 16,false, false, false, 0);
	device->setWindowCaption(L"Test Particle System");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

    /* Get the mesh of a rocket from "media" directory */
	IAnimatedMesh *meshMissile = smgr->getMesh("media/rocket.3ds");
    /* Create an animatedMeshSceneNode by default in 0,0,0 with the mesh of the rocket */
	IAnimatedMeshSceneNode *nodeMissile = smgr->addAnimatedMeshSceneNode( meshMissile );
	nodeMissile->setMaterialFlag(EMF_LIGHTING, false);

    /*
        Now create a particle system with the idea of being the rocket thruster.
        Since usually in a missile both thruster and rocket itself move all togheter
        I thought it was a good idea having particle system thruster as childNode of rocket.
        Rocket is directed inside the screen and fire of thruster should be directed out from his back.
        If we don't use any offset between father and child nodes, particle system will be inside rocket and maybe not visible
        so child node particle system should be positioned a little back relatively to his father. Anyway NOTHING is telling
        ANY NODE to MOVE from its position ok?
    */
    IParticleSystemSceneNode *nodoFireMissile = smgr->addParticleSystemSceneNode(false, nodeMissile, -1,vector3df(0.0,0.0,-1.0));
    nodoFireMissile->setParticleSize(dimension2d<f32>(2.0,2.0));
    IParticleEmitter *emitterFireMissile = nodoFireMissile->createPointEmitter(
        vector3df(0.000f,0.00f,-0.009f),
        70,85, SColor(0, 255, 255, 255), SColor(0, 255, 255, 0), 200, 700, 2);
    nodoFireMissile->setEmitter(emitterFireMissile);
    emitterFireMissile->drop();

	if (nodoFireMissile) {
        nodoFireMissile->setMaterialFlag(EMF_LIGHTING, false);
        nodoFireMissile->setMaterialTexture(0, driver->getTexture("media/ParticleFire.tga"));
        nodoFireMissile->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
	}

	smgr->addCameraSceneNode(0, vector3df(0,20,-25), vector3df(0,5,0));

	while(device->run())
	{
		driver->beginScene(true, true, SColor(0,200,200,200));
		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}
	device->drop();
	return 0;
}
As explained in comment I use father and child relationship with rocket and particle system to have the effect of a missile thruster. I already used this technique with different engines placing a little offset between father and child in order to position thuster particle system back to the rocket.
Though the strange thing is that if I use an offset vecto3df in addParticleSystemSceneNode method, the particle system unexpectly moves away from his father and keep moving far and far. If I don't use offset in addParticleSystemSceneNode method, the particle system doesn't move yet it is exactly at the same coords as rocket so it apper inside rocket. If I try to manually position child I get the same moving away effect. Another strange thing is that the speed of how fast the child node moves away is proportional to vector3df of direction in createPointEmitter method, that is if I use a direction vector3df(0.0f,0.0f,0.0f) while creating emitter, particle system doesn't move from his father but this way I loose the "fire effect".So this is what happens:

Program starts:
Image

After one second or two:
Image

Medias for this testing prgram can be downloaded here:
http://www.manicomio.org/levante/media.zip

Please help me, I think Particle system should behave differently :-(

Marco
[/img][/url][/code]
Marco Del Percio
levante
Posts: 13
Joined: Wed Oct 11, 2006 1:03 pm
Contact:

Post by levante »

I have studied the problem deep and I haven't understood why does it happen but it seems I have found a pretty, light and easy workaround. I'll post some material to explain everything this evening.
Marco Del Percio
levante
Posts: 13
Joined: Wed Oct 11, 2006 1:03 pm
Contact:

[WORKAROUND] Particle system child moving away

Post by levante »

Hi all. Here is how to workaround:

So I haven't understood why but this workaround works ;-)
You all have seen what does it happen with previous code. If you repeat experiment using the same code with just replacing:

Code: Select all

IParticleSystemSceneNode *nodoFireMissile = smgr->addParticleSystemSceneNode(false, nodeMissile, -1,vector3df(0.0,0.0,-1.0)); 
    nodoFireMissile->setParticleSize(dimension2d<f32>(2.0,2.0)); 
    IParticleEmitter *emitterFireMissile = nodoFireMissile->createPointEmitter( 
        vector3df(0.000f,0.00f,-0.009f), 
        70,85, SColor(0, 255, 255, 255), SColor(0, 255, 255, 0), 200, 700, 2);
With this very similar:

Code: Select all

IParticleSystemSceneNode *nodoFireMissile = smgr->addParticleSystemSceneNode(false, nodeMissile, -1,vector3df(0.5,0.0,-8.0));
    nodoFireMissile->setParticleSize(dimension2d<f32>(2.0,2.0));
    IParticleEmitter *emitterFireMissile = nodoFireMissile->createBoxEmitter(
        core::aabbox3d<f32>(-0.5,-0.5,-0.5,0.5,0.5,0.5),
        vector3df(0.000f,0.00f,-0.009f),
        70,85, SColor(0, 255, 255, 255), SColor(0, 255, 255, 0), 200, 700, 2);
This time you will see particle system thruster as child of missile node but NOT moving away :-) you'll see thruster fire just back missile and not in movement and I even tried moving for example missile node forward, it keeps its child perfectly without any need of changing direction or rebuilding system/emitter.

Image

The trick is simply to use a box emitter with very little box (like core::aabbox3d<f32>(-0.5,-0.5,-0.5,0.5,0.5,0.5) ) so that is very similar to Point Emitter but for unknown reasons in this way you can use child-father relationship without problems while Point Emitter is acting very strange.
THIS IS A WORKAROUND NOT A SOLUTION!! I WOULD LIKE TO WARN NIKO/AUTHOR TO LOOK FOR THIS KIND OF BUG AND SEE WHY POINT EMITTER IS ACTING SO STRANGE :wink: [/img]
Marco Del Percio
funcdoobiest
Posts: 48
Joined: Thu Jun 15, 2006 6:35 pm

Post by funcdoobiest »

I forgot to post about this but I had the same problem some time ago before I realsised that it was a box emitter I really weanted anyway! But I couldn't figure out the original problem of the positioning of the emitter node messing up the particle emission.
Post Reply