// Copyright (C) 2002-2009 Nikolaus Gebhardt // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CParticleCylinderEmitter.h" #include "os.h" namespace irr { namespace scene { //! constructor CParticleCylinderEmitter::CParticleCylinderEmitter( const core::vector3df& center, f32 radius, const core::vector3df& normal, f32 length, bool outlineOnly, const core::vector3df& direction, u32 minParticlesPerSecond, u32 maxParticlesPerSecond, const video::SColor& minStartColor, const video::SColor& maxStartColor, u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees, const core::dimension2df& minStartSize, const core::dimension2df& maxStartSize ) : Center(center), Normal(normal), Direction(direction), MaxStartSize(maxStartSize), MinStartSize(minStartSize), MinParticlesPerSecond(minParticlesPerSecond), MaxParticlesPerSecond(maxParticlesPerSecond), MinStartColor(minStartColor), MaxStartColor(maxStartColor), MinLifeTime(lifeTimeMin), MaxLifeTime(lifeTimeMax), Radius(radius), Length(length), Time(0), Emitted(0), MaxAngleDegrees(maxAngleDegrees), OutlineOnly(outlineOnly) { #ifdef _DEBUG setDebugName("CParticleCylinderEmitter"); #endif } //! Prepares an array with new particles to emitt into the system //! and returns how much new particles there are. s32 CParticleCylinderEmitter::emitt(u32 now, u32 timeSinceLastCall, SParticle*& outArray) { Time += timeSinceLastCall; const u32 pps = (MaxParticlesPerSecond - MinParticlesPerSecond); const f32 perSecond = pps ? (f32)MinParticlesPerSecond + (os::Randomizer::rand() % pps) : MinParticlesPerSecond; const f32 everyWhatMillisecond = 1000.0f / perSecond; if(Time > everyWhatMillisecond) { Particles.set_used(0); u32 amount = (u32)((Time / everyWhatMillisecond) + 0.5f); Time = 0; SParticle p; if(amount > MaxParticlesPerSecond*2) amount = MaxParticlesPerSecond * 2; for(u32 i=0; i