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).
我打算制作一款游戏,我想为这款游戏制作一些背景动画。其中一个动画是旋转矩形。我看了一遍,我找不到任何形式的数学或逻辑,允许我旋转一个矩形(SDL_Rect是具体的,但你可能已经知道)。
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.
基本上我正在寻找某种类型的逻辑,我可以应用矩形的坐标,这样每当主游戏循环循环时,它将旋转矩形一定程度的度数。
1 个解决方案
#1
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_Rect。如果你看它的定义,它是由左上角的坐标,宽度和高度组成的。无法表示边长与坐标系轴不平行的矩形。
SDL_RenderCopyEx
supports drawing rotated textures, though.
但是,SDL_RenderCopyEx支持绘制旋转纹理。
#1
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_Rect。如果你看它的定义,它是由左上角的坐标,宽度和高度组成的。无法表示边长与坐标系轴不平行的矩形。
SDL_RenderCopyEx
supports drawing rotated textures, though.
但是,SDL_RenderCopyEx支持绘制旋转纹理。