PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Translation before rotation

I load a Bitmap and before rotating, i'd like to make a translation to move the rotation center of the image. When i use the rotation center property of blt(), it moves the center of the image to the point I defined but the image still have the same center of rotation. What i want is to move this point on the image but not on the screen. I'd like to make a translation. In fact the vertical line of my image always have to cross the center of the screen when it rotates. Does smbdy has a solution?

thx
InexorableTash · 11 May 2006, 04:23 UTC
So I presume you're doing something like this (in pseudocode):

Code:

x = Surface.Width / 2
y = Surface.Height / 2

w = Bitmap.Width
h = Bitmap.Height

Surface.Blt( Bitmap, x - (w / 2), y - (h / 2) )


That is, draw the bitmap at such a position so that it's centered at some point on the surface.

In that case you need to account for your bitmap changing size as the result of a blit:

Code:

x = Surface.Width / 2
y = Surface.Height / 2

w = Bitmap.Width
h = Bitmap.Height

// Remember, angle is in radians

w2 = abs( cos(angle) * w + sin(angle) * h )
h2 = abs( sin(angle) * w - cos(angle) * h )

Surface.RotoBlt( Bitmap, x - (w2 / 2), y - (h2 / 2), angle )