Detect mouse intersect for rotated objects

Hello,

I have button that I want to rotate in animation. How do I check if mouse is on top of rotated button?
I am not using rectangle currently but simple X,Y checks. I am rotating button in draw call of SpriteBatch. I know Sprite Batch handles only drawing on screen and has nothing to do with Input logic but Rectangle doesn’t seem to have rotate function.

I am using framework for few days for simple project. Online sources were okay for me to create my own UI library and animation system but this seems to elude me.

you are talking about collision detection, detecting if a point is inside a rotated rectangular button, which is being drawn on a vector2, is that right?

…One easy way conceptually is to get the color of the pixel beneath the mouse, and have a unique color for the button, so if the cursor samples “green” you know they hit “go”…

… Another way I have used, is to define geometry like your button as a list of vector2s, one for each corner… Basically use a list of vector2s to represent your shapes…
Then you test the cursors pos against each imaginary line between the 4 corners, and if the cursor is ABOVE each line in your polygon, it must be inside your polygon…
-You can even move the vectors in real time, rotate their position around an axis, etc…
The math for detecting if a point is above or below 2 other points, is like a c-levels formula, which you an look up online easily… -You just run that math on all the lines in your shape, comparing your mouse point to each, and if it is above every line, you are inside.

-This requires you to avoid concave shapes… ie some complex geometry must be split into primitives / multiple parts.

Both approaches have served me well, and once implemented, are REALLY flexible, and have been used in games for a LONG time.

I hope you didn’t give up :slight_smile:

I can guide you through the process in more detail, or finer steps, if I got too confusing.