0

モデルの 3 つのグループがある 3D シーンを作成しました。私はそれらのグループの 1 つを見ているカメラを持っています。これらのグループのモデルは、グループの中心 (上軸) を中心に回転し、モデルも自身のローカル センター (上軸) を回転します。

これは、XNA Racing Game の車の選択画面に似ています。唯一の違いは、カメラを回転させて別のグループを見ることができるようにしたいということです。カメラを回転させて次のグループを見るとき、120 度回転させたい (私は 3 つのモデル グループ 360/3=120 を持っている)

注: - カメラは、グループの平面の少し上からグループを見ています。

カメラ用:

viewMatrix = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);    
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, 1f, 1000f);

わかった:

  • モデルを自身の軸を中心に回転させることができます。
  • モデルのグループをグループの中心点を中心に左右に回転できます (ゲーム画面では、画面に最も近いモデルが現在選択されているモデルです)。

良くないですよ:

  • 独自のアップ軸を中心にカメラを回転させる正しい方法が見つかりません。

この状況を明確にするための画像のカップル:

4

1 に答える 1

0

カメラのアップ軸ではなく、ワールドのアップ軸を中心にすべての回転をしたいようです。

あるグループから別のグループにビューを変更する方法を次に示します。これは一定の速度で回転します。目的のグループに到達したときに回転を少し遅くしたい場合は、追加のコードが必要です。これは、各グループの中心位置がわかっていることを前提としています。

float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
float rotationRate = 0.01f; //radians per second. set to taste
Vector3 cameraGoal;// the center point of the group that you want the camera to settle on. changes with input.

Vector3 currentLookingDirection = cameraTarget - cameraPosition;//
Vector3 desiredLookingDirection = cameraGoal - cameraPosition;
float angularSeparationFactor = Vector3.Dot(currentLookingDirection, desiredLookingDirection);
if(angularSeparationFactor < 0.98f);//set to taste
{
  float directionToRotate = Math.Sign(Vector3.Cross(currentLookingDirection , desiredLookingDirection ).Y);
   cameraTarget = Vector3.Transform(cameraTarget - cameraPosition, Matrix.CreateRotationY(rotationRate * elapsed * directionToRotate)) + cameraPosition;
}
else
{
   cameraTarget = cameraGoal;
}

view = Matrix.CreatLookAt(cameraPosition, cameraTarget, Vector3.Up);
于 2013-03-24T02:32:24.260 に答える