Game Development Reference
In-Depth Information
Vertex A returns 4 as stated. But, if we try the same thing for vertex B we
get a count of 3, so the vertex is not inside the polygon.
BOOL PointInPolygon(POINT &p, POLYGON &ply){
int count = 0, q1, q2;
EDGE *e;
for (i=0; i<ply.numedges; i++){
e = &ply.edge[i];
//Get quadrant for first edge vertex
if (e->a.y>p.y){
q1 = (e->a.x>p.x)?0:1;
}else{
q1 = (e->a.x<p.x)?2:3;
}
//Get quadrant for second edge vertex
if (e->b.y>p.y){
q2 = (e->b.x>p.x)?0:1;
}else{
q2 = (e->b.x<p.x)?2:3;
}
if (q1!=q2){
switch(q1){
case 0:
if (q2==1){
count-;
}else{
count++;
}
break;
case 1:
if (q2==2){
count-;
}else{
count++;
}
break;
case 2:
if (q2==3){
count-;
}else{
Search Nedrilad ::




Custom Search