public override void InitParticle( Particle particle )
{
float xOff, yOff, zOff;
// First we create a random point inside a bounding cylinder with a
// radius and height of 1 (this is easy to do). The distance of the
// point from 0,0,0 must be <= 1 (== 1 means on the surface and we
// count this as inside, too).
while ( true )
{
// three random values for one random point in 3D space
xOff = Utility.SymmetricRandom();
yOff = Utility.SymmetricRandom();
zOff = Utility.SymmetricRandom();
// the distance of x,y from 0,0 is sqrt(x*x+y*y), but
// as usual we can omit the sqrt(), since sqrt(1) == 1 and we
// use the 1 as boundary. z is not taken into account, since
// all values in the z-direction are inside the cylinder:
if ( xOff * xOff + yOff * yOff <= 1 )
{
// found one valid point inside
break;
}
}
// scale the found point to the cylinder's size and move it
// relatively to the center of the emitter point
particle.Position = position + xOff * xRange + yOff * yRange * zOff * zRange;
// Generate complex data by reference
GenerateEmissionColor( ref particle.Color );
GenerateEmissionDirection( ref particle.Direction );
GenerateEmissionVelocity( ref particle.Direction );
// Generate simpler data
particle.timeToLive = GenerateEmissionTTL();
}