Please lay me a hand.

Started by
14 comments, last by borg_ri 12 years, 10 months ago

Then for each pixel in the rotated image you do

int src_bitmap_x=(int)((x+0));
int src_bitmap_y=(int)((y+0));
if( src_bitmap_x>=0 && src_bitmap_x<image.get_width() && src_bitmap_y>=0 && src_bitmap_y<image.get_height() ) {
image_rotated.buffer[y * image_rotated.get_width() + x] = image.buffer[src_bitmap_x * image.get_width() + src_bitmap_y];
}

shouldn't:
image_rotated.buffer[y * image_rotated.get_width() + x] = image.buffer[src_bitmap_x * image.get_width() + src_bitmap_y];

be

image_rotated.buffer[y * image_rotated.get_width() + x] = image.buffer[src_bitmap_y * image.get_width() + src_bitmap_x];


OUTSTANDING CATCH MAN! :) It works now.

There are some special cases where the image will still face the opposite direction it is moving, but that smells like something being wrong with the algorithm that decides to flip the image horizontally.

You're awesome guys! :)
[size="2"]I like the Walrus best.
Advertisement
i think that you problem is in this


if (x_vel<0)
{
radians = 0-(3.1416-atan2(y_vel,x_vel));
}


you can't flip image by rotateing. you need to do this


if (x_vel<0)
{
for(int x=0; x<width; x++) for(int y=0; y<height; y++)
image_fliped.buffer[(y+1) * width - x] = image.buffer[y * width + x];
}
or you can remove the if statement and change this



image_rotated.buffer[y * image_rotated.get_width() + x] = image.buffer[src_bitmap_y * image.get_width() + src_bitmap_x];



to this




int rot_index = (x_vel<0) ? (y+1) * image_rotated.get_width() - x : y * image_rotated.get_width() + x;

image_rotated.buffer[rot_index] = image.buffer[src_bitmap_y * image.get_width() + src_bitmap_x];


i think that you problem is in this


if (x_vel<0)
{
radians = 0-(3.1416-atan2(y_vel,x_vel));
}


you can't flip image by rotateing. you need to do this


if (x_vel<0)
{
for(int x=0; x<width; x++) for(int y=0; y<height; y++)
image_fliped.buffer[(y+1) * width - x] = image.buffer[y * width + x];
}




if (x_vel<0)
{
radians = 0-(3.1416-atan2(y_vel,x_vel));
}


doesn't flip the image, it adjusts the rotation so that the flipped image faces in the correct direction (as flipping the image effectivly changes the direction its facing by pi radians the performed rotation has to be adjusted by the same amount to compensate to avoid having the flipped image face the wrong way)

it should probably be changed to:

float radians = atan2(y_vel, x_vel);
if (x_vel<0) {
radians -= 3.1416;
} //This should be equivalent but avoids one atan2 call and thus should be faster (unless the compiler is capable of optimizing out calls to pure functions when the variables passed doesn't change)

I'm assuming owl has a flip function aswell that he calls when xvel<0 since he said he was flipping the image in his original post (yet the code he posted doesn't flip it).

The remaining "special cases" could probably be solved if we knew in what ranges they occured (If it happens when moving close to straight up or straight down for example)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

The remaining "special cases" could probably be solved if we knew in what ranges they occured (If it happens when moving close to straight up or straight down for example)


It was a problem related to sometimes not flipping the image. This code is for the fish tank entry and I'm writing it as it comes, that is: messy :)
[size="2"]I like the Walrus best.
i am sorry, in my code i gave you i was fliping image the wrong way, that is probably why it didn't work. try this.




comment out the



if (x_vel<0)
{
radians = 0-(3.1416-atan2(y_vel,x_vel));
}







and replace



image_rotated.buffer[y * image_rotated.get_width() + x] = image.buffer[src_bitmap_y * image.get_width() + src_bitmap_x];






with



int rot_index = (x_vel<0) ? (dest_height-y-1) * image_rotated.get_width() + x : y * image_rotated.get_width() + x;

image_rotated.buffer[rot_index] = image.buffer[src_bitmap_y * image.get_width() + src_bitmap_x];


This topic is closed to new replies.

Advertisement