Rotating a Rect Around Its Center?
BlitzMax Forums/BlitzMax Beginners Area/Rotating a Rect Around Its Center?
| ||
Can someone set me straight on this? I am having a hard time understanding the concepts off origin vs. handle. I am wanting to rotate a square (rect) around it's center, rather than around it's corner. I thought could use origin or handle to move my focus point before I apply the rotation, but don't seem to be having much luck. Can someone point me in the right direction? |
| ||
For a square, if you are drawing it with just DrawRect, there won't be any `handle` information associates with it. It might be affected by rotation and scale. You could try `AutoMidHandle True` and see if that automatically makes it central. Otherwise you'd need to render the rect and grab it as an image, then render the image with a handle. |
| ||
here is the codezGraphics 800,600 x=200 y=200 sizex=100 sizey=20 Repeat x:+1 a:+2 If a>359 Then a=0 SetRotation a SetHandle sizex/2,sizey/2 SetColor 255,100,100 DrawRect x,y,sizex,sizey SetHandle 0,0 SetRotation 0 Flip Cls If KeyHit(key_escape) Then End Forever If you want to do it with a image then it is a lot harder. SetHandle doesnt work for images for some reason. |
| ||
try SetImageHandle instead |
| ||
Thank you all so much. Coorrae - I have implemented the concepts of your code in my work, but I'm still having a small problem understanding it. Why do I use the coordinates of half the width and height? In my head, I thought SetHandle would want coordinates in the graph-space itself to pinpoint the location of my handle. How does SetHandle know that I'm speaking of my rect? Or is this what the documentation means when it used the term "Local"? Thanks again, Michael |
| ||
sethandle sets the handle for everything. like setcolor Why do I use the coordinates of half the width and height? In my head, I thought SetHandle would want coordinates in the graph-space itself to pinpoint the location of my handle. half the width and height is the center of the rect. That is local. like 0,0 is always the topleft of a image. doesnt matter where you later draw it try SetImageHandle instead thanks I will put that in my game I earlier made a function SetOriginMidImage(). that I wont need |
| ||
That makes more sense... so "local" refers to the items at hand (rect, poly, etc) in relation to where it's handle would normally be. It's a 'translation', correct? Thank you, Michael |
| ||
adding a couple of loop statements to the code makes an interesting effect Graphics 800,600 x=200 y=50 sizex=20 sizey=20 Repeat x:+1 a:+2 If a>359 Then a=0 SetRotation a SetHandle sizex/2,sizey/2 SetColor 255,100,100 For loopx = 0 To -500 Step -25 For loop = 0 To 500 Step 25 DrawRect x+loopx,y+loop,sizex,sizey Next Next SetHandle 0,0 SetRotation 0 Flip Cls If KeyHit(key_escape) Then End Forever |