Original Post
🔒 Locked
Rotating a image
Advertisement
What you probably should do is check out some docs on texture mapping. You can make a simple texturemapper and use then just rotate the polygon''s points.
Just do a google search on "programminf texture mapping"...
Just do a google search on "programminf texture mapping"...
It's really easy, if you only want to restrict it to 2D.
In your original algorithm, you took each source pixel, applied a 2D rotation formula to find it's new position, and draw it there. Because of inaccuracies and the discrete nature of pixel graphics, you'll get holes/overlapping pixels.
Just turn the approach around: for every pixel in the destination image, rotate it *backwards* (using the same equation as you did before, just with a negative angle) and find it's position in the source image. Then copy this source pixel to the destination one.
Pseudocode:
As said, RotatePixel() is the same equation as you currently use. The only difference is the negative angle.
/ Yann
[edited by - Yann L on September 27, 2002 2:44:00 PM]
In your original algorithm, you took each source pixel, applied a 2D rotation formula to find it's new position, and draw it there. Because of inaccuracies and the discrete nature of pixel graphics, you'll get holes/overlapping pixels.
Just turn the approach around: for every pixel in the destination image, rotate it *backwards* (using the same equation as you did before, just with a negative angle) and find it's position in the source image. Then copy this source pixel to the destination one.
Pseudocode:
for( y=0; y<height; y++ ) {
for( x=0; x<width; x++ ) {
// x and y are destination coordinates, so rotate them
// backwards into the source image
RotatePixel(x, y, -angle, &source_x, &source_y);
// source_x/y now hold the position of the destination
// pixel in the source image. Now, just copy it:
Destination_array[x][y] = Source_array[source_x, source_y];
}
}
As said, RotatePixel() is the same equation as you currently use. The only difference is the negative angle.
/ Yann
[edited by - Yann L on September 27, 2002 2:44:00 PM]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement