1

私のアプリケーションには単純な長方形の形状があり、その側面の1つを固定して回転させ、X軸を中心に回転させています。回転は次の図のようになります (灰色は、この図で取得している現在の回転を示します)。

ここに画像の説明を入力

この回転を取得するために次のコードを使用しています

glPushMatrix();
glTranslatef(position of the axis point which has to be fixed for rotation);
glRotatef(rotationAmount, 1,0,0);
glTranslatef(-position of the axis point which has to be fixed for rotation);
Rectangle(xPosition, Position,200,100);
glPopMatrix();

ただし、この同じ図を、その側面の 1 つを中心に y 軸を中心にさらに回転させて回転させる必要があります (図の緑の矢印の方向)。この長方形を x 軸と y 軸の周りを同時に回転し続けるように回転するにはどうすればよいですか?

編集:別のものを追加しようとしましたglRotatef(rotateAroundYaxis amount,0,1,0)が、出力は実際には期待していたものとは異なります。図は、単純なページめくりのように y 軸を中心に回転するのではなく、2 つの象限で回転します。

プログラムでこれらの2つのローテーションを1つだけを使用して(両方を一緒にではなく)個別に試した場合、つまり

glRotatef(rotateAmount,1,0,0);
glRotatef(rotateYamount,0,-1,0);

必要な X と Y の回転は個別に取得できますが、組み合わせると奇妙な回転効果が得られます。

4

2 に答える 2

1

以下が欲しいだけのようです。教えていただけない場合は、変更いたします。

glPushMatrix();
glTranslatef(position of the axis point which has to be fixed for rotation);
glRotatef(rotationAmount, 1,0,0); // <- keep this but also
glRotatef(rotationAmountAroundYAxis, 0,1,0); // <- add this
glTranslatef(-position of the axis point which has to be fixed for rotation);
Rectangle(xPosition, Position,200,100);
glPopMatrix();
于 2012-12-04T07:36:20.477 に答える
0

これを変更する必要があります:

glRotatef(rotationAmount, 1,0,0);

これに:

glRotatef(rotationAmount, 1,1,0);
于 2012-12-04T07:38:32.410 に答える