Ejemplo n.º 1
0
        public void Activate(ICamera oldCamera)
        {
            IMouseKeyboardInputSource src = InputSystem.GetInstance().MouseKeyboard;

            src.MouseDown += _OnMouseDown;
            src.MouseUp   += _OnMouseUp;

            if (oldCamera != null)
            {
                var data = oldCamera.GetCameraData();
                m_isLeftDrugging  = false;
                m_isRightDrugging = false;

                var gaze = data.lookAt - data.eye;
                Zoom = gaze.Length();

                gaze.Normalize();
                var right    = Vector3.Cross(data.up, gaze);
                var position = data.eye;

                m_cameraTrans.Row1 = new Vector4(right, 0);
                m_cameraTrans.Row2 = new Vector4(data.up, 0);
                m_cameraTrans.Row3 = new Vector4(gaze, 0);
                m_cameraTrans.Row4 = new Vector4(position, 1);
            }
        }
Ejemplo n.º 2
0
        public void Deactivate()
        {
            IMouseKeyboardInputSource src = InputSystem.GetInstance().MouseKeyboard;

            src.MouseDown -= _OnMouseDown;
            src.MouseUp   -= _OnMouseUp;
        }
Ejemplo n.º 3
0
        public void Update(double dt)
        {
            IMouseKeyboardInputSource src = InputSystem.GetInstance().MouseKeyboard;

            int dWheel = src.WheelDelta;

            Zoom = MathUtil.Clamp(Zoom + dWheel * -ZoomFactor, MinZoom, MaxZoom);
            Vector2 dPos = src.MousePositionDelta;

            if (m_isLeftDrugging)
            {
                // update angle
                float hAngle = dPos.X * AngleFactor;
                float vAngle = dPos.Y * AngleFactor;
                m_cameraTrans = Matrix.RotationYawPitchRoll(hAngle, vAngle, 0) * m_cameraTrans;
            }

            if (m_isRightDrugging)
            {
                // update look at position
                float xOffset = -dPos.X * PositionFactor;
                float yOffset = dPos.Y * PositionFactor;
                m_cameraTrans = Matrix.Translation(xOffset, yOffset, 0) * m_cameraTrans;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update component
        /// </summary>
        /// <param name="dT">spend time [sec]</param>
        public override void Update(double dT)
        {
            var cameraSys = CameraSystem.GetInstance();
            var drawSys   = DrawSystem.GetInstance();

            // Calc camera
            var viewHeadMat = cameraSys.GetCameraData().GetViewMatrix() * drawSys.GetDrawContext().GetHeadMatrix();

            viewHeadMat.Invert();
            var moveDirection = new Vector3(viewHeadMat.Backward.X, 0, viewHeadMat.Backward.Z);

            moveDirection.Normalize();

            var gameSys = GameSystem.GetInstance();

            switch (gameSys.Config.InputDevice)
            {
            case GameConfig.UserInputDevices.MouseKeyboard:
            {
                IMouseKeyboardInputSource src = InputSystem.GetInstance().MouseKeyboard;

                var v = Vector3.Zero;
                if (src.TestKeyState(Keys.W))
                {
                    v.Z += PositionFactor;
                }
                if (src.TestKeyState(Keys.A))
                {
                    v.X -= PositionFactor;
                }
                if (src.TestKeyState(Keys.D))
                {
                    v.X += PositionFactor;
                }
                if (src.TestKeyState(Keys.S))
                {
                    v.Z -= PositionFactor;
                }

                if (v.X != 0 || v.Z != 0)
                {
                    float angleY = (float)Math.Atan2(moveDirection.X, moveDirection.Z);
                    v = Vector3.Transform(v, Matrix3x3.RotationY(angleY));
                    m_behaviorC.RequestMove(v);
                    m_behaviorC.RequestTurn(v);
                }
            }
            break;

            case GameConfig.UserInputDevices.Pad:
            {
                IPadInputSource src = InputSystem.GetInstance().Pad;

                float angleY    = (float)Math.Atan2(moveDirection.X, moveDirection.Z);
                var   thumbDir  = src.LeftThumbInput.Direction;
                float magnitude = src.LeftThumbInput.NormalizedMagnitude;
                if (magnitude >= MinimumPadMagnitude)
                {
                    var v = new Vector3(thumbDir.X, 0, thumbDir.Y);
                    v = Vector3.Transform(v, Matrix3x3.RotationY(angleY));
                    v = v * magnitude;
                    m_behaviorC.RequestMove(v);
                    m_behaviorC.RequestTurn(v);
                }
            }
            break;

            default:
                Debug.Fail("unsupported input device type : " + gameSys.Config.InputDevice);
                break;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Update component
        /// </summary>
        /// <param name="dT">spend time [sec]</param>
        public override void Update(double dT)
        {
            var mapSys = MapSystem.GetInstance();

            m_coroutine.Update(dT);

            if (!m_coroutine.HasCompleted())
            {
                // wait for end of character operation
                return;
            }

            var cameraSys = CameraSystem.GetInstance();
            var drawSys   = DrawSystem.GetInstance();

            var gameSys = GameSystem.GetInstance();

            switch (gameSys.Config.InputDevice)
            {
            case GameConfig.UserInputDevices.MouseKeyboard:
            {
                IMouseKeyboardInputSource src = InputSystem.GetInstance().MouseKeyboard;

                var v = Vector3.Zero;
                if (src.TestKeyState(Keys.W))
                {
                    v.Z += PositionFactor;
                }
                if (src.TestKeyState(Keys.A))
                {
                    v.X -= PositionFactor;
                }
                if (src.TestKeyState(Keys.D))
                {
                    v.X += PositionFactor;
                }
                if (src.TestKeyState(Keys.S))
                {
                    v.Z -= PositionFactor;
                }

                if (v.X != 0 || v.Z != 0)
                {
                    // @todo
                }
            }
            break;

            case GameConfig.UserInputDevices.Pad:
            {
                IPadInputSource src = InputSystem.GetInstance().Pad;

                // update move
                {
                    _InputType inputType = _InputType.None;

                    var   thumbDir  = src.LeftThumbInput.Direction;
                    float magnitude = src.LeftThumbInput.NormalizedMagnitude;
                    if (magnitude >= MinimumPadMagnitude)
                    {
                        // use pad stick
                        if (thumbDir.Y <= -0.851)
                        {
                            inputType = _InputType.Backward;
                        }
                        else if (thumbDir.Y >= 0.851)
                        {
                            inputType = _InputType.Forward;
                        }
                        else
                        {
                            if (thumbDir.X < 0)
                            {
                                inputType = _InputType.Left;
                            }
                            else
                            {
                                inputType = _InputType.Right;
                            }
                        }
                    }
                    else
                    {
                        // use pad cross key
                        if (src.TestButtonState(InputSystem.PadButtons.Down))
                        {
                            inputType = _InputType.Backward;
                        }
                        else if (src.TestButtonState(InputSystem.PadButtons.Up))
                        {
                            inputType = _InputType.Forward;
                        }
                        else if (src.TestButtonState(InputSystem.PadButtons.Left))
                        {
                            inputType = _InputType.Left;
                        }
                        else if (src.TestButtonState(InputSystem.PadButtons.Right))
                        {
                            inputType = _InputType.Right;
                        }
                    }

#if true
                    switch (inputType)
                    {
                    case _InputType.Forward:
                    {
                        var         nextDir      = MapLocation.GetForwardDirection(m_currentLocation.Direction);
                        MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir);
                        if (nextLocation.HasValue)
                        {
                            m_currentLocation = nextLocation.Value;
                            var pose = mapSys.GetPose(m_currentLocation);
                            m_coroutine.Start(new _MoveToTask(this, pose.TranslationVector));                                                            // no turn
                        }
                    }
                    break;

                    case _InputType.Backward:
                    {
                        var nextDir = MapLocation.GetBackwardDirection(m_currentLocation.Direction);
                        m_currentLocation.Direction = nextDir;
                        var pose = mapSys.GetPose(m_currentLocation);
                        m_coroutine.Start(new _TurnToTask(this, pose.Forward));
                    }
                    break;

                    case _InputType.Left:
                    {
                        var nextDir = MapLocation.GetLeftDirection(m_currentLocation.Direction);
                        m_currentLocation.Direction = nextDir;
                        var pose = mapSys.GetPose(m_currentLocation);
                        m_coroutine.Start(new _TurnToTask(this, pose.Forward));
                    }
                    break;

                    case _InputType.Right:
                    {
                        var nextDir = MapLocation.GetRightDirection(m_currentLocation.Direction);
                        m_currentLocation.Direction = nextDir;
                        var pose = mapSys.GetPose(m_currentLocation);
                        m_coroutine.Start(new _TurnToTask(this, pose.Forward));
                    }
                    break;
                    }
#else
                    switch (inputType)
                    {
                    case _InputType.Forward:
                    {
                        var         nextDir      = MapLocation.GetForwardDirection(m_currentLocation.Direction);
                        MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir);
                        if (nextLocation.HasValue)
                        {
                            m_currentLocation = nextLocation.Value;
                            var pose = mapSys.GetPose(m_currentLocation);
                            m_coroutine.Start(new _MoveToTask(this, pose.TranslationVector));                                                            // no turn
                        }
                    }
                    break;

                    case _InputType.Backward:
                    {
                        var         nextDir      = MapLocation.GetBackwardDirection(m_currentLocation.Direction);
                        MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir);
                        if (nextLocation.HasValue)
                        {
                            m_currentLocation = nextLocation.Value;
                            var pose = mapSys.GetPose(m_currentLocation);
                            m_coroutine.Start(Coroutine.Join(new _TurnToTask(this, pose.Forward), new _MoveToTask(this, pose.TranslationVector)));
                        }
                    }
                    break;

                    case _InputType.Left:
                    {
                        var         nextDir      = MapLocation.GetLeftDirection(m_currentLocation.Direction);
                        MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir);
                        if (nextLocation.HasValue)
                        {
                            m_currentLocation = nextLocation.Value;
                            var pose = mapSys.GetPose(m_currentLocation);
                            m_coroutine.Start(Coroutine.Join(new _TurnToTask(this, pose.Forward), new _MoveToTask(this, pose.TranslationVector)));
                        }
                    }
                    break;

                    case _InputType.Right:
                    {
                        var         nextDir      = MapLocation.GetRightDirection(m_currentLocation.Direction);
                        MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir);
                        if (nextLocation.HasValue)
                        {
                            m_currentLocation = nextLocation.Value;
                            var pose = mapSys.GetPose(m_currentLocation);
                            m_coroutine.Start(Coroutine.Join(new _TurnToTask(this, pose.Forward), new _MoveToTask(this, pose.TranslationVector)));
                        }
                    }
                    break;
                    }
#endif
                }
            }
            break;

            default:
                Debug.Fail("unsupported input device type : " + gameSys.Config.InputDevice);
                break;
            }
        }