0

私は現在、設定ベクトルに関連する FPS カメラ機能を実装しようとしています。この場合、惑星の中心からプレイヤーの位置までの法線になります。これにより、惑星を歩き回ることができます。惑星の曲率によってカメラが歪むことはありません。

現在、これを使用してカメラの方向を設定しています。

        Main.getMap().getLocalizedUpVector(shootPos, up);
        Main.getMap().getLocalizedAngle(shootPos, angle);

        matrice.rotate(angle.y, RenderElement.AXIS_YAW);
        matrice.rotate(angle.x, RenderElement.AXIS_PITCH);

        matrice.rotate(yaw,up);
        right.set(matrice.m00, matrice.m10, matrice.m20);   

        if(right.length()>0){
            right.normalise();
        }

        matrice.rotate(pitch, right);

        eye.set(matrice.m02, matrice.m12, matrice.m22);

これらの関数を呼び出します。

public void getLocalizedUpVector(Vector3f pos, Vector3f res){

    res.set(pos.x - center.x, pos.y - center.y, pos.z - center.z);

    if(res.length() > 0){
        res.normalise();
    }
}


public void getLocalizedAngle(Vector3f pos, Vector3f angle){

    float deltaX = pos.x - center.x;
    float deltaY = pos.y - center.y;
    float deltaZ = pos.z - center.z;

    float distance = (float)Math.sqrt(deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ);

    float yaw = -(float)Math.atan2(deltaX, deltaZ);     
    float pitch = (float)Math.asin(deltaY/distance);

    angle.set(pitch, yaw, 0);
}

この実装は、地球の半分では問題なく機能しますが、反対側ではうまくいきません。これは、getLocalizedAngle 関数がオイラー範囲の値を返すためだと思われます。しかし、よくわかりません。これに対する解決策はありますか?

4

1 に答える 1

0

わかりました、何か他のことをしている間にそれを理解しました!

        matrice.setIdentity();

        Main.getMap().getLocalizedUpVector(shootPos, up);
        matrice.m02 = up.x; matrice.m12 = up.y; matrice.m22 = up.z;

        matrice.rotate(pitch, RenderElement.AXIS_PITCH);
        matrice.rotate(yaw, up);

        eye.set(matrice.m02, matrice.m12, matrice.m22);


        if(eye.length() > 0){
            eye.normalise();
        }

最初に行列をアップ ベクトルに設定し、次にそのベクトルをグローバル ピッチ軸で回転させてピッチを取得します。アップ ベクトルを中心に回転してヨーを取得します。

次に、行列から相対的な目を取得します。

于 2013-11-18T17:13:01.780 に答える