rotate image using mouse

BlitzMax Forums/BlitzMax Programming/rotate image using mouse

Qweeg(Posted 2005) [#1]
Could someone tell me how to rotate an image using the mouse please? I found a note saying that you could use ATAN2 to do this but I can only get it to allow rotation between 0 and 90 degrees, as in this text example:

Graphics 800,600
SetColor 255,255,255

SetOrigin(GraphicsWidth()/2,GraphicsHeight()/2)
HideMouse()

Local varx : Float
Repeat

	SetRotation ATan2(MouseY(),MouseX())
	varx = GetRotation()
	DrawText "rotation = " + String(varx), 10,10
	Flip
	Cls

Until KeyHit(key_escape) = 1


Many thanks,
Tim


Eric(Posted 2005) [#2]
Graphics 800,600
SetColor 255,255,255

'SetOrigin(GraphicsWidth()/2,GraphicsHeight()/2)
HideMouse()

Local varx : Float
Repeat

SetRotation ATan2((MouseY()-GraphicsWidth()/2), MouseX()-(GraphicsHeight()/2))
varx = GetRotation()
DrawText "rotation = " + String(varx), GraphicsWidth()/2,GraphicsHeight()/2
Flip
Cls

Until KeyHit(key_escape) = 1


tonyg(Posted 2005) [#3]
ATAN2 needs the difference between target and source coords where you're only using the target coords in mousex() and mousey()
Could be neater...
Graphics 800,600
SetColor 255,255,255

SetOrigin(GraphicsWidth()/2,GraphicsHeight()/2)
'HideMouse()

Local varx : Float
Repeat
    mx=MouseX()
    my=MouseY()
    x1 = mx-400
    y1 = my-300
	SetRotation ATan2(y1,x1)
	varx = GetRotation()
	DrawText "rotation = " + String(varx), 10,10
	Flip
	Cls

Until KeyHit(key_escape) = 1



Qweeg(Posted 2005) [#4]
Oh god I'm so dense! Thanks loads guys.


Filax(Posted 2005) [#5]
Thanks for this piece of code :)