Jump to content
  • Advertisement

Archived

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

Peon

Rotating graphics (held in an array)

This topic is 5954 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

Just wondering... is this even possible? I''m writing a pixel level sprite editor (don''t ask ) for my next game, and want the ability to rotate an image, so that I won''t have to do it by hand. First a bit of background on the program. The graphics data is stored in three equally sized arrays -- red, green, and blue. I want to be able to rotate to say... 30 degrees or something, and then store the resulting "rotated array" in another array. I know that when I rotate something, it will no longer fit in the same size array (meaning, I''ll have to store it in a bigger array) but that''s not an issue. Here''s what I''ve been thinking so far: - I would take the current column position of the array, multiply by the cosine of the angle, and store that into the new array - Then, I would take the current row position of the array, multiply by the sin of the angle, and then store that. The only problem is, the cos/sin functions will return a float, which cannot be used a subscript. I haven''t tried this yet, but would it work if I simply typecasted to an int and lost the float precision? (This is assuming what I said up there makes any sense at all; it might be totally off ) Anyone know how this would be done? I''ve thought and thought and thought about how I could do this, but I can''t seem to get it right. I''m not sure this can be done, but seeing as how it can be done with bitmaps and such, I''m guessing there is SOME way to do it. Suggestions appreciated

Share this post


Link to post
Share on other sites
Advertisement
As bitmaps are arrays of bytes you certainly can.


For a 90 degree rotation:

NewArray[Height-Y][X] = OldArray[X][Y];

For other degrees:

Translate to Origin Point P

NewX = X Cos & + Y Sin &; //I may have them the wrong way round
NewY = Y Cos & - X Sin &; // & is the angle

Translate Back from Origin P

There is a newsgroup clipping on it in the articles and resources section.

,Jay

Share this post


Link to post
Share on other sites
I explained how I did rotations HERE.

Note, the code has been updated since to lock and unlock the surfaces. Even though it was done in system memory, I learned it was wise to always take this approach.

( Note: This question comes up on a regular basis, someone should write an article. )

Guy

Share this post


Link to post
Share on other sites
quote:
( Note: This question comes up on a regular basis, someone should write an article. )


Sorry about that; I usually do a search first, but I was kind of in a hurry, so I just posted the topic instead.

Anyway, thanks for the help; I appreciate it

Share this post


Link to post
Share on other sites
The formulae I gave can be used back-to-front to get the source pixels for a given destination, this means no missing pixels and no overdraw.

You can also use Breshams algorithm to generate a line from two rotated end points, this is discussed in the clipping I mentioned, in theory very quick.

,Jay

Share this post


Link to post
Share on other sites

  • 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!