Example #1
0
 internal TapInput(ActiveGesture gesture) : this()
 {
     PressPosition   = gesture.StartPosition;
     ReleasePosition = gesture.EndPosition;
     TapDuration     = gesture.EndTime - gesture.StartTime;
     TapDrift        = gesture.TravelDistance;
     TimeStamp       = gesture.EndTime;
 }
Example #2
0
        /// <summary>
        /// Construct a new swipe input from a given gesture.
        /// </summary>
        internal SwipeInput(ActiveGesture gesture) : this()
        {
            InputId          = gesture.InputId;
            StartPosition    = gesture.StartPosition;
            PreviousPosition = gesture.PreviousPosition;
            EndPosition      = gesture.EndPosition;
            SwipeDirection   = (EndPosition - StartPosition).normalized;
            SwipeDuration    = gesture.EndTime - gesture.StartTime;
            TravelDistance   = gesture.TravelDistance;
            SwipeSameness    = gesture.SwipeDirectionSameness;

            if (SwipeDuration > 0.0f)
            {
                SwipeVelocity = (float)(TravelDistance / SwipeDuration);
            }
        }
        private void DebugInfo(ActiveGesture gesture)
        {
            if (label == null)
            {
                return;
            }

            var builder = new StringBuilder();

            builder.AppendFormat("ID: {0}", gesture.InputId);
            builder.AppendLine();
            builder.AppendFormat("Start Position: {0}", gesture.StartPosition);
            builder.AppendLine();
            builder.AppendFormat("Position: {0}", gesture.EndPosition);
            builder.AppendLine();
            builder.AppendFormat("Duration: {0}", gesture.EndTime - gesture.StartTime);
            builder.AppendLine();
            builder.AppendFormat("Sameness: {0}", gesture.SwipeDirectionSameness);
            builder.AppendLine();
            builder.AppendFormat("Travel distance: {0}", gesture.TravelDistance);
            builder.AppendLine();
            builder.AppendFormat("Samples: {0}", gesture.Samples);
            builder.AppendLine();
            builder.AppendFormat("Realtime since startup: {0}", Time.realtimeSinceStartup);
            builder.AppendLine();
            builder.AppendFormat("Starting Timestamp: {0}", gesture.StartTime);
            builder.AppendLine();
            builder.AppendFormat("Ending Timestamp: {0}", gesture.EndTime);
            builder.AppendLine();

            label.text = builder.ToString();

            var worldStart = Camera.main.ScreenToWorldPoint(gesture.StartPosition);
            var worldEnd   = Camera.main.ScreenToWorldPoint(gesture.EndPosition);

            worldStart.z += 5;
            worldEnd.z   += 5;
        }
        private void OnPressedFirst(PointerInput input, double time)
        {
            Debug.Assert(!activeGestures.ContainsKey(input.InputId));

            var newGesture = new ActiveGesture(input.InputId, input.Position, time);

            activeGestures.Add(input.InputId, newGesture);

            DebugInfo(newGesture);

            _posLastFirst = input.Position;

            if (_secondPressed)
            {
                _pinching = true;

                _pinchPosStartFirst  = _posLastFirst;
                _pinchPosStartSecond = _posLastSecond;

                _pinchStartDistance = Vector2.Distance(_pinchPosStartFirst, _pinchPosStartSecond);
                _pinchLastDistance  = _pinchStartDistance;

                PinchStarted?.Invoke(new PinchInput()
                {
                    InputId                 = input.InputId,
                    PinchDeltaDistance      = 0,
                    PinchDistance           = _pinchStartDistance,
                    Pointer0CurrentPosition = _pinchPosStartFirst,
                    Pointer0StartPosition   = _pinchPosStartFirst,
                    Pointer1CurrentPosition = _pinchPosStartSecond,
                    Pointer1StartPosition   = _pinchPosStartSecond
                });
            }

            PressedFirst?.Invoke(new SwipeInput(newGesture));
        }
 /// <summary>
 /// Checks whether a given active gesture will be a valid tap.
 /// </summary>
 private bool IsValidTap(ref ActiveGesture gesture)
 {
     return(gesture.TravelDistance <= maxTapDrift &&
            (gesture.StartTime - gesture.EndTime) <= maxTapDuration);
 }
 /// <summary>
 /// Checks whether a given active gesture will be a valid swipe.
 /// </summary>
 private bool IsValidSwipe(ref ActiveGesture gesture)
 {
     return(gesture.TravelDistance >= minSwipeDistance &&
            (gesture.StartTime - gesture.EndTime) <= maxSwipeDuration &&
            gesture.SwipeDirectionSameness >= swipeDirectionSamenessThreshold);
 }