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

Re: [pygame] Rotating Images on a specified axis.



I completly agree, that not all rotations (360) needs to be painted. For fluent animation a few would do the job. Though I guess for best rotate quality I would use Phtoshop, 3D tool (if object in 3D) instead of rotating it in Pygame and cut it out from there to safe the image.

Am 28.12.2006 um 17:51 schrieb Brandon N:

Just to throw in my piece, I worked on a school project a few years ago that required this type of rotation and I had good luck with rotating the artifact in somewhere around 6 degree increments and saving them all to one large texture with rotozoom at the start. It worked swiftly and I found that you could get away with less than perfect rotations given the high speed nature of the simulation. Your mileage may vary, as usual.

On Dec 28, 2006, at 11:45 AM, DR0ID wrote:

Farai Aschwanden schrieb:
ANY image transform operation does distort a image in a bigger or minor way. You have 3 possibilities to solve this "problem":
1. Using a existing rotate function (best thing is to work always with the original for most less quality loss when rotating)
2. You paint the tank and the turret in every desired angle (be aware of rotate functions inside paint programs! ;) )
3. You use OpenGL and do it vector based


the easiest way is using the existing rotate function: easy to use and works fast.

Thats all I can say about it.
Farai

Am 28.12.2006 um 01:21 schrieb Caleb Mahase:

Farai Aschwanden wrote:
How about using: pygame.transform.rotozoom(Surface, angle, scale): return Surface
The angle can be positive or negative, depending if you want to move the turret clock- or anti-clockwise. I assume the tank is a different sprite than the turret. Dunno, if 0 or 1 for scale will not make it zoom. But thats probably the funtion you are looking for. ;)


Just my 2 cents
Farai



Am 27.12.2006 um 23:38 schrieb Caleb Mahase:

I'm trying to make an overhead tank battle game. The biggest problem I'm running into is rotating the turret over the tank chassis. In order to do so, I need to be able to specify the axis on which the turret image will rotate instead of just rotating around the middle. The PysGear library seems to have solved this problem however I would like to avoid using an entire library to solve one problem. Any info on this issue will be greatly appreciated.

-Cal

I am already using the rotate function. From what I understand, rotozoom distorts the image.


Hi

if speed is an issue ( as I assume) I would suggest to store for every angle used the rotated turret image. For nice graphics (less distortion) you could render/draw the rotated images in an external program and safe them. If you want to safe some space on the harddisk then you only have to store one image and build the list with the rotated images at startup (using pygame.tramsform.rotate or ,for better quality but a bit slower, rotozoom ).
Oh and I would draw the turret such that the center of the image is also the rotation center of the turret, so when you rotate it, you can just use the center for positioning (its the simplest way, if you dont so then you will have to calculate the position of the rotate image).


Rotation about any point:

----------pseudo code -------

cx, cy     #center coordinates of the image
ncx, ncy  #new center coordinates of rotated image
px, py     #rotation axis
alpha       # angle of rotation in degrees

dx = cx-px #calculate the vector between rotation axis and center of image
dy = cy-py


# rotate vector (here alpha in radians)
ncx = dx * cos(radians(alpha))-dy*sin(radians(alpha))
ncy = dx * sin(radians(alpha))+dy*cos(radians(alpha))

#rotate image (perhaps it has to be -alpha) here alpha in degrees
nimg = pygame.transform.rotate(img, alpha)

#get rect of rotated image
r = nimg.get_rect()

#set center of the image rect to new position
r.center = (px+ncx, py+ncy)

-------- pseudo code end-----

The code is untested so I may have made an mistake somewhere, but I hope it helps you anyway.

~DR0ID