Archived

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

RapidStunna

2D Surface Rotation Theory

Recommended Posts

Hello, After starting a 2D project which requires software image rotated drawing, problems started occurring when beginning the image rotation code. It at first seemed simple - as I was using the Pixelate tutorial on sine/cosine and image rotation here as a complete reference. After coding it out, and successfully getting it to work, unfortunately it didn't solve my problem. The code in that article describes a method that infinitely repeats and rotates an image until the output screen is filled which is not what I wanted. I just wanted a drawing function that would draw the single image rotated at the position given with the coordinates being the upper left corner of the un-rotated image. So back to square one. After doing some modifications (which to be honest, I had no idea what I was doing), I came up with a way to use that same algorithm but only draw the image once. The problem was then that the image wasn't positioned correctly and it would swing around the page when rotating. Then after doing some more modifications, that problem was solved but then corners were starting to be cut. It ended up that that algorithm just didn't seem to fit this purpose. After doing some searching, I came up with nothing. A few tutorials using skewing and flipping but that didn't seem logical - plus it assumed knowledge of filling a rotated polygon (texturing actually) which if I knew that in the first place I could just rotate the corners and fill it like it was a square. And then I could use just basic planar mapping. But unfortunately it became too confusing. Finally, after searching Flipcode's forums and plenty of times on the search engines and rereading to try and figure it out myself, my life ended up back to you all. From what I found, there didn't seem to be many online sources for these techniques and the ones that were depended on other articles (such as texture mapping) which didn't make sense. What I want is some ideas of how I can go about this simple concept. It seems like it could be simple - rotate corners and interpolate colors between corners but I just can't make sense of it. So now that you know what I know, maybe you can put some sense this. How, in theory, can I simple rotate a 2D surface? ---
Brent Gunning | My Site [edited by - RapidStunna on November 2, 2002 10:34:26 PM]

Share this post


Link to post
Share on other sites
Perhaps not the answer you wanted, but rotation can be done nicely and very quickly by treating the bitmap as a texture-mapped polygon.

Simple 2D texture mapping (affine texture mapping, I believe it''s calleed) isn''t really that hard to do if you''ve ever written a solid-filled polygon drawing routine.

Search for Hugo Elias''s web site. He has a good overview of how to do solid polygons. For texture mapping, there should be plenty of resources out there. The easiest approach really just adds a few variables to keep track of in the drawing code (texture coordinates.)


---
Bart

Share this post


Link to post
Share on other sites
afaik bart is right on: check out hugo''s site:
http://freespace.virgin.net/hugo.elias (if i remember correctly) and goto graphics-> scan line conversion or something... think about storing the image coords at each vertex ("corner") and interpolating along that line between the points... then just scan line convert it (interpolate horizonitally.)

good luck, it''s not too difficult once you understand it, but it''s kinda tricky until then... shoot me an e-mail if you struggle.

thr33d@*nospam*yahoo.com
just delete the *nospam* part ya know

-Michael

Share this post


Link to post
Share on other sites
Once you understand solid polygon filling (as described at Hugo''s site), Michael Abrash''s Graphics Programming Black Book has a good overview of the kind of texture mapping you''ll want to implement.

He also discusses polygon filling, but I think Hugo''s explanation is simpler and may prove to be a better introduction to the subject.



---
Bart

Share this post


Link to post
Share on other sites