6

アークボール/トラックボールの回転を実装しようとしていますが、回転の中心に問題があります。何があっても中心を画面の中心にしたい。

私がこれまでに行ったことを説明しましょう。

クォータリオンを作成しました (回転軸: vector_start x vector_end、角度: vector_start * vector_end)

そのクォータニオンから、glMultMatrixf(matrix) で使用して目的の回転を取得するために、回転マトリックスを作成しました。

問題は、モデルが本来のようにアークボール回転しているように見えますが、常にローカル原点を中心に回転していることです。ローカルの原点がどこにあるかに関係なく、画面の中心を中心に回転させるにはどうすればよいですか?

その問題の解決策は、回転軸全体を画面の中央に移動してから回転を適用することだと思いますが、これは可能ですか? ここで何かが恋しいですか?

4

2 に答える 2

1

回転行列と平行移動行列を正しい順序で適用することで、これを解決できるはずです。コードでは、原点T(-pos_x、-pos_y、-pos_z)に変換し直し、回転を適用して、オブジェクトの中心に再度変換することができますT(pos_x、pos_y、pos_z)。これは、回転行列の作成方法に関係なく、一般的に機能するはずです。

于 2009-12-09T18:27:30.037 に答える
0

これは、私が少し前に書いた 3 段階のロケット発射ビューアのコードです。http://www.euclideanspace.com/maths/geometry/rotationsからほとんどの情報を入手しました

注: ヨー、ピッチ、ロールは、座標系の設定方法に基づいて変更される場合があります

      // Assuming the angles are in radians.
            double p = curPitch * Math.PI/180.0 / 2.0;
            double y = curYaw * Math.PI/180.0 / 2.0;
            double r = curRoll * Math.PI/180.0 / 2.0;

            double sinp = Math.sin(p);
            double siny = Math.sin(y);
            double sinr = Math.sin(r);
            double cosp = Math.cos(p);
            double cosy = Math.cos(y);
            double cosr = Math.cos(r);

            Vector3 axis = new Vector3();

            //here's the important part: how you get your quaternion vector!
            axis.x = sinr * cosp * cosy - cosr * sinp * siny;
            axis.y = cosr * sinp * cosy + sinr * cosp * siny;
            axis.z = cosr * cosp * siny - sinr * sinp * cosy;

            //now normalize the vector in case we want to use it again later
            axis = Vector3.normalizeVector(axis);

            orientation[1] = axis.x;
            orientation[2] = axis.y;
            orientation[3] = axis.z;

            //w is omega: the angle to rotate about the quaternion
            double w = cosr * cosp * cosy + sinr * sinp * siny;

            w = Math.acos(w) * 2.0;

            orientation[0] = w;

            gl.glPushMatrix();

              //translate object first, then rotate it.
              gl.glTranslated(curDisplacement[0] + saveDisplacement[0], -curDisplacement[1] + saveDisplacement[2], curDisplacement[2] + saveDisplacement[1]);

              //this order might be messed up because I screwed up my coordinate system, but the idea is still there
              gl.glRotated(orientation[0]*180/Math.PI, orientation[2]*180/Math.PI, orientation[3]*180/Math.PI, orientation[1]*180/Math.PI);

             //place your objects
             gl.glPopMatrix();

お役に立てれば!

于 2009-12-18T18:46:24.387 に答える