Game Development Reference
In-Depth Information
public class Circle
{
Vector Position { get; set; }
double Radius { get; set; }
public Circle()
{
Position = Vector.Zero;
Radius = 1;
}
public Circle(Vector position, double radius)
{
Position = position;
Radius = radius;
}
public void Draw()
{
// Determines how round the circle will appear.
int vertexAmount = 10;
double twoPI = 2.0 * Math.PI;
// A line loop connects all the vertices with lines
// The last vertex is connected to the first vertex
// to make a loop.
Gl.glBegin(Gl.GL_LINE_LOOP);
{
for (int i = 0; i <= vertexAmount; i++)
{
double xPos = Position.X + Radius * Math.Cos(i * twoPI /
vertexAmount);
double yPos = Position.Y + Radius * Math.Sin(i * twoPI /
vertexAmount);
Gl.glVertex2d(xPos, yPos);
}
}
Gl.glEnd();
}
}
By default, a circle is defined to be at the origin and to have a radius of 1 unit. The
drawing code is currently missing. The circle will be drawn using OpenGL
Search WWH ::




Custom Search