Otherwise known as a hard edge, this is a line over which the mouse cannot cross. Useful in games and the like.
Currently, I have a function that returns if my mouse cursor is in a polygon drawn on the screen. If it is not, I move my cursor to the last stored point that was in the polygon.
if (!PointInPolygon(local, polyGon))
{
Cursor.Position = safePoint;
}
else
{
safePoint = Cursor.Position;
}
I don't like this for a couple reasons:
Due to slow update times or for whatever reason, I am sometimes able to break out of the box. This then stores that position as the safePoint, outside of the polygon. My mouse is then stuck in this position.
Sloped edges should pust the mouse in the slope direction. Pushing the mouse right againts an "/" shaped wall should end up with the cursor in the top right corner. But due to the nature of this approach, going over the line will reset the cursor to where it previously was. Continuing to push right will only keep reseting the cursor, and will not push it "up the slope."
Are there any other approaches to tackle this problem? I'm mainly worried about the last issue: this slope transversal behavior is the main objective of my program and I need to get it working. Even if I use this basic method, any ideas for an optimization of that specific behavior?
EDIT:
It has been suggested by Reed that I instead return to the point that is CLOSEST to the current out-of-bounds point. Given the 4 corner points of a quadrilateral, how would I find the closest point in/on the shape?