Rotating a rectangle

I’m writing a card game. I would like to rotate some of the cards 90 degrees and others 270 degrees to represent people sitting to the left and right of me at a table.

void rotate_card (SDL_Rect *dest)

SDL_Rect src;
int rot = 90;

src.x = 0;
src.y = 0;
src.w = dest->w;
src.h = dest->h;

SDL_RenderCopyEx (screen, img, &src, dest, rot, NULL, SDL_FLIP_NONE);

The image rotates correctly. Unfortunately, it is stretched and out of proportion.

I have tried adding
dest->w = dest->h;

This keeps the proportions right, but now I have a square card.
I think I’m missing a step, but I’m not sure what it is. Any suggestions?

Do you swap the width and height when rotating the card 90° or 270°? I don’t think you should do that because it seems like the dest rectangle describes the area that the texture would have occupied if there was no rotation. This means that the texture might be rendered partially outside the dest rectangle if you use a non-zero rotation angle.

What happens if you set the source rect to NULL? That’s what I do in similar circumstances and I’m not seeing the distortion you describe.

That worked. Thanks. :slight_smile:

1 Like