예제 #1
0
        /// <summary>
        /// Calculate the stick's direction and magnitude
        /// </summary>
        /// <param name="pos">The current left touch position</param>
        public void EvaluatePoint(Vector2 pos, float dt)
        {
            StickDirection = pos - StartLocation;
            float stickLength = StickDirection.Length();

            if (stickLength <= DeadZoneSize)
            {
                StickDirection = Vector2.Zero;
                StickMagnitude = 0.0f;
            }
            else
            {
                var tmp = StickDirection;
                tmp.Normalize();
                StickDirection = new Vector2(tmp.X, tmp.Y * -1f);
                if (stickLength < AliveZoneSize)
                {
                    StickMagnitude = stickLength / AliveZoneSize;
                    StickDirection = new Vector2(StickDirection.X * StickMagnitude, StickDirection.Y * StickMagnitude);
                }
                else
                {
                    StickMagnitude = 1.0f;

                    if (StickStyle == TouchStickStyle.FreeFollow && stickLength > AliveZoneSize * AliveZoneFollowFactor)
                    {
                        Vector2 targetLoc = new Vector2(
                            pos.X - StickDirection.X * AliveZoneSize * AliveZoneFollowFactor,
                            pos.Y + StickDirection.Y * AliveZoneSize * AliveZoneFollowFactor);

                        StartLocation = GetNewStartLocation(StartLocation, targetLoc, stickLength, dt);
                    }
                }
            }
        }