2012-04-10 5 views
0

ピボットポイント(脚の上端)の周りを脚の動きをしようとすると、代わりに脚を前後に回転させたいときに、脚が間違ったポイントを中心に回転し始めます。足の動きを作る方法、OpenGL?

この問題を解決するにはどうすればよいですか?

これは私のコードです。

glPushMatrix(); 

    glTranslatef(x+0.0f, y+6.0f, z-1.5f); 
    glRotatef(walk, 1.0f,0.0f,0.0f); 
    glBegin(GL_QUADS); 
     glTexCoord2f(0.5f,0.0f); glVertex3f(x-1.0f, y-6.0f, z-3.0f); 
     glTexCoord2f(1.0f,0.0f); glVertex3f(x-1.0f, y-6.0f, z-0.5f); 
     glTexCoord2f(1.0f,0.5f); glVertex3f(x-1.0f, y-18.0f, z-0.5f); 
     glTexCoord2f(0.5f,0.5f); glVertex3f(x-1.0f, y-18.0f, z-3.0f); 

     glTexCoord2f(0.5f,0.0f); glVertex3f(x+1.0f, y-6.0f, z-3.0f); 
     glTexCoord2f(1.0f,0.0f); glVertex3f(x+1.0f, y-6.0f, z-0.5f); 
     glTexCoord2f(1.0f,0.5f); glVertex3f(x+1.0f, y-18.0f, z-0.5f); 
     glTexCoord2f(0.5f,0.5f); glVertex3f(x+1.0f, y-18.0f, z-3.0f); 

     glTexCoord2f(0.5f,0.0f); glVertex3f(x-1.0f, y-6.0f, z-3.0f); 
     glTexCoord2f(1.0f,0.0f); glVertex3f(x+1.0f, y-6.0f, z-3.0f); 
     glTexCoord2f(1.0f,0.5f); glVertex3f(x+1.0f, y-18.0f, z-3.0f); 
     glTexCoord2f(0.5f,0.5f); glVertex3f(x-1.0f, y-18.0f, z-3.0f); 

     glTexCoord2f(0.5f,0.0f); glVertex3f(x-1.0f, y-6.0f, z-0.5f); 
     glTexCoord2f(1.0f,0.0f); glVertex3f(x+1.0f, y-6.0f, z-0.5f); 
     glTexCoord2f(1.0f,0.5f); glVertex3f(x+1.0f, y-18.0f, z-0.5f); 
     glTexCoord2f(0.5f,0.5f); glVertex3f(x-1.0f, y-18.0f, z-0.5f); 
glEnd(); 
glPopMatrix(); 
glPushMatrix(); 
    glTranslatef(x+0.0f, y+6.0f, z+1.5f); 
    glRotatef(-walk, 0.0f,0.0f,1.0f); 
    glBegin(GL_QUADS); 
     glTexCoord2f(0.5f,0.0f); glVertex3f(x-1.0f, y-6.0f, z+3.0f); 
     glTexCoord2f(1.0f,0.0f); glVertex3f(x-1.0f, y-6.0f, z+0.5f); 
     glTexCoord2f(1.0f,0.5f); glVertex3f(x-1.0f, y-18.0f, z+0.5f); 
     glTexCoord2f(0.5f,0.5f); glVertex3f(x-1.0f, y-18.0f, z+3.0f); 

     glTexCoord2f(0.5f,0.0f); glVertex3f(x+1.0f, y-6.0f, z+3.0f); 
     glTexCoord2f(1.0f,0.0f); glVertex3f(x+1.0f, y-6.0f, z+0.5f); 
     glTexCoord2f(1.0f,0.5f); glVertex3f(x+1.0f, y-18.0f, z+0.5f); 
     glTexCoord2f(0.5f,0.5f); glVertex3f(x+1.0f, y-18.0f, z+3.0f); 

     glTexCoord2f(0.5f,0.0f); glVertex3f(x-1.0f, y-6.0f, z+3.0f); 
     glTexCoord2f(1.0f,0.0f); glVertex3f(x+1.0f, y-6.0f, z+3.0f); 
     glTexCoord2f(1.0f,0.5f); glVertex3f(x+1.0f, y-18.0f, z+3.0f); 
     glTexCoord2f(0.5f,0.5f); glVertex3f(x-1.0f, y-18.0f, z+3.0f); 

     glTexCoord2f(0.5f,0.0f); glVertex3f(x-1.0f, y-6.0f, z+0.5f); 
     glTexCoord2f(1.0f,0.0f); glVertex3f(x+1.0f, y-6.0f, z+0.5f); 
     glTexCoord2f(1.0f,0.5f); glVertex3f(x+1.0f, y-18.0f, z+0.5f); 
     glTexCoord2f(0.5f,0.5f); glVertex3f(x-1.0f, y-18.0f, z+0.5f); 
glEnd(); 

glPopMatrix(); 
+0

だからあなたの質問は何ですか? –

+0

は、代わりにhttp://gamedev.stackexchange.com/を試すことがあります。この種の質問に特化したサイト。 – Gorgen

+0

物事は周りを回っていますか? –

答えて

1

すべてのOpenGLの回転は、点を中心に行われている(0,0,0)。あなたの周りの頂点の特定のポイント(RX、RY、RZ)を回転させるようにしたいのであれば、あなたは次の変換を実行する必要があります。

Translate(-rx, -ry, -rz); 
Rotate(alpha, beta, gamma); 
Translate(rx, ry, rz); 
+0

2つの翻訳の順序を切り替える必要があります。 –

+0

それは依存します。私は変換を時間順に書いており、その点では正しいものです(回転中心は(0、0、0)点に変換されなければなりません)。手動で変換を適用する場合は、私が提示した順序で変換を行う必要があります。しかし、行列を使って変換を適用し、変換行列を生成したい場合、実際には、変換の結合プロパティのためにシーケンスを元に戻す必要があります。 – Spook

+0

実際、私は翻訳を切り替える必要がありました。それ以外の場合、あなたの答えは私の問題を解決しました。 – Ripspace

関連する問題