开发者

glScalef command off center

Hey guys, I'm working on a game created through C++ and OpenGL. I have an animated sprite I'm using 开发者_如何学Goas the main character. When you push the 'a' key, he runs backwards, and when you push the 'd' key, he runs forwards. I'm using the glScalef command to flip the sprite when he runs backwards. However, when it's flipped, the mirror location is the edge of the sprite, instead of the center where, so it's appearing as though he jumps from one location to another. Any ideas to help? This is the line glScalef(mirrorX,1.0,1.0);

If it's 1, it faces forward, or if it's -1, it's backwards. I also have a video of my problem. http://www.youtube.com/watch?v=SCi6sotj-94 It's pretty bad quality, but you can see it when he goes back and forth. Thanks in advance guys


Your scaling is just not applied from the center of your sprite. From your video, your current code is :

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

You should try to scale from the center of your 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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜