Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
glScalef命令偏离中心 嘿,我正在做一个用C++和OpenGL创建的游戏。我有一个动画精灵,我用它作为主角。当你按“a”键时,他向后跑;当你按“d”键时,他向前跑。我正在使用glScalef命令在精灵向后运行时翻转它。然而,当它翻转时,镜像位置是精灵的边缘,而不是中心,因此它看起来就像精灵从一个位置跳到另一个位置。有什么好办法吗? 这是电话线 glScalef(mirrorX,1.0,1.0)_C++_Visual Studio_Opengl - Fatal编程技术网

glScalef命令偏离中心 嘿,我正在做一个用C++和OpenGL创建的游戏。我有一个动画精灵,我用它作为主角。当你按“a”键时,他向后跑;当你按“d”键时,他向前跑。我正在使用glScalef命令在精灵向后运行时翻转它。然而,当它翻转时,镜像位置是精灵的边缘,而不是中心,因此它看起来就像精灵从一个位置跳到另一个位置。有什么好办法吗? 这是电话线 glScalef(mirrorX,1.0,1.0)

glScalef命令偏离中心 嘿,我正在做一个用C++和OpenGL创建的游戏。我有一个动画精灵,我用它作为主角。当你按“a”键时,他向后跑;当你按“d”键时,他向前跑。我正在使用glScalef命令在精灵向后运行时翻转它。然而,当它翻转时,镜像位置是精灵的边缘,而不是中心,因此它看起来就像精灵从一个位置跳到另一个位置。有什么好办法吗? 这是电话线 glScalef(mirrorX,1.0,1.0),c++,visual-studio,opengl,C++,Visual Studio,Opengl,如果是1,它朝前,如果是-1,它朝后。 我也有我的问题的视频。 这是相当糟糕的质量,但你可以看到它时,他来回。 提前感谢各位您的缩放不是从精灵的中心应用的。从您的视频中,您当前的代码是: // apply the rotation around the center of the sprite glTranslatef(centerX, centerY, 0) glRotatef(theta, 0, 0, 1) glTranslatef(-centerX, -centerY, 0) glScal

如果是1,它朝前,如果是-1,它朝后。 我也有我的问题的视频。 这是相当糟糕的质量,但你可以看到它时,他来回。
提前感谢各位

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

// 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)
您应该尝试从精灵的中心缩放:

// 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)

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

// 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)
您应该尝试从精灵的中心缩放:

// 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)