Game Development Reference
In-Depth Information
public class Rectangle
{
Vector BottomLeft { get; set;}
Vector TopRight { get; set; }
Color _color = new Color(1, 1, 1, 1);
public Color Color
{
get { return _color; }
set { _color = value; }
}
public Rectangle(Vector bottomLeft, Vector topRight)
{
BottomLeft = bottomLeft;
TopRight = topRight;
}
public void Render()
{
Gl.glColor3f(_color.Red, _color.Green, _color.Blue);
Gl.glBegin(Gl.GL_LINE_LOOP);
{
Gl.glVertex2d(BottomLeft.X, BottomLeft.Y);
Gl.glVertex2d(BottomLeft.X, TopRight.Y);
Gl.glVertex2d(TopRight.X, TopRight.Y);
Gl.glVertex2d(TopRight.X, BottomLeft.Y);
}
Gl.glEnd();
}
}
The rectangle class can create and draw rectangles. The only function missing
is the all important intersect function.
public bool Intersects(Point point)
{
if (
point.X >= BottomLeft.X &&
point.X <= TopRight.X &&
point.Y <= TopRight.Y &&
point.Y >= BottomLeft.Y)
Search WWH ::




Custom Search