Rotating a grid of square images

BlitzMax Forums/BlitzMax Programming/Rotating a grid of square images

EdzUp MkII(Posted June) [#1]
It's probably a stupidly simple thing but is there a so. please algorithm to rotate a grid of images, each image is 32x32 pixels.

Yes my mind has gone completely blank I used to do this in my sleep lol


Brucey(Posted June) [#2]
I wish I had time for sleep :-/


EdzUp MkII(Posted June) [#3]
I know that feeling Brucey ;)


Derron(Posted June) [#4]
As I wont do it for you (maybe there is even something like this in the code archives):

The basic knowledge you need is how to rotate a point around another point in 2d space.

You have your rotation point - eg. the center of the grid, or the top left. And you have the local coordinate of the image. Eg. "-100,-100" regarding the center of the grid, or "0,0" with the rotation point being at the "0,0" coordinate of a 200x200 grid.

All you need to do is to calculate where the new "local coordinate" is when being rotated around the rotation center.
All images in the grid share the same calculation (just different "local coordinates" are used - of course).



Edit: This is a piece of code I am using in my Dig-Framework (in the TVec2D-Class)

	Method RotateAroundPoint:TVec2D(point:TVec2D, angle:Float)
		local xnew:float = (x - point.x) * cos(angle) - (y - point.y) * sin(angle) + point.x
		local ynew:float = (x - point.x) * sin(angle) + (y - point.y) * cos(angle) + point.y
		x = xnew
		y = ynew
		return self
	End Method


Think it should help if you think about what I wrote at the beginning of this post.


bye
Ron


Derron(Posted June) [#5]
Just forgot to add something. Of course you need to "setrotate" when drawing the images.

Bye
Ron


grable(Posted June) [#6]
You can do what Derron said with SetHandle too, since it is applied before scale/rotation.



EdzUp MkII(Posted June) [#7]
I remember the sin/cos stuff it's just a grid of images. I think I have a idea on how to tackle it and will have a look and see.

Thanks everyone :)


TomToad(Posted June) [#8]
Typed this up before I realized it was pretty much what grable did. Basic idea is to locate each image's handle at the same point on the screen, then a SetRotation will automatically place each square at its proper location.