私は現在、設定ベクトルに関連する 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 関数がオイラー範囲の値を返すためだと思われます。しかし、よくわかりません。これに対する解決策はありますか?