particle gravity affector

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
riveranb
Posts: 28
Joined: Fri Sep 23, 2011 9:37 am

particle gravity affector

Post by riveranb »

Hi, everyone,
I think maybe I can share some experiences on my graphics coding about irrlicht.

I want to talk about the CParticleGravityAffector. The original version is as below:

Code: Select all

 
void CParticleGravityAffector::affect(u32 now, SParticle* particlearray, u32 count)
{
        if (!Enabled)
                return;
        f32 d;
        for (u32 i=0; i<count; ++i)
        {
                d = (now - particlearray[i].startTime) / TimeForceLost;
                if (d > 1.0f)
                        d = 1.0f;
                if (d < 0.0f)
                        d = 0.0f;
                d = 1.0f - d;
                particlearray[i].vector = particlearray[i].startVector.getInterpolated(Gravity, d);
        }
}
 
And I think it's better to modify the particle position with consideration to newton's movement law.

// approximate the newton's low
// X = V0 * t + (a + g) * t * t/2
particle-pos = ( particle-vector * ratio + gravity) * t * t / 2;
ratio is to decrease the influence of the particle-vector (as the a component)

I think I got better approximation of gravity this way.

Sorry for some reason, I modify the article to skip some source codes.
Last edited by riveranb on Tue Nov 29, 2011 10:35 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: particle gravity affector

Post by CuteAlien »

Hm, should probably rather offer both options, otherwise the effects from people already using this are broken.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: particle gravity affector

Post by Cube_ »

nice ;)
"this is not the bottleneck you are looking for"
Post Reply