Rotate Sprites

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
keramsege
Posts: 7
Joined: April 24th, 2012, 6:28 pm

Rotate Sprites

Post by keramsege » July 4th, 2012, 11:22 am

Hello

i add some new code in chili framework and i can resize Sprites now. But can you imagine for a function to ROTATE Sprites?? (The walking dude should for example go upside down). Sry for my english.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Rotate Sprites

Post by chili » July 4th, 2012, 11:55 am

You wrote a scaling algorithm? That's a good excersise. If you mean upside down, you can do that with a vertical flip and it wouldn't be that hard.

Actual rotation by any angle is more difficult. It can be done simply by rotating each source pixel and then writing it to the backbuffer, but the result can be ugly. We will cover this topic in good time though.
Chili

keramsege
Posts: 7
Joined: April 24th, 2012, 6:28 pm

Re: Rotate Sprites

Post by keramsege » July 4th, 2012, 12:45 pm

yeah, upside down was only a (bad) example.
My plan was drawing a space ship or something else, which can rotate, if you move it around. But i couldn't solve it yet(i think using cos,sin or tan is important)

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Rotate Sprites

Post by chili » July 4th, 2012, 12:55 pm

sin and cos are required, tan is not.
Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Rotate Sprites

Post by Asimov » July 4th, 2012, 1:31 pm

Hi all,

Well the methods that are used in some games is to pre make all the rotations without computing it and putting it on a sprite sheet.

If I was making a sprite in 3ds max I could render it out at all the angles needed for the game and make the sprite sheet from that.

Ugly pixels can happen because you can't actually rotate a pixel as it is always square and sometimes when the sprite is rotated you get horrible jagged edges.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Rotate Sprites

Post by LuX » July 4th, 2012, 3:07 pm

Making a n image rotating function is pretty easy after you figure out the math. But as chili pointed out, you will end up with an ugly image with holes in the middle at the most extreme angles (45 degrees). Also, using geometrical functions like cos and sin, is a very slow process, so I think in this case it's smarter to use some build in function.

A way to go around the ugly pixels is to scan the image one more time before displaying it, by scanning the bitmap, and filling empty holes with the same pixel as next to it. This will make it even slower tho...
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Rotate Sprites

Post by chili » July 4th, 2012, 3:40 pm

You can do it in realtime with UV mapping. It's not too hard, but it is more complicated than rotating the source pixels and then putting them.
Chili

Post Reply