Graphics Question: How do I restrict the mouse cursor to within a circle?

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-05-17T21:24:15Z Indexed on 2010/05/17 21:30 UTC
Read the original article Hit count: 127

Filed under:
|
|

I'm playing with XNA. When I click the left mouse button, I record the X,Y co-ordinates. Keeping the mouse button held down, moving the mouse draws a line from this origin to the current mouse position. I've offset this into the middle of the window.

Now, what I'd like to do is restrict the mouse cursor to within a circle (with a radius of N, centred on the middle of the screen). Restricting the mouse to a rectangular region is easy enough (by adjusting the origin by the difference of the mouse position and the size of the region), but I haven't a clue on how to start doing it for a circular region.

Can anyone explain how to do this? Any advice on where to start would be helpful.

© Stack Overflow or respective owner

Related posts about graphics

Related posts about XNA