Game Development Reference
In-Depth Information
The m_RandNumber variable is used to generate random numbers.
private Random m_RandNumber = new Random();
The GenerateRandomColor() function generates and returns a random color using m_RandNumber . The
nextFloat() function generates and returns a random number in the range of 0-1. (See Listing 7-42.)
Listing 7-42. Generating a Random Color
Vector3 GenerateRandomColor()
{
Vector3 Color = new Vector3(0,0,0);
// 1. Generate Random RGB Colors in Range of 0-1;
Color.x = m_RandNumber.nextFloat();
Color.y = m_RandNumber.nextFloat();
Color.z = m_RandNumber.nextFloat();
return Color;
}
The GenerateRandomRotation() function generates and returns the value of a random rotation in the
range 0-MaxValue. (See Listing 7-43.)
Listing 7-43. Generating a Random Rotation
float GenerateRandomRotation(float MaxValue)
{
float Rotation;
// 1. Generate Random Rotation in Range of 0-1 * MaxValue;
Rotation = MaxValue * m_RandNumber.nextFloat();
return Rotation;
}
The GenerateRandomRotationAxis() function generates and returns a normalized randomly
generated rotation axis. (See Listing 7-44.)
Listing 7-44. Generating a Random Rotation Axis
Vector3 GenerateRandomRotationAxis()
{
Vector3 RotationAxis = new Vector3(0,0,0);
// 1. Generate Random Rotation in Range of 0-1
RotationAxis.x = m_RandNumber.nextFloat();
RotationAxis.y = m_RandNumber.nextFloat();
RotationAxis.z = m_RandNumber.nextFloat();
RotationAxis.Normalize();
return RotationAxis;
}
 
Search WWH ::




Custom Search