作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,我正在开发一款通过 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/
我是一名优秀的程序员,十分优秀!