Game Development Reference
In-Depth Information
14.3.2 Sample Application: Firework
Figure 14.3: A
screen shot of
the Firework
sample
The Firework system's class is defined as:
class Firework : public PSystem
{
public:
Firework(D3DXVECTOR3* origin, int numParticles);
void resetParticle(Attribute* attribute);
void update(float timeDelta);
void preRender();
void postRender();
};
The constructor takes a pointer to the origin of the system and the
number of particles that the system has. In this case, the origin of the
system refers to where the firework will explode.
The resetParticle method initializes a particle at the origin of
the system and creates a random velocity in a sphere. Each particle in
the Firework system is given a random color. Finally, we define that the
particle will live for two seconds.
void Firework::resetParticle(Attribute* attribute)
{
attribute->_isAlive = true;
attribute->_position = _origin;
D3DXVECTOR3 min = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
D3DXVECTOR3 max = D3DXVECTOR3( 1.0f, 1.0f, 1.0f);
d3d::GetRandomVector(
&attribute->_velocity,
&min,
&max);
Search WWH ::




Custom Search