Hello!
I'm new to cocos2dx with spine and try to make a collision system in cocos2dx using bounding box of spine.
But I'm having trouble detectioning.
I have a question about source code around bounding box of spine of cocos2dx.
SkeletonBounds.c
int spPolygon_containsPoint (spPolygon* self, float x, float y) {
int prevIndex = self->count - 2;
int inside = 0;
int i;
for (i = 0; i < self->count; i += 2) {
float vertexY = self->vertices[i + 1];
float prevY = self->vertices[prevIndex + 1];
if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
float vertexX = self->vertices[i];
if (vertexX + (y - vertexY) / (prevY - vertexY) * (self->vertices[prevIndex] - vertexX) < x) inside = !inside;
}
prevIndex = i;
}
return inside;
}
I have a question about the following process of the above source code
if (vertexX + (y - vertexY) / (prevY - vertexY) * (self->vertices[prevIndex] - vertexX) < x)
I do not understand what this judgement formula is doing.
What this judgement formula is doing?