Jump to content
  • Advertisement
Sign in to follow this  
Scott Brosious

Rotation within an Array?

This topic is 4237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to rotate the contents on an array. Here is what I got for a formula so far. x = xcntr + ((i-xcntr) * cos(a * pi# / 180) - (j-ycntr) * sin(a * pi# / 180)) y = ycntr + ((i-xcntr) * sin(a * pi# / 180) + (j-ycntr) * cos(a * pi# / 180)) i and j are the lookup indices within the array this works great for 90 degree incremeents but sloppy at otheers Does anyone know a better way to to this? So code would be nice. Thanks

Share this post


Link to post
Share on other sites
Advertisement
IT is difficult to rotate an array at other than 90 degree intervals. Try it by hand. Rotation like that always loses some information.

Share this post


Link to post
Share on other sites
I assume the array represents an image of some sort. Don't do it yourself if you don't have to. For example, SDL provides a "rotozoom" module that handles this stuff.

Otherwise, you can improve accuracy by:

- iterating over the *destination* array, translating destination-array coordinates into source array coordinates, and copying them over. If you iterate over the source and copy into the destination, then you may get some pixels mapping to the same spot, and some spotted unmapped.
- Choosing adjacent pixels in the source and taking a weighted average to decide on the destination value. You can use the fractions from the floating-point calculations to determine how to weight the averages. (However, this is completely wrong for most palettized images.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!