C# 摄影机在世界空间而不是本地空间中俯仰

C# 摄影机在世界空间而不是本地空间中俯仰,c#,xna,camera,pitch,C#,Xna,Camera,Pitch,如何在localspace中放置摄影机 我有一个模型,不管它在世界空间的什么位置,它都会绕轴旋转。我遇到的问题是,无论模型的其他旋转(偏航)如何,都要让相机保持相同的俯仰角度。当前,如果模型在世界空间中朝北或朝南,则相机会相应地倾斜。但是当模型面向任何其他基本方向时,在尝试倾斜摄影机后,摄影机在模型后面以圆周运动上下移动(因为它只识别世界空间,而不识别模型所面向的方向) 如何使节距随模型旋转,以便无论模型朝向哪个方向?当我尝试俯仰时,相机会在模型上移动吗 // Rotates model and

如何在localspace中放置摄影机

我有一个模型,不管它在世界空间的什么位置,它都会绕轴旋转。我遇到的问题是,无论模型的其他旋转(偏航)如何,都要让相机保持相同的俯仰角度。当前,如果模型在世界空间中朝北或朝南,则相机会相应地倾斜。但是当模型面向任何其他基本方向时,在尝试倾斜摄影机后,摄影机在模型后面以圆周运动上下移动(因为它只识别世界空间,而不识别模型所面向的方向)

如何使节距随模型旋转,以便无论模型朝向哪个方向?当我尝试俯仰时,相机会在模型上移动吗

// Rotates model and pitches camera on its own axis
    public void modelRotMovement(GamePadState pController)
    {
        /* For rotating the model left or right.
         * Camera maintains distance from model
         * throughout rotation and if model moves 
         * to a new position.
         */

        Yaw = pController.ThumbSticks.Right.X * MathHelper.ToRadians(speedAngleMAX);

        AddRotation = Quaternion.CreateFromYawPitchRoll(Yaw, 0, 0);
        ModelLoad.MRotation *= AddRotation;
        MOrientation = Matrix.CreateFromQuaternion(ModelLoad.MRotation);

        /* Camera pitches vertically around the
         * model. Problem is that the pitch is
         * in worldspace and doesn't take into
         * account if the model is rotated.
         */
        Pitch = pController.ThumbSticks.Right.Y * MathHelper.ToRadians(speedAngleMAX);
    }

    // Orbit (yaw) Camera around model
    public void cameraYaw(Vector3 axisYaw, float yaw)
    {
        ModelLoad.CameraPos = Vector3.Transform(ModelLoad.CameraPos - ModelLoad.camTarget,
            Matrix.CreateFromAxisAngle(axisYaw, yaw)) + ModelLoad.camTarget;
    }

    // Pitch Camera around model
    public void cameraPitch(Vector3 axisPitch, float pitch)
    {
        ModelLoad.CameraPos = Vector3.Transform(ModelLoad.CameraPos - ModelLoad.camTarget,
            Matrix.CreateFromAxisAngle(axisPitch, pitch)) + ModelLoad.camTarget; 
    }

    public void updateCamera()
    {
        cameraPitch(Vector3.Right, Pitch);
        cameraYaw(Vector3.Up, Yaw);
    }
我应该在你的最后一个问题中看到这一点。sry

axisPitch实际上是一个全局空间向量,它需要位于局部空间。这应该行得通

   public void cameraPitch(float pitch)
    {
        Vector3 f = ModelLoad.camTarget - ModelLoad.CameraPos;
        Vector3 axisPitch = Vector3.Cross(Vector3.Up, f);
        axisPitch.Normalize();
        ModelLoad.CameraPos = Vector3.Transform(ModelLoad.CameraPos - ModelLoad.camTarget,
            Matrix.CreateFromAxisAngle(axisPitch, pitch)) + ModelLoad.camTarget; 
    }
   public void cameraPitch(float pitch)
    {
        Vector3 f = ModelLoad.camTarget - ModelLoad.CameraPos;
        Vector3 axisPitch = Vector3.Cross(Vector3.Up, f);
        axisPitch.Normalize();
        ModelLoad.CameraPos = Vector3.Transform(ModelLoad.CameraPos - ModelLoad.camTarget,
            Matrix.CreateFromAxisAngle(axisPitch, pitch)) + ModelLoad.camTarget; 
    }