public override void UpdateCamera(NCharacterController viewTarget, NexusEngine.NCamera camera, float deltaTime)
 {
     base.UpdateCamera(viewTarget, camera, deltaTime);
 }
예제 #2
0
        public override void UpdateCamera(NCharacterController viewTarget, NexusEngine.NCamera camera, float deltaTime)
        {
            GamePlayerInput playerInput = null;

            if (viewTarget is LocalPlayerController)
            {
                LocalPlayerController lcc = viewTarget as LocalPlayerController;
                playerInput = lcc.PlayerInput;
            }

            if (playerInput != null)
            {
                if (playerInput.IsKeyPressed(Keys.ControlKey) && playerInput.IsKeyPressed(Keys.Menu))
                {
                    //自由观景模式
                    if (!m_FreeMode)
                    {
                        m_FreeMode = true;
                        //记录当前摄像机数据,以备将来恢复
                        m_PitchRotater.StartValue = Pitch;
                        m_YawRotater.StartValue   = Yaw;
                        System.Drawing.Point pt = new System.Drawing.Point(playerInput.MouseValueX, playerInput.MouseValueY);
                        playerInput.FreezeMouse(pt);
                    }
                    if (playerInput.MouseValueDY != 0)
                    {
                        float pitch = -playerInput.MouseValueDY * m_RotateSpeed;
                        this.MovePitch(pitch * deltaTime);
                    }
                    if (playerInput.MouseValueDX != 0)
                    {
                        float yaw = -playerInput.MouseValueDX * m_RotateSpeed;
                        this.MoveYaw(yaw * deltaTime);
                    }
                }
                else
                {
                    if (m_FreeMode)
                    {
                        m_FreeMode = false;
                        playerInput.UnfreezeMouse();

                        m_PitchRotater.EndValue = Pitch;
                        m_PitchRotater.Start();

                        m_YawRotater.EndValue = Yaw;
                        m_YawRotater.Start();
                    }
                    else
                    {
                        if (!m_PitchRotater.IsEnd)
                        {
                            m_PitchRotater.Update(deltaTime);
                            this.MovePitch(m_PitchRotater.Delta);
                        }
                        if (!m_YawRotater.IsEnd)
                        {
                            m_YawRotater.Update(deltaTime);
                            this.MoveYaw(m_YawRotater.Delta);
                        }
                        if (!m_DistanceInterpolater.IsEnd)
                        {
                            m_DistanceInterpolater.Update(deltaTime);
                            this.MoveDistance(m_DistanceInterpolater.Delta);
                        }
                    }

                    if (playerInput.IsKeyPressed(Keys.Menu))
                    {
                        if (playerInput.MouseValueWheel != 0)
                        {
                            m_DistanceInterpolater.StartValue = Distance;
                            m_DistanceInterpolater.EndValue   = Distance + (playerInput.MouseValueWheel < 0 ? -1 : 1) * (MaxDistance - MinDistance) * 0.1f;
                            m_DistanceInterpolater.Start();
                        }
                        else if (playerInput.IsKeyPressed(Keys.Up))
                        {
                            this.MoveDistance(-m_PullSpeed * deltaTime);
                        }
                        else if (playerInput.IsKeyPressed(Keys.Down))
                        {
                            this.MoveDistance(m_PullSpeed * deltaTime);
                        }
                    }
                    else if (playerInput.MouseValueWheel != 0)
                    {
                        //float dyaw = (playerInput.MouseValueWheel > 0 ? m_RotateSpeed : -m_RotateSpeed) * 0.5f;
                        float dyaw = (playerInput.MouseValueWheel > 0 ? 1 : -1) * (float)Math.PI / 9.0f;
                        m_PitchRotater.StartValue = Pitch;
                        m_YawRotater.StartValue   = Yaw + dyaw;
                        m_PitchRotater.EndValue   = Pitch;
                        m_YawRotater.EndValue     = Yaw;
                        m_PitchRotater.Start();
                        m_YawRotater.Start();
                    }
                    else if (playerInput.IsKeyPressed(Keys.Left))
                    {
                        this.MoveYaw(-m_RotateSpeed * deltaTime);
                    }
                    else if (playerInput.IsKeyPressed(Keys.Right))
                    {
                        this.MoveYaw(m_RotateSpeed * deltaTime);
                    }
                }
            }

            camera.FOV = this.fov;

            if (viewTarget != null)
            {
                // 设置好View Target Point
                Vector3 lookAt = viewTarget.Location;
                lookAt.y    += viewTarget.EyesHeight;
                m_LastTarget = this.LookAt;
                this.LookAt  = lookAt;
            }

            base.UpdateCamera(viewTarget, camera, deltaTime);

            //如果当前摄像机运动到地表以下,则恢复到地表
            Vector3 pos    = camera.Position;
            float   height = GameEngine.EngineInstance.CurrentLevel.GetWorldHeight(pos.x, pos.z);

            if (pos.y < height + 100.0f)
            {
                float dh    = pos.y - height - 100.0f;
                float dis   = (this.LookAt - pos).Length();
                float pitch = (float)Math.Atan(dh / dis);
                this.MovePitch(pitch);
                base.UpdateCamera(viewTarget, camera, deltaTime);
            }
        }