How to center rotation (midhandle) a rect or oval?

BlitzMax Forums/BlitzMax Programming/How to center rotation (midhandle) a rect or oval?

Tibit(Posted 2005) [#1]
Using a image with midhandle works great. But for the sake of examples it is nice to use the basic drawing commands along with SetRotation(). But somehow the rect is rotated around its top,left corner. I need a function to in every case recalculate the rotation and movement as if the rect was midhandled so I can use the same SetRotaion() command as for a midhandled image.

I figured it was as simple as moving it in X,Y with Cos,Sin.. But I guess not..


klepto2(Posted 2005) [#2]
Well, I think the simpliest way is to save the Rect or Oval in an Image. Maybe like this



Press Space to toggle between Midhandle and use A and Y
to Rotate


Tibit(Posted 2005) [#3]
Many Thanks!

That works perfect.


TomToad(Posted 2005) [#4]
You can also do something like this
Local RectXPos = 100
Local RectYPos = 100
Local RectWidth = 10
Local RectHeight = 10

DrawRect (RectXPos-RectWidth/2,RectYPos-RectHeight/2,RectWidth,RectHeight)


ETA: Then again. after testing, that doesn't seem to work.


Eikon(Posted 2005) [#5]
SetHandle


klepto2(Posted 2005) [#6]
Yes, never seen this command before, but it really works by using SetHandle w/2,h/2.
Thx.


Tibit(Posted 2005) [#7]
Good news, SetHandle..

SetRotation(Rot)
SetHandle w/2, h/2
DrawOval( 400-w/2 , 300-h/2, w, h )


Yan(Posted 2005) [#8]
Didn't AutoMidHandle do this at one point, or did I just imagine it?


tonyg(Posted 2005) [#9]
Seems that's only for images although I can't remember if it included draws at an earlier level.