船の移動の前後方向の位置を適切な速度で更新するための2つの適切なキーをコーディングしようとしていますが、思いついたのは次のとおりです。
//Update method
public void Update(Vector3 position, Vector3 orientation)
{
//TO DO - Create an updated version of this.local matrix
this.local *= Matrix.CreateFromYawPitchRoll(orientation.Y, orientation.X, orientation.Z);
this.local *= Matrix.CreateTranslation(position.X, position.Y, position.Z);
}
Game1 より:
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
//Update the camera
camera.Update();
KeyboardState keyState = Keyboard.GetState();
// The time since Update was called last.
float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
float RotationAngle = 0;
RotationAngle += elapsed;
float circle = MathHelper.Pi * 2;
RotationAngle = RotationAngle % circle;
Vector3 orientation = new Vector3(0, 0, 0);
Vector3 position = new Vector3(0, 0, 0);
if (keyState.IsKeyDown(Keys.W))
orientation.X = RotationAngle;
if (keyState.IsKeyDown(Keys.S))
orientation.X = -RotationAngle;
if (keyState.IsKeyDown(Keys.A))
orientation.Y = RotationAngle;
if (keyState.IsKeyDown(Keys.D))
orientation.Y = -RotationAngle;
if (keyState.IsKeyDown(Keys.Z))
orientation.Z = RotationAngle;
if (keyState.IsKeyDown(Keys.X))
orientation.Z = -RotationAngle;
//TO DO - Code two suitable keys to update position in the forward/backward direction of Ship travel at a suitable velocity
if (keyState.IsKeyDown(Keys.F))
position.Z = 1f;
if (keyState.IsKeyDown(Keys.B))
position.Z = 1f;
//Update the first model i.e. the Ship
scene[0].Update(position, orientation);
base.Update(gameTime);
}
問題は、船の機首を左右に回転させても、これらのボタンは私 (カメラ) に向かって前後に機能します。船の「鼻」、船の方向の前後に動かすには何を追加しますか?
答え!!!!それを機能させるために私がしなければならなかったのは、行列を異なる方法で乗算することだけでした.Translateよりも最初に回転し、最後にローカル!!! 回答ありがとうございます。それは本当に私の頭の上に座っていました!
this.local = Matrix.CreateFromYawPitchRoll(orientation.Y, orientation.X, orientation.Z) * Matrix.CreateTranslation(position.X, position.Y, position.Z) * this.local;