Game Development Reference
In-Depth Information
The UpdateParticle() function (see Listing 7-40) updates the particle in the following way:
If the particle is active, that is m_Active = true , then it continues with the
update; otherwise, it returns.
1.
2.
It applies a rotational force to the particle.
3.
It updates the physics of the particle.
4.
If the time that passes since the particle was created is greater than the
particle life span, which is m_TimeDelay , it destroys the particle by calling
Destroy() . Otherwise, it calls FadeColor() to fade the color of the particle
toward black.
Listing 7-40. Updating the Particle
void UpdateParticle(long current_time)
{
// If particle is Active (on the screen)
if (m_Active)
{
// Update Particle Physics and position
GetObjectPhysics().ApplyRotationalForce(40, 1);
GetObjectPhysics().UpdatePhysicsObject(m_Orientation);
long TimePassed = current_time - m_TimeStamp;
if (TimePassed > m_TimeDelay)
{
// Destroy Particle
Destroy();
}
else
{
FadeColor(TimePassed);
}
}
}
The Render() function draws the particle to the screen by calling DrawObject() , located in the
Object3d class. (See Listing 7-41.)
Listing 7-41. Rendering a Particle
void Render(Camera Cam, PointLight light)
{
DrawObject(Cam, light);
}
Creating the SphericalPolygonExplosion Class
Next, we have to create the class that represents our explosion, which is the
SphericalPolygonExplosion class. What this class does is create a group of PolyParticleEx
polygons and uses them to create an explosion.
 
Search WWH ::




Custom Search