bool AgeSizeParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps) { if(getMFAges()->size()!=getMFSizes()->size()) { return false; } else { Real32 time; UInt32 i(0); Real32 Age(System->getAge(ParticleIndex)),Lifespan(System->getLifespan(ParticleIndex)); if(Lifespan < 0.0) { return false; } time = (Age)/(Lifespan); for( ;i<getMFAges()->size() && time>getAges(i);++i) { } if(i == getMFSizes()->size()) { System->setSize(getMFSizes()->back(),ParticleIndex); } else if(i == 0.0) { System->setSize(getMFSizes()->front(),ParticleIndex); } else { Vec3f size; time = (time - getAges(i-1))/(getAges(i)-getAges(i-1)); lerp(getSizes(i-1),getSizes(i),time,size); System->setSize(size,ParticleIndex); } } return false; }
bool AgeFadeParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps) { Real32 Alpha(0.0f); if(System->getAge(ParticleIndex)<getFadeInTime()) { lerp<Real32>(getStartAlpha(), getFadeToAlpha(),1.0f-((getFadeInTime() - System->getAge(ParticleIndex))/getFadeInTime()), Alpha); } else if(System->getLifespan(ParticleIndex) < 0 || (System->getAge(ParticleIndex)< System->getLifespan(ParticleIndex)-getFadeOutTime())) { Alpha = getFadeToAlpha(); } else { //lerp lerp<Real32>(getFadeToAlpha(), getEndAlpha(), ((System->getAge(ParticleIndex)-System->getLifespan(ParticleIndex)+getFadeOutTime())/(getFadeOutTime())), Alpha); } Color4f Color = System->getColor(ParticleIndex); Color[3] = Alpha; System->setColor(Color, ParticleIndex); return false; }