gpt4 book ai didi

c++ - glScalef 命令偏离中心

转载 作者:行者123 更新时间:2023-11-28 01:07:55 24 4
gpt4 key购买 nike

大家好,我正在开发一款通过 C++ 和 OpenGL 创建的游戏。我有一个用作主角的动画 Sprite 。当你按“a”键时,他会向后跑,当你按“d”键时,他会向前跑。当他向后跑时,我正在使用 glScalef 命令来翻转 Sprite 。然而,当它被翻转时,镜像位置是 Sprite 的边缘,而不是中心位置,所以它看起来好像他从一个位置跳到另一个位置。有什么想法可以帮助吗?这是线glScalef(mirrorX,1.0,1.0);

如果为 1,则面向前方,如果为 -1,则面向后方。我也有我的问题的视频。 http://www.youtube.com/watch?v=SCi6sotj-94质量很差,但是他来回走动的时候你能看出来。提前谢谢大家

最佳答案

您的缩放不是从 Sprite 的中心应用的。从您的视频中,您当前的代码是:

// apply the rotation around the center of the sprite
glTranslatef(centerX, centerY, 0)
glRotatef(theta, 0, 0, 1)
glTranslatef(-centerX, -centerY, 0)
glScalef(mirrorX, 1, 1)

你应该尝试从 Sprite 的中心开始缩放:

// apply the rotation and scale from the center of the sprite
glTranslatef(centerX, centerY, 0)
glRotatef(theta, 0, 0, 1)
glScalef(mirrorX, 1, 1)
glTranslatef(-centerX, -centerY, 0)

关于c++ - glScalef 命令偏离中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5149648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com