Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate a rect in SDL2?

I plan on making a game, and I want to create some background animations for said game. One of these animations is a rotating rectangle. I've looked all over, and I cannot find any form of math or logic that allows me to rotate a rectangle (SDL_Rect to be specific, but you might have already known that).

I can't figure out the math for myself, I really don't have any working code for this, so I can't show anything.

Essentially I'm looking for some type of logic that I can apply the rectangle's coordinates so that whenever the main game loop loops, it will rotate the rectangle some amount of degrees.

like image 586
CNJMC1 Avatar asked May 12 '15 18:05

CNJMC1


1 Answers

You can't rotate an SDL_Rect. If you look at its definition, it's made of coordinates for the top-left corner, the width and the height. There's no way to represent a rectangle with sides that aren't parallel to the coordinate system's axes.

SDL_RenderCopyEx supports drawing rotated textures, though.

like image 156
Staven Avatar answered Nov 14 '22 18:11

Staven