Re: Rotating a pixbuf (free, any number of degrees)



On 5/24/05, Benjamin Podszun <ben galactic-tales de> wrote:
I'm currently trying to write a small game using GTK (to be honest:
gtk-sharp) and need to rotate an image for my (small, easy, currently
dumb) 2D Game-View.
I found no reference to any GTK-way of doing things like that, but all
"no, you can't do this without writing the code yourself or using 3rd
party libraries" that I found were about 3-4 years old, so I would like
to give it a try again: Is there any native way of archiving what I want?

I think this may be coming with Cairo, but that's not due for a while.
And I'm not sure about the status/speed of the projected win32 cairo
backend. Image rotate is rather easy to implement yourself (at least a
simple rotate is).

I'd implement an affine transform: for every pixel (x',y') in the
output, use this to find the pixel in the input you copy to that
point:

  x' = x * a + y * b + c
  y' = x * d + y * e + f

where a, b, c, d, e, f are six constants. c and f do translation, a,
b, d, e and a 2x2 matrix which does rotate, scale and shear. To do
rotate, set:

  a = cos theta
  b = -sin theta
  d = sin theta
  e = cos theta

That will do nearest-neighbour, but bilinear is hardly more
complicated. Removing the matrix multiplication is slightly more
difficult, and only worth doing if you have speed problems.

John



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]