使用SDL旋转图像的最佳方法?

时间:2022-08-24 08:57:46

I am building a game and the main character's arm will be following the mouse cursor, so it will be rotating quite frequently. What would be the best way to rotate it?

我正在构建一个游戏,主角的手臂将跟随鼠标光标,所以它会频繁旋转。旋转它的最佳方法是什么?

3 个解决方案

#1


With SDL you have a few choices.

使用SDL,您有几个选择。

  1. Rotate all your sprites in advance (pre-render all possible rotations) and render them like you would any other sprite. This approach is fast, but uses more memory and more sprites. As @Nick Wiggle pointed out, RotSprite is a great tool for generating sprite transoformations.

    提前旋转所有精灵(预渲染所有可能的旋转)并像任何其他精灵一样渲染它们。这种方法很快,但使用更多内存和更多精灵。正如@Nick Wiggle所指出的,RotSprite是一个用于生成精灵变换的好工具。

  2. Use something like SDL_gfx to do real-time rotation/zooming. (Not recommended, very slow)

    使用SDL_gfx之类的东西进行实时旋转/缩放。 (不推荐,非常慢)

  3. Use SDL in OpenGL mode and render your sprites to primitives, applying rotation to the primitives.

    在OpenGL模式下使用SDL并将精灵渲染为基元,将旋转应用于基元。

Option 3 is probably your best bet because you gain all of the advantages of using OpenGL. It's really up to you how to want to do it. It's also a possibility that you can load your sprites, perform all rotation calculations with SDL_gfx and then save the rotated versions to a SDL_Surface in memory.

选项3可能是您最好的选择,因为您获得了使用OpenGL的所有优势。这取决于你如何做到这一点。您也可以加载精灵,使用SDL_gfx执行所有旋转计算,然后将旋转的版本保存到内存中的SDL_Surface。

EDIT: In response to your comment I would recommend checking out Lazyfoo's SDL tutorals. Specifically, this one about rotation. There is also an OpenGl function, glRotatef, which can be useful in your case. A quick search brought back this little tidbit which could also be helpful.

编辑:在回应您的评论时,我建议您查看Lazyfoo的SDL tutorals。具体来说,这一个关于旋转。还有一个OpenGl函数glRotatef,它可以在你的情况下使用。快速搜索带回了这个小小的一点,也可能有用。

#2


You can use a library like SDL_gfx

您可以使用SDL_gfx之类的库

#3


SDL_RenderCopyEx()

has extra arguments for rotation, flipping, and the rotation center.

有旋转,翻转和旋转中心的额外参数。

#1


With SDL you have a few choices.

使用SDL,您有几个选择。

  1. Rotate all your sprites in advance (pre-render all possible rotations) and render them like you would any other sprite. This approach is fast, but uses more memory and more sprites. As @Nick Wiggle pointed out, RotSprite is a great tool for generating sprite transoformations.

    提前旋转所有精灵(预渲染所有可能的旋转)并像任何其他精灵一样渲染它们。这种方法很快,但使用更多内存和更多精灵。正如@Nick Wiggle所指出的,RotSprite是一个用于生成精灵变换的好工具。

  2. Use something like SDL_gfx to do real-time rotation/zooming. (Not recommended, very slow)

    使用SDL_gfx之类的东西进行实时旋转/缩放。 (不推荐,非常慢)

  3. Use SDL in OpenGL mode and render your sprites to primitives, applying rotation to the primitives.

    在OpenGL模式下使用SDL并将精灵渲染为基元,将旋转应用于基元。

Option 3 is probably your best bet because you gain all of the advantages of using OpenGL. It's really up to you how to want to do it. It's also a possibility that you can load your sprites, perform all rotation calculations with SDL_gfx and then save the rotated versions to a SDL_Surface in memory.

选项3可能是您最好的选择,因为您获得了使用OpenGL的所有优势。这取决于你如何做到这一点。您也可以加载精灵,使用SDL_gfx执行所有旋转计算,然后将旋转的版本保存到内存中的SDL_Surface。

EDIT: In response to your comment I would recommend checking out Lazyfoo's SDL tutorals. Specifically, this one about rotation. There is also an OpenGl function, glRotatef, which can be useful in your case. A quick search brought back this little tidbit which could also be helpful.

编辑:在回应您的评论时,我建议您查看Lazyfoo的SDL tutorals。具体来说,这一个关于旋转。还有一个OpenGl函数glRotatef,它可以在你的情况下使用。快速搜索带回了这个小小的一点,也可能有用。

#2


You can use a library like SDL_gfx

您可以使用SDL_gfx之类的库

#3


SDL_RenderCopyEx()

has extra arguments for rotation, flipping, and the rotation center.

有旋转,翻转和旋转中心的额外参数。