Page 1 of 1

Rotate Sprites

Posted: July 4th, 2012, 11:22 am
by keramsege
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.

Re: Rotate Sprites

Posted: July 4th, 2012, 11:55 am
by chili
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.

Re: Rotate Sprites

Posted: July 4th, 2012, 12:45 pm
by keramsege
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)

Re: Rotate Sprites

Posted: July 4th, 2012, 12:55 pm
by chili
sin and cos are required, tan is not.

Re: Rotate Sprites

Posted: July 4th, 2012, 1:31 pm
by Asimov
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

Re: Rotate Sprites

Posted: July 4th, 2012, 3:07 pm
by LuX
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...

Re: Rotate Sprites

Posted: July 4th, 2012, 3:40 pm
by chili
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.