Game Development Reference
In-Depth Information
bool inside=false;
size_t points = polygon.size();
// The polygon must at least be a triangle
if (points < 3)
return false;
oldPoint = polygon[points-1];
for (unsigned int i=0 ; i < points; i++)
{
newPoint = polygon[i];
if (newPoint.x > oldPoint.x)
{
left = oldPoint;
right = newPoint;
}
else
{
left = newPoint;
right = oldPoint;
}
// A point exactly on the left side of the polygon
// will not intersect - as if it were
”
if ((newPoint.x < test.x) == (test.x <= oldPoint.x)
&& (test.y-left.y) * (right.x-left.x)
< (right.y-left.y) * (test.x-left.x) )
“
open
{
inside=!inside;
}
oldPoint = newPoint;
}
return(inside);
}
Controls have four states: active, highlighted, pressed, and disabled, as shown in Fig-
ure 10.3. An active control is able to receive events, but it isn
'
t the center of attention.
When the control gets the focus or passes a hit test from the pointing device, its state
changes to highlighted. It
s common for highlighted controls to have separate art or
even a looping animation that plays as long as it has focus.
'