OpenGLでは、ボタンを押したときにインジケータに基づいて撮影する前に、最初に高さインジケータを左右に動かしてボールを撃つことができるフットボールゲームを構築しています。ここでは次のようになります。これらの指標を移動させるときOpenGL - ボールが動かないのはなぜですか?
縦1(x)の場合、私のボールは、垂直インジケータ(Y)の高さで移動する必要があり、左または右方向。
まず、ここに私のサッカーを取得するために今すぐ
を移動するために、私のサッカーのための私(私のRenderScene()
機能で描画されたテクスチャされている)の指標
void SpecialKeys(int key, int x, int y){
if (key == GLUT_KEY_RIGHT) { // moves the bottom indicator RIGHT
horizontalBarX += 5.0f;
}
if (key == GLUT_KEY_LEFT) {
horizontalBarX -= 5.0f; // moves the bottom indicator LEFT
}
if (key == GLUT_KEY_UP) { // moves the top indicator UP
verticalBarY += 5.0f;
verticalBarX += 1.0f;
}
if (key == GLUT_KEY_DOWN) { // moves the top indicator DOWN
verticalBarY -= 5.0f;
verticalBarX -= 1.0f;
}
}
計算を動かすコードですインジケータが移動した後に移動するには、x
,y
およびz
ボールの軸に次の計算を適用する必要があります。
X =罪(シータ)* COS(PHI)Y = COS(シータ)* SIN(PHI)Z = COS(シータ)
シータ= ZXの角度、およびZY
でPHI =角度
だからこれで、私は単にあなたがSpecialKeys()
機能に押されているものの高さの指標に応じて、それらをインクリメントすることにより、最初のシータとファイ両方の角度の値を取得しようと試みてきた。今では
void SpecialKeys(int key, int x, int y){
if (key == GLUT_KEY_RIGHT) { // moves the bottom indicator RIGHT
horizontalBarX += 5.0f;
theta += 5; // Increase theta angle by 5
}
if (key == GLUT_KEY_LEFT) {
horizontalBarX -= 5.0f; // moves the bottom indicator LEFT
theta -= 5; // Decrease theta angle by 5
}
if (key == GLUT_KEY_UP) { // moves the top indicator UP
verticalBarY += 5.0f;
verticalBarX += 1.0f;
phi += 5; // Increase theta angle by 5
}
if (key == GLUT_KEY_DOWN) { // moves the top indicator DOWN
verticalBarY -= 5.0f;
verticalBarX -= 1.0f;
phi -= 5; // Decrease phi angle by 5
}
}
私は角度を持っている、私は計算を接続したいdrawFootballへのd値()の方法により、当初のように私のRenderScene機能で呼び出されるパラメータ、...ここ
drawFootBall(0, 40, 500, 50); // x,.y, z, r
...と私は、上記の計算でボールを起動しようとしています方法は次のとおりです。
void SpecialKeys(int key, int x, int y){
// indicator if statements just above this line
if (key == GLUT_KEY_F1) {
drawFootBall(sin(theta)*cos(phi), cos(theta)*sin(phi), cos(theta), 50);
}
}
しかし、私はF1起動ボタンをクリックして行くとき、何もすべてで起こりません。私はどこを台無しにしましたか?
EDIT:それは助けている場合、ここに私のdrawFootball()
機能が
です:
void drawFootBall(GLfloat x, GLfloat y, GLfloat z, GLfloat r)
{
glPushMatrix();
glFrontFace(GL_CCW);
glTranslatef(x,y,z);
//create ball texture
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_BALL]);
//glDisable(GL_LIGHTING);
glColor3f(0.5,0.5,0.5);
quadricFootball = gluNewQuadric();
gluQuadricDrawStyle(quadricFootball, GLU_FILL);
gluQuadricNormals(quadricFootball, GLU_SMOOTH);
gluQuadricOrientation(quadricFootball, GLU_OUTSIDE);
gluQuadricTexture(quadricFootball, GL_TRUE);
gluSphere(quadricFootball, r, 85, 50);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}
drawFootBall()が何をしているのかわからなくても、あなたを助けることは非常に難しいでしょう。 – Frank
こんにちは@Frank、私はあなたのために私のdrawFootball()関数を表示するための私の質問を編集しました。 –
あなたの角度は度ではなく、ラジアンでなければなりません。 5ラジアンはほぼ360度です。 – molbdnilo