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

Re: [pygame] Rotation of image



On 4/8/06, Tom Wardill <tom@xxxxxxxxxxxxx> wrote:
> I need the ship image to rotate so it always faces the centre.
> I've tried doing:
> self.image = pygame.transform.rotate(self.image, -dTheta)
> (where dTheta is the angle to rotate) but this destroys the image, and
> does some very strange things with the movement of the ship.
>
I don't think it destroys the image - I think it makes a copy of it,
and you just replaced your binding to the original with a binding to
the rotated copy. Keep a reference to the original (you'll need it)

In terms of the odd movement, think of it this way, you started with a
rectangular block which covered the pixels, then you rotated that
block around it's center. some of the pixels of the block went outside
of the original rect (namely the four corners), so the rect had to be
expanded to include them all (the image must increase in size or you
lose data), then it  shifted so the new block so it's upper-left is at
the same place as the old block's upper-left

in this way, the center of the image was shifted down and right by:
[(newimage.width() - oldimage.width())/2, (newimage.height() -
oldimage.height())/2]
So if you draw the new image offset up and left from the old by that
amount, the center should stay in the same place


> In C++, this can be easily done using a glRotate call on the draw
> function. Is there any equivalent way to do this using the built in
> sprite class in pygame?
>
glRotate works great when you use openGL for blitting/rendering.
pyGame sprites use SDL, which can use multiple backends, but usually
doesn't use openGL. if you use pyOpenGL (possibly in concert with
pyGame) you can use glRotate just fine.