[osg-users] Change particle color !

b boltze con at bspot.de
Tue Sep 16 09:31:25 PDT 2008


Hi Mattias,

On Monday 18 August 2008 22:42:04 Mattias Helsing wrote:
> On Mon, Aug 18, 2008 at 8:44 PM, Carlos Sanches <cesmsp at gmail.com> wrote:
> > to do this I need to change the color of particles after your creation
> > only when I press the key.
>
> yes it is possible. You need an EventHandler and a osg::Timer.
> Set the color in EventHandler::handle(osgGA::FRAME).
>
> There is probably 10 other ways to do this also.

I have a similar problem and I fear I don't understand how this is supposed to 
work. Creating an EventHandler and a Timer is easy of course, but actually 
changing the particles' colors seems problematical to me:

Since the _current_* (alpha, color, etc.) attributes are protected in Particle 
and there are no setter functions, I can not change these values directly. I 
can only change the ranges, using set*Range. 

If the particles have limited lifetime, I can setColorRange or setAlphaRange 
on them, so they will fade out. But since they have already lived a portion 
of their lifetime, they won't start at the beginning of the given interval, 
but jump right into it, to the value corresponding to the percentage of their 
lifetime they have already spent. 

For example: A particle has already lived 9 seconds out of 10. Alpha range 
before the change was 1 to 1, so the particles alpha was 1. Then I set the 
alpha to range from 1 to 0, and the particle will immediately take an alpha 
value of 1+(0-1)*(9/10) = 0.1, assuming linear interpolation. 

If, on the other hand, the particle has infinite lifetime, I can't change its 
color or alpha at all, because immortal particles retrieve their current 
values from the interpolators only once, at their first rendering pass ever. 
So changing the ranges has no effect on them.

Did I miss something? 

Thanks for your help
	bastian



More information about the osg-users mailing list