Indiefreaks.Xna.Input.TouchMap.GetVector2Value C# (CSharp) Method

GetVector2Value() public method

public GetVector2Value ( List touches, GamePadDeadZone gamePadDeadZone ) : Vector2
touches List
gamePadDeadZone GamePadDeadZone
return Vector2
        public Vector2 GetVector2Value(List<TouchLocation> touches, GamePadDeadZone gamePadDeadZone)
        {
            TouchLocation? touch = null;
            Update(touches, ref touch);

            Vector2 result = Vector2.Zero;

            if (!touch.HasValue)
            {
                if (Static)
                {
                    _centerPosition = new Vector2(TouchArea.X + TouchArea.Width/2f, TouchArea.Y + TouchArea.Height/2f);
                    _currentPosition = _centerPosition;
                }

                result = Vector2.Zero;
            }
            else if (touch.Value.State == TouchLocationState.Pressed)
            {
                if (Static)
                    _centerPosition = new Vector2(TouchArea.X + TouchArea.Width / 2f, TouchArea.Y + TouchArea.Height / 2f);
                else
                    _centerPosition = touch.Value.Position;

                _currentPosition = touch.Value.Position;

                result = Vector2.Zero;
            }
            else if (touch.Value.State == TouchLocationState.Moved)
            {
                _currentPosition = touch.Value.Position;

                var vector = (_currentPosition - _centerPosition) / MaxThumbstickDistance;

                if (vector.LengthSquared() > 1f)
                    vector.Normalize();

                vector.Y = -vector.Y;

                switch (gamePadDeadZone)
                {
                    case GamePadDeadZone.None:
                        {
                            result = vector;
                            break;
                        }
                    case GamePadDeadZone.Circular:
                        {
                            if (vector.LengthSquared() < DeadZoneSize * DeadZoneSize)
                                vector = Vector2.Zero;
                            
                            break;
                        }
                    default:
                    case GamePadDeadZone.IndependentAxes:
                        {
                            if (Math.Abs(vector.X) < DeadZoneSize)
                                vector.X = 0f;
                            if (Math.Abs(vector.Y) < DeadZoneSize)
                                vector.Y = 0f;

                            break;
                        }   
                }

                result = vector;
            }

            return result;
        }