Exemplo n.º 1
0
 public Cluster(TouchInput point)
 {
     this.AddPoint(point.Id);
     this.Hash = "#" + point.Id;
     this.Centroid = point.Position;
     _state = ClusterState.Invalid;
 }
Exemplo n.º 2
0
 public bool Equals(TouchInput other)
 {
     if (this.Position.x == other.Position.x || this.Position.y == other.Position.y)
         return true;
     else
         return false;
 }
Exemplo n.º 3
0
        public bool Equals(TouchInput other, float pxThreshold)
        {
            float dist = Vector2.Distance(this.Position, other.Position);

            if (dist <= pxThreshold)
                return true;
            else
                return false;
        }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
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.Hash = ClusterUtils.GetPointsHash(_pointsIds.ToArray<int>());

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

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

            return this;
        }
Exemplo n.º 6
0
        /// <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;
        }
Exemplo n.º 7
0
 internal void Update(TouchInput t)
 {
     this._id = t.Id;
     this._position = t.Position;
     this._state = t.State;
 } 
Exemplo n.º 8
0
 internal FingerTouch(TouchInput t)
 {
     this._id = t.Id;
     this._position = t.Position;
     this._state = t.State;
 }
Exemplo n.º 9
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.Hash;
                        _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.Hash = ClusterUtils.GetPointsHash(_pointsIds.ToArray<int>());
         //       }
        //        else
                

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

            }

            UpdateCentroid();            
            
            return new Cluster[] { this ,newCluster };

        }