Esempio n. 1
0
        public void AddTouch(TouchPt touch)
        {
            TouchPt existingTouch;

            if (GetExistingTouch(touch, out existingTouch))
            {
                existingTouch.Update(touch);
                touch = existingTouch;
            }

            _touchList.Add(touch);
        }
Esempio n. 2
0
        public void Update(TouchPt touch)
        {
            if (fingerId != touch.fingerId)
            {
                throw new InvalidOperationException(string.Format("Cannot update touch ID {0} from ID {1}", fingerId, touch.fingerId));
            }

            // Update all information except timeBegan and timeEnded
            deltaPosition = touch.deltaPosition;
            deltaTime     = touch.deltaTime;
            phase         = touch.phase;
            position      = touch.position;
            rawPosition   = touch.rawPosition;
            tapCount      = touch.tapCount;
        }
Esempio n. 3
0
        private bool GetExistingTouch(TouchPt touch, out TouchPt existingTouch)
        {
            int index = FindIndex(_tempTouchList, touch.fingerId);

            if (index != -1)
            {
                existingTouch = _tempTouchList[index];
                _tempTouchList.RemoveAt(index);
                return(true);
            }

            index = FindIndex(_lingeringTouchPts, touch.fingerId);
            if (index != -1)
            {
                existingTouch = _lingeringTouchPts[index];
                _lingeringTouchPts.RemoveAt(index);
                return(true);
            }

            // Didn't have a match on fingerId. Try to match position up with any
            // lingering touches
            // Start with bestDistance set to the maximum allowable
            float maxDistance  = MultiselectEventSystem.current.MaxDoubleClickDistancePixels;
            float bestDistance = maxDistance * maxDistance;
            int   bestIndex    = -1;

            for (int i = 0; i < _lingeringTouchPts.Count; i++)
            {
                float sqrDistance = (_lingeringTouchPts[i].position - touch.position).sqrMagnitude;
                if (sqrDistance < bestDistance)
                {
                    bestDistance = sqrDistance;
                    bestIndex    = i;
                }
            }
            if (bestIndex != -1)
            {
                existingTouch = _lingeringTouchPts[bestIndex];
                _lingeringTouchPts.RemoveAt(bestIndex);
                return(true);
            }
            existingTouch = default(TouchPt);
            return(false);
        }
Esempio n. 4
0
        protected void EvaluateRelativeMotion(MultiTouchPointerEventData eventData)
        {
            NumInward        = 0;
            NumOutward       = 0;
            NumOffAxisCW     = 0;
            NumOffAxisCCW    = 0;
            NumMatchCentroid = 0;
            NumAntiCentroid  = 0;

            NumNearCenter = 0;
            DeltaPinch    = Vector2.zero;
            DeltaRotate   = 0;

            float clusterRadius = eventData.touchCluster.Radius;

            Vector2 centroidDelta = eventData.centroidPosition - GestureData.PriorCluster.Centroid;

            foreach (var entry in eventData.touchCluster.Touches)
            {
                TouchPt currentTouch = entry.Value;
                TouchPt normalizedPriorTouch;
                if (NormalizedPriorCluster.Touches.TryGetValue(entry.Key, out normalizedPriorTouch))
                {
                    float   dot;
                    Vector2 rawMove = currentTouch.position - GestureData.PriorCluster.Touches[currentTouch.fingerId].position;
                    if (rawMove.sqrMagnitude > 0.5f)
                    {
                        dot = Vector2.Dot(centroidDelta.normalized, rawMove.normalized);
                        if (Mathf.Abs(dot) >= (1.0f - DragTollerance))
                        {
                            NumMatchCentroid++;
                        }
                        else
                        {
                            NumAntiCentroid++;
                        }
                    }
                    Vector2 fromCentroid = eventData.touchCluster.GetRelativeTouchVector(entry.Key);
                    if (!Mathf.Approximately(clusterRadius, 0f))
                    {
                        if (fromCentroid.magnitude / clusterRadius < CloseToCenterRatio)
                        {
                            NumNearCenter++;
                        }
                    }

                    Vector2 delta          = currentTouch.position - normalizedPriorTouch.position;
                    float   deltaMagnitude = delta.magnitude;
                    dot = Vector2.Dot(fromCentroid.normalized, delta.normalized);
                    float absDot = Mathf.Abs(dot);

                    if (1.0f - absDot < PinchTollerance)
                    {
                        if (dot > 0)
                        {
                            NumOutward++;
                            DeltaPinch += delta.Abs();
                        }
                        else
                        {
                            NumInward++;
                            DeltaPinch -= delta.Abs();
                        }
                    }
                    else if (absDot < RotateTollerance)
                    {
                        float dotPerp = Vector2.Dot(fromCentroid.Perp(), delta);
                        if (dotPerp < 0)
                        {
                            NumOffAxisCW++;
                            DeltaRotate += deltaMagnitude / fromCentroid.magnitude;
                        }
                        else
                        {
                            NumOffAxisCCW++;
                            DeltaRotate -= deltaMagnitude / fromCentroid.magnitude;
                        }
                    }
                }
            }
            if (NumOffAxisCCW > 0 || NumOffAxisCW > 0)
            {
                DeltaRotate = Mathf.Atan2(DeltaRotate, 1f) * Mathf.Rad2Deg;
                if (DeltaRotate > 180f)
                {
                    DeltaRotate -= 360f;
                }
            }
        }
Esempio n. 5
0
 public void AddTouch(TouchPt touch)
 {
     _touchPoints.Add(touch);
 }
Esempio n. 6
0
 private bool IsTouchToFind(TouchPt t)
 {
     return(t.fingerId == _touchToFind);
 }