Archived

This topic is now archived and is closed to further replies.

Jeremiah

rotated pictures (sprites)

Recommended Posts

im creating a top-down view game in 2d, and i want to draw just one picture for things (for instance, an enemy, a missle, tank, etc) and have my engine be able to draw it in any angle (instead of having 8 pictures drawn in 8 different directions). any suggestions? i was thinking about using some code that is supposed to be used to draw 3d textured polygons (not perspective corrected). i know it will work, but it''d require me to rotate 4 points and then draw the bitmap (sprite, whatever) like it was a polygon. is there a faster way? if there is i cant think of it. i know allegro has a function that does this, but i would rather write it myself, then just plug in some function into my code. any suggestions? -jeremiah;

Share this post


Link to post
Share on other sites
Just like in your other post, go check out inverse reality. Here, I''ll give you a more accurate URL so you''ll just be taken to the Graphics programming page
CLICK ME

Hope that helps



========================================================
If something sounds stupid but works, it's not stupid

Share this post


Link to post
Share on other sites
I am trying to do the same thing, but I found that doing your own rotational transformations can create extremely messy results.

The problem with doing 2d rotational transformations is that when you rotate a pixel about a point, the resulting position is not always going to be a whole number coordinate (ie. not fractional). this meeans that you have to ''spread'' the pixel out over the neighboring pixels. Note: these neighboring pixels will also be share fractional parts of another transformed pixel, which means that you need to blend the to pixel colors. It can turn out to be a real mess, especially with smaller bitmaps.

So, instead of re-inventing the wheel, I know you probably don''t want to here this but, get Paint Shop pro and load your bitmap/sprite.

1. Rotate by 11.25 degrees, save. Reload original bitmap/sprite, rotate by 22.5 degrees, Repeat until you have rotated by 78.75 degrees.

2. Then go back and crop the new sprites back to the original size.

3. take each sprite and then rotate it by 90 degrees three times.

this will result in 32 sprites. which you can then either load independantly or paste onto a master ''sheet''.

This whole process took me 20 minutes. Writing the code will take you considerably alot more than that with varying degrees of success.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Here are a couple URLS to some bitmap rotation code on Codeguru. Hopefully they''ll be of some use.

http://codeguru.earthweb.com/bitmap/RotateByShear.shtml

http://codeguru.earthweb.com/bitmap/rotate_bitmap.shtml

http://codeguru.earthweb.com/mfc/comments/15346.shtml

Share this post


Link to post
Share on other sites
No one seems to like my version , but in my game arkia.tripod.com, I had to do some rotations. It did do the inaccurate kind (point to point), but it works fine unless the image is dithered. Its a lot like the one at http://codeguru.earthweb.com/bitmap/rotate_bitmap.shtml, but it uses fixedpoint arthmetic, and inline assembly. It is incredibly fast, but ugly, because I''m not exactly sure how it works.

If you want to see the source just download fsrc.zip, and look in ddbitmap.cpp. Drawing at an angle starts with AngleDraw.

Share this post


Link to post
Share on other sites
i do not want to have 32 different pictures just for one "sprite". i want to have one, and then have a function that can draw that one on the screen in a certain angle. my sprites will probably be 32x32.

right now im probably going to create a function that draws the bitmap like a 4-sided polygon, but i was hoping to find a faster and easier function. any suggestions?

its gotta be fast since its going to be called lots of time per frame to draw certain sprites onto the screen.

-jeremiah;

Share this post


Link to post
Share on other sites