Beispiel #1
0
 /// <summary>
 /// Creates a Cluster instance from a single TouchInput
 /// </summary>
 /// <param name="point"></param>
 public Cluster(TouchInput point)
 {
     this.AddPoint(point.Id);
     this._hashId   = "#" + point.Id;
     this._centroid = point.Position;
     _state         = ClusterState.Invalid;
 }
Beispiel #2
0
 /// <summary>
 /// Creates a Cluster instance from a single TouchInput
 /// </summary>
 /// <param name="point"></param>
 public Cluster(TouchInput point)
 {
     this.AddPoint(point.Id);
     this._hashId = "#" + point.Id;
     this._centroid = point.Position;
     _state = ClusterState.Invalid;
 }
 /// <summary>
 /// Checks if current TouchInput is in the same position with specified one  
 /// </summary>
 /// <param name="other">TouchInput to compare with current</param>
 /// <returns>true if other is in same position</returns>
 public bool Equals(TouchInput other)
 {
     if (this.Position.x == other.Position.x || this.Position.y == other.Position.y)
         return true;
     else
         return false;
 }
Beispiel #4
0
 /// <summary>
 /// Checks if current TouchInput is in the same position with specified one
 /// </summary>
 /// <param name="other">TouchInput to compare with current</param>
 /// <returns>true if other is in same position</returns>
 public bool Equals(TouchInput other)
 {
     if (this.Position.x == other.Position.x || this.Position.y == other.Position.y)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 internal static void AddFingerTouch(TouchInput t)
 {
     FingerTouch finger;
     if (_touches.TryGetValue(t.Id, out finger))
     {
         finger.Update(t);
         _touches[t.Id] = finger;
     }
     else
         _touches[t.Id] = new FingerTouch(t);
 }
Beispiel #6
0
        /// <summary>
        /// Checks if current TouchInput is in the same position with specified within
        ///  a pixel distance threshold
        /// </summary>
        /// <param name="other">TouchInput to compare with current</param>
        /// <param name="pxThreshold">TouchInput comparison threshold in pixels </param>
        /// <returns>true if comparison is successfull</returns>
        public bool Equals(TouchInput other, float pxThreshold)
        {
            float dist = Vector2.Distance(this.Position, other.Position);

            if (dist <= pxThreshold)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #7
0
        public Cluster AddPoint(int touchId)
        {
            TouchInput touch = new TouchInput(touchId, InternalTouches.List[touchId].Position, InternalTouches.List[touchId].State);

            _pointsIds.Add(touchId);
            _points.Add(touchId, touch);
            UpdateCentroid();
            this._hashId = GetPointsHash(_pointsIds.ToArray <int>());

            if (_pointsIds.Count == 4)
            {
                this._state = ClusterState.Unidentified;
            }

            else if (_pointsIds.Count > 4)
            {
                this._state = ClusterState.Invalid;
            }

            return(this);
        }
 internal void Update(TouchInput t)
 {
     this._id = t.Id;
     this._position = t.Position;
     this._state = t.State;
 }
 internal FingerTouch(TouchInput t)
 {
     this._id = t.Id;
     this._position = t.Position;
     this._state = t.State;
 }
Beispiel #10
0
        public Cluster[] UpdatePoint(int touchId)
        {
            Cluster newCluster;
            if (Vector2.Distance(this.Centroid, InternalTouches.List[touchId].Position) < ClusterManager.Instance.ClusterDistThreshold)
            {
                //Point still in clustrer
                _points[touchId] = new TouchInput(touchId, InternalTouches.List[touchId].Position, TouchState.Moved);
                newCluster = null;

                if (State == ClusterState.Identidied)
                    _state = ClusterState.Updated;
            }
            else
            {
                //Point has moved out of the cluster
                //Handle current Cluster

                //If it was just one point then we must cancel the cluster!!!!!!
                //       if (_pointsIds.Count != 1)
                //       {
                _pointsIds.Remove(touchId);
                _points.Remove(touchId);

                if (_state == ClusterState.Identidied || _state == ClusterState.Updated)
                {
                    _state = ClusterState.Cancelled;
                    _cancelledHash = this._hashId;
                    _cancelledPointsIds.Add(touchId);
                }

                else if (State == ClusterState.Cancelled)
                    _cancelledPointsIds.Add(touchId);

                else if (_pointsIds.Count == 4)
                    _state = ClusterState.Unidentified;

                else
                    _state = ClusterState.Invalid;

                //Update new Hash
                this._hashId = GetPointsHash(_pointsIds.ToArray<int>());
                //       }
                //        else

                newCluster = new Cluster(InternalTouches.List[touchId]);

            }

            UpdateCentroid();

            return new Cluster[] { this, newCluster };
        }
Beispiel #11
0
        public Cluster AddPoint(int touchId)
        {
            TouchInput touch = new TouchInput(touchId, InternalTouches.List[touchId].Position, InternalTouches.List[touchId].State);
            _pointsIds.Add(touchId);
            _points.Add(touchId, touch);
            UpdateCentroid();
            this._hashId = GetPointsHash(_pointsIds.ToArray<int>());

            if (_pointsIds.Count == 4)
                this._state = ClusterState.Unidentified;

            else if (_pointsIds.Count > 4)
                this._state = ClusterState.Invalid;

            return this;
        }
Beispiel #12
0
        public Cluster[] UpdatePoint(int touchId)
        {
            Cluster newCluster;

            if (Vector2.Distance(this.Centroid, InternalTouches.List[touchId].Position) < ClusterManager.Instance.ClusterDistThreshold)
            {
                //Point still in clustrer
                _points[touchId] = new TouchInput(touchId, InternalTouches.List[touchId].Position, TouchState.Moved);
                newCluster       = null;

                if (State == ClusterState.Identidied)
                {
                    _state = ClusterState.Updated;
                }
            }
            else
            {
                //Point has moved out of the cluster
                //Handle current Cluster

                //If it was just one point then we must cancel the cluster!!!!!!
                //       if (_pointsIds.Count != 1)
                //       {
                _pointsIds.Remove(touchId);
                _points.Remove(touchId);

                if (_state == ClusterState.Identidied || _state == ClusterState.Updated)
                {
                    _state         = ClusterState.Cancelled;
                    _cancelledHash = this._hashId;
                    _cancelledPointsIds.Add(touchId);
                }

                else if (State == ClusterState.Cancelled)
                {
                    _cancelledPointsIds.Add(touchId);
                }

                else if (_pointsIds.Count == 4)
                {
                    _state = ClusterState.Unidentified;
                }

                else
                {
                    _state = ClusterState.Invalid;
                }

                //Update new Hash
                this._hashId = GetPointsHash(_pointsIds.ToArray <int>());
                //       }
                //        else


                newCluster = new Cluster(InternalTouches.List[touchId]);
            }

            UpdateCentroid();

            return(new Cluster[] { this, newCluster });
        }
        /// <summary>
        /// Given an array of TouchInputs finds the two furthes apart
        /// </summary>
        /// <param name="points">Array of TouchInputs</param>
        /// <returns>The two furthest TouchInputs indexes</returns>
        private int[] FindTwoFurthestPoints(TouchInput[] points)
        {
            int[] result = new int[2];
            float maxDist = 0.0f;
            float currentDist = 0.0f;

            for (int i = 0; i < points.Length; i++)
            {
                for (int j = i + 1; j < points.Length; j++)
                {
                    currentDist = Vector2.Distance(points[i].Position, points[j].Position);

                    if (currentDist > maxDist)
                    {
                        //Found new max
                        maxDist = currentDist;
                        result[0] = points[i].Id;
                        result[1] = points[j].Id;
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// Checks if current TouchInput is in the same position with specified within
        ///  a pixel distance threshold 
        /// </summary>
        /// <param name="other">TouchInput to compare with current</param>
        /// <param name="pxThreshold">TouchInput comparison threshold in pixels </param>
        /// <returns>true if comparison is successfull</returns>
        public bool Equals(TouchInput other, float pxThreshold)
        {
            float dist = Vector2.Distance(this.Position, other.Position);

            if (dist <= pxThreshold)
                return true;
            else
                return false;
        }