Game Development Reference
In-Depth Information
float d3d::GetRandomFloat(float lowBound, float highBound)
{
if( lowBound >= highBound ) // bad input
return lowBound;
// get random float in [0, 1] interval
float f = (rand() % 10000) * 0.0001f;
// return float in [lowBound, highBound] interval.
return (f * (highBound - lowBound)) + lowBound;
}
This next function outputs a random vector in the box defined by its
minimum point min and maximum point max .
void d3d::GetRandomVector(
D3DXVECTOR3* out,
D3DXVECTOR3* min,
D3DXVECTOR3* max)
{
out->x = GetRandomFloat(min->x, max->x);
out->y = GetRandomFloat(min->y, max->y);
out->z = GetRandomFloat(min->z, max->z);
}
Note: Remember to seed the random number generator using
srand() .
14.3 Concrete Particle Systems:
Snow, Firework, Particle Gun
Now let's derive several concrete particle systems from PSystem .
These systems have been kept simple by design for illustration pur-
poses and do not take advantage of all the flexibility that the PSystem
class provides. We implement Snow, Firework, and Particle Gun sys-
tems. These systems' names pretty much sum up the system that they
model. The Snow system models falling snowflakes. The Firework sys-
tem models an explosion that looks like a firework. The Particle Gun
system fires particles out from the camera's position in the direction
that the camera is looking based on a keypress; this makes it look like
we are firing “particle bullets” and could be used as a foundation for a
gun system in a game.
Note: As usual, the complete code projects illustrating these sys-
tems can be found in the companion files for this chapter.
Search WWH ::




Custom Search