need help with rotating stuff

Monkey Forums/Monkey Programming/need help with rotating stuff

Duke87(Posted 2015) [#1]
Hey Monks,

I got a little Problem over here.

I have a "GetMouseOverBox" (X,Y are Midhandled like my Images, so I can rotate them easily) Function like :
Function MOBox:Bool(_X:Float, _Y:Float, _Width:Float, _Height:Float)
	If (_X-_Width/2.0) < MouseX() And _X + _Width/2.0 > MouseX() And (_Y-_Height/2.0) < MouseY() And (_Y + _Height/2.0) > MouseY()
		Return True
	Else
		Return False
	Endif
End Function


And now I let them Rotate within the OnRender like:

...
RotateAt(X,Y,Angle)
DrawImage MyImg, X,Y,0,pxlX/MyImg.Width(),pxlY/MyImg.Height()
ResetMatrix()

So far, so fine.

But when i want to check for a 'MouseOver' within the OnUpdate like:

...
if MOBox(X,Y,Width,Height)
...

or
RotateAt(X,Y, Angle)
If MOBox(X,Y,Width,Height)
...
ResetMatrix()

it both uses the 'unrotated' rect of my MOBox() function

How do i Check for a Mouseover within a rotated rectangle?


If needed my Rotate-func.
Function RotateAt:Void(x:Float, y:Float, angle:Float)
    Translate(x, y)
    Rotate(angle)
    Translate(-x, -y)
End
Function ResetMatrix:Void()
    SetMatrix(1,0,0,1,0,0)
End



Midimaster(Posted 2015) [#2]
This sample shows, that a rotation command does not affect the mouse coordinates:



You have to invent a GetMouseOverBox() function which calculates the true rectangle of the rotated box. GetMatrix() will help you finding aut the current rotation angle. Sin() and Cos() will be need to calculate the borders.


MikeHart(Posted 2015) [#3]
This is my method inside fE for checking if a touch is inside a rotated box. You should easily be able to adapt it:




Duke87(Posted 2015) [#4]
Thank you,

will have a look at this.