我正在尝试编写两个合适的键来以合适的速度更新船舶前进/后退方向的位置,我想出的是:在 Cmodel 中:
//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);
    }
问题是当我向左或向右旋转船头时,这些按钮仍然像向后和向前一样朝着我(相机)工作。我要添加什么让它在船“鼻子”的方向前后移动?
回答!!!!我所要做的就是将矩阵与不同的矩阵相乘:首先旋转而不是平移,最后是本地!!!谢谢大家的回答。它真的很重要!
this.local = Matrix.CreateFromYawPitchRoll(orientation.Y, orientation.X, orientation.Z) * Matrix.CreateTranslation(position.X, position.Y, position.Z) * this.local;