Game Development Reference
In-Depth Information
For the purposes of demonstrating intersection, it would be nice to able to color
the circles. A white circle could be a non-intersected circle and a red circle could
indicate that it intersects with something. This is an easy addition to make. In the
Circle class, modify the code so it has a color member that is used in the Draw
function.
Color _color = new Color(1, 1, 1, 1);
public Color Color
{
get { return _color; }
set { _color = value; }
}
public void Draw()
{
Gl.glColor3f(_color.Red, _color.Green, _color.Blue);
By default, all circles will be rendered white but the color can be changed at
any time.
Circle-point intersection was covered in the vector section. The distance of the
point from the circle origin is calculated; if that distance is greater than the circle
radius, then it lies outside of the circle. To test this graphically, the mouse pointer
can be used as the point.
Getting the position of the mouse pointer is a little tricky because of the different
coordinate systems involved. The OpenGL origin is in the middle of the form but
the cursor's position is not in the same coordinate system; its origin is the very
top left of the form. This means OpenGL considers the position 0, 0 to be a point
in the middle of the form while the cursor considers 0,0 to be the very top left of
the form. These different coordinate systems are shown in Figure 8.19. The form
coordinate origin is labeled a, the control coordinate is labeled b, and the
OpenGL coordinate origin is labeled c. To convert the mouse pointer from
the form coordinate system to the OpenGL coordinate system a little more code
needs to be added to the form.
The first thing we need is a simple Input class to record the mouse input.
public class Input
{
public Point MousePosition { get; set; }
}
Search WWH ::




Custom Search