2011-03-01 60 views
0

嘿,我正在研究通過C++和OpenGL創建的遊戲。我有一個我用作主角的動畫精靈。當你按下'a'鍵時,他會倒退,當你按下'd'鍵時,他會向前跑。當他向後跑時,我正在使用glScalef命令來翻轉精靈。然而,當它被翻轉時,鏡像位置是精靈的邊緣,而不是中心,因此它看起來好像他從一個位置跳到另一個位置。任何想法幫助? 這是行 glScalef(mirrorX,1.0,1.0);glScalef命令偏離中心

如果它是1,則它向前,或者如果它是-1,則向後。 我也有我的問題的視頻。 http://www.youtube.com/watch?v=SCi6sotj-94 質量很差,但是當他來回走動時可以看到它。 在此先感謝球員

回答

3

你的縮放不適用於你的精靈的中心。從你的視頻,你當前的代碼是:

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