Elementary image rotation by 90 degrees?

BlitzMax Forums/BlitzMax Beginners Area/Elementary image rotation by 90 degrees?

tobykurk(Posted February) [#1]
Is there a simple way to rotate an image by multiples of 90 degrees?

The "SetRotation" command accommodates arbitrary angles and offset rotation centers, so it is necessarily more complex than an elementary 90 degree rotation...

I just want fixed 90, 180, or 270 degree rotation, where the top-left pixel of the new rotated bitmap just stays at (0,0). Like what happens in a basic bitmap editor.

Using "MidHandle" and "SetRotation" and then "SetImageHandle" or ""SetOrigin"; seems much too complicated. I imagine that there should be a much simpler solution?

All suggestions greatly appreciated.


xlsior(Posted February) [#2]
Using "MidHandle" and "SetRotation" and then "SetImageHandle" or ""SetOrigin"; seems much too complicated. I imagine that there should be a much simpler solution?


I think you'll be stuck with that, unless you pre-render the rotations and just use 4 separate images without real-time rotation.


Floyd(Posted February) [#3]
NOTE: Wasn't paying attention, thought this was Blitz3D. I'll leave it here in case somebody stumbles across it looking for Blitz3D information.
BlitzMax might seem more complicated, but you could write a function to do SetRotation, SetImageHandle etc work. So you only have to go through this once.
Anyway, back to what I thought was Blitz3D:


TFormImage does this.
TFormImage image, a,b,  c,d

will apply the following transormation matrix to the image
 a b
 c d

To rotate counterclockwise by angle a use the following matrix
 Cos(a) -Sin(a)
 Sin(a)  Cos(a)
For simple turns of 90,180,270 the only possible values of Sin and Cos are 0,1 and -1. For example a 90 degree rotation would be
 0 -1 1  0
with the corresponding command
TFormImage image, 0,-1, 1,0

The rotation is around the image handle. You would use MidHandle before the rotation. Afterwards you can put the handle back to something else, such as the upper left corner.


TomToad(Posted February) [#4]
After setting Graphics but before loading any images, type this command AutoMidHandle True. Now your images will automatically be loaded with the handle in the center. After that, anytime you want to rotate an image, just type SetRotation 90. Don't see how it can be any simpler than that.

If you are looking to permanently rotate an image by 90, 180, or 270 degrees, this RotatePixmap function below will take a pixmap and return a rotated copy. Note the function isn't optimised and slow, so you would want to call it outside of the main loop.



tobykurk(Posted March) [#5]
Thank you