Game Development Reference
In-Depth Information
// Generate random x,y,z coords
Vector3 direction = new Vector3(0,0,0);
direction.x = randomx;
direction.y = randomy;
direction.z = randomz;
direction.Normalize();
// Set Particle Explosion Direction Array
m_ExplosionDirection[i] = direction;
// Create New Particle
m_Particles[i] = new PolyParticleEx(iContext, iMesh, iMeshEx, iTextures,
iMaterial, iShader);
// Set Particle Array Information
if (RandomColors)
{
m_Particles[i].SetColor(GenerateRandomColor());
}
else
{
m_Particles[i].Create(m_ParticleColor);
}
m_Particles[i].SetTimeDelay(ParticleLifeSpan);
m_Particles[i].SetFadeDelta(FadeDelta);
// Generate Random Rotations
Vector3 Axis = GenerateRandomRotationAxis();
m_Particles[i].m_Orientation.SetRotationAxis(Axis);
float rot = GenerateRandomRotation(360);
m_Particles[i].m_Orientation.SetRotationAngle(rot);
}
}
The GetRandomParticleVelocity() function (see Listing 7-46) creates and returns a random velocity
based on the pdirection that the particle was set when the explosion was created and a random speed.
The function does the following:
1.
Gets the normalized direction of particle ParticleNumber from the
m_ExplosionDirection array
2.
Creates a new vector variable, ParticleVelocity , to hold the final particle
velocity and initializes it with the explosion direction found in step 1
3.
Generates a random speed for the particle between the MinVelocity and
MaxVelocity input parameters
4.
Calculates the final new random particle velocity by multiplying the
ParticleVelocity variable that holds the direction of the particle by the
random speed in the RandomVelocityMagnitude variable
 
Search WWH ::




Custom Search