I can't believe it worked!
(update: i had good reason to, it didnt haha. See below for an updated function)
Thanks a lot for finding that - only I read you message after an hour of two or mucking with trigonometry to no avail 🙂
This was my code (translated to objective-C)
-(bool) point:(SPPoint *)point inObject:(SPDisplayObject *)obj {
double c = cos(-obj.rotation * (PI/180));
double s = sin(-obj.rotation * (PI/180));
float rotatedX = obj.x + c * (point.x - obj.x) - s * (point.y - obj.y);
float rotatedY = obj.y + s * (point.x - obj.x) + c * (point.y - obj.y);
float leftX = obj.x - obj.width/2;
float rightX = obj.x + obj.width /2;
float topY = obj.y - obj.height /2;
float bottomY = obj.y + obj.height /2;
return (leftX <= rotatedX && rotatedX <= rightX && topY <= rotatedY && rotatedY <= bottomY);
}
This doesn't seem to be bad performance-wise; however I'll now try it in my game rather than a sandbox 😛
Thanks a lot for finding it.
WIKI LINK: http://wiki.sparrow-framework.org/tutorials/point_in_rotated_object