Game Development Reference
In-Depth Information
Gl.glColor3f(color.Red, color.Green, color.Blue);
Gl.glBegin(Gl.GL_LINES);
{
for (int i = 0; i < _sampleSize; i ++)
{
// Work out new X and Y positions
double newX = previousX + xIncrement; // Increment one unit on the x
// From 0-1 how far through plotting the graph are we?
double percentDone = (i / _sampleSize);
double percentRadians = percentDone * (Math.PI * _frequency);
// Scale the wave value by the half the length
double newY = _yPosition + waveFunction(percentRadians) *
(_yLength / 2);
// Ignore the first value because the previous X and Y
// haven't been worked out yet.
if (i > 1)
{
Gl.glVertex2d(previousX, previousY);
Gl.glVertex2d(newX, newY);
}
// Store the previous position
previousX = newX;
previousY = newY;
}
}
Gl.glEnd();
} // Empty Update and Render methods omitted
}
The member variables _xPosition , _yPosition , _xLength , and
_yLength are used to position and describe the size of the graph. The
smoothness of the graph is determined by the _sampleSize variable. The
sample size is the number of vertices used to draw the line of the graph. Each
vertex y position is determined by a particular wave function such as sine or
cosine. The _frequency variable is used to determine how often the wave will
oscillate, the higher the frequency the greater the number of oscillations.
 
Search WWH ::




Custom Search