polygonPoint static method
Implementation
static bool polygonPoint(PolygonShape b, Vector2 point) {
var collision = false;
// go through each of the vertices, plus the next
// vertex in the list
final vertices = b.points;
var next = 0;
for (var current = 0; current < vertices.length; current++) {
// get next vertex in list
// if we've hit the end, wrap around to 0
next = current + 1;
if (next == vertices.length) {
next = 0;
}
// get the PVectors at our current position
// this makes our if statement a little cleaner
final vc = vertices[current]; // c for "current"
final vn = vertices[next]; // n for "next"
// compare position, flip 'collision' variable
// back and forth
if (((vc.y > point.y && vn.y < point.y) ||
(vc.y < point.y && vn.y > point.y)) &&
(point.x < (vn.x - vc.x) * (point.y - vc.y) / (vn.y - vc.y) + vc.x)) {
collision = !collision;
}
}
return collision;
}