Game Development Reference
In-Depth Information
Listing 7-46. Getting a Random Particle Velocity
Vector3 GetRandomParticleVelocity(int ParticleNumber, float MaxVelocity, float MinVelocity)
{
Vector3 ExplosionDirection = m_ExplosionDirection[ParticleNumber];
Vector3 ParticleVelocity= new Vector3(ExplosionDirection.x, ExplosionDirection.y,
ExplosionDirection.z);
float RandomVelocityMagnitude = MinVelocity + (MaxVelocity - MinVelocity)*
m_RandNumber.nextFloat();
ParticleVelocity.Multiply(RandomVelocityMagnitude);
return ParticleVelocity;
}
The StartExplosion() function is called to start the actual explosion at Position location with
particles with speeds from MinVelocity to MaxVelocity .
The StartExplosion() function (see Listing 7-47) does the following:
1.
Sets the m_ExplosionActive variable to true to indicate the explosion is in
progress
2.
Sets the particles in the explosion to active, which means that they will be
rendered and updated
3.
Sets the timestamp on all the particles to the current system time, which is
the start of the explosion
4.
Sets the position of all the particles to the input parameter Position
5.
Sets random velocities for all the particles
6.
Sets the scale of the particles to m_ParticleSize
7.
Sets a random color for all the particles, if random colors for the particles are
selected, to m_RandomColors = true ; otherwise, sets the color of the particle
to m_ParticleColor
8.
Sets the particle's life span time to m_ParticleLifeSpan
Listing 7-47. Starting the Explosion
void StartExplosion(Vector3 Position,float MaxVelocity, float MinVelocity)
{
// 1. Set Position of Particles
m_ExplosionActive = true;
for (int i = 0; i < m_NumberParticles; i++)
{
m_Particles[i].SetActiveStatus(true);
m_Particles[i].SetTimeStamp(System.currentTimeMillis());
m_ExplosionCenter = new Vector3(Position.x, Position.y, Position.z);
m_Particles[i].m_Orientation.SetPosition(m_ExplosionCenter);
 
Search WWH ::




Custom Search