Beispiel #1
0
        /// <summary>
        /// Return appropriate behaviour based on the position of the HaptiQ within 
        /// this HapticRectangle
        /// </summary>
        /// <param name="haptiQ"></param>
        /// <returns></returns>
        protected override IBehaviour chooseBehaviour(HaptiQ haptiQ)
        {
            IBehaviour behaviour = null;

            Point bottomLeft = new Point(x, y + height);
            Point bottomRight = new Point(x + width, y + height);
            Point topLeft = new Point(x, y);
            Point topRight = new Point(x + width, y);

            List<Tuple<Point, Point>> lines = new List<Tuple<Point, Point>>();
            if (pointIsCloseToSegment(haptiQ.position, bottomLeft, bottomRight, CORNER_NEARNESS_TOLLERANCE) &&
                pointIsCloseToSegment(haptiQ.position, bottomLeft, topLeft, CORNER_NEARNESS_TOLLERANCE)) // bottom-left corner
            {
                lines.Add(new Tuple<Point, Point>(bottomLeft, bottomRight));
                lines.Add(new Tuple<Point, Point>(bottomLeft, topLeft));
            }
            else if (pointIsCloseToSegment(haptiQ.position, topLeft, topRight, CORNER_NEARNESS_TOLLERANCE) &&
                    pointIsCloseToSegment(haptiQ.position, topLeft, bottomLeft, CORNER_NEARNESS_TOLLERANCE)) // top-left corner
            {
                lines.Add(new Tuple<Point, Point>(topLeft, topRight));
                lines.Add(new Tuple<Point, Point>(topLeft, bottomLeft));
            }
            else if (pointIsCloseToSegment(haptiQ.position, topRight, topLeft, CORNER_NEARNESS_TOLLERANCE) &&
                pointIsCloseToSegment(haptiQ.position, topRight, bottomRight, CORNER_NEARNESS_TOLLERANCE)) // top-right corner
            {
                lines.Add(new Tuple<Point, Point>(topRight, topLeft));
                lines.Add(new Tuple<Point, Point>(topRight, bottomRight));
            }
            else if (pointIsCloseToSegment(haptiQ.position, bottomRight, topRight, CORNER_NEARNESS_TOLLERANCE) &&
                pointIsCloseToSegment(haptiQ.position, bottomRight, bottomLeft, CORNER_NEARNESS_TOLLERANCE)) // bottom-right corner
            {
                lines.Add(new Tuple<Point, Point>(bottomRight, topRight));
                lines.Add(new Tuple<Point, Point>(bottomRight, bottomLeft));
            }
            else if (pointIsCloseToSegment(haptiQ.position, bottomLeft, bottomRight, NEARNESS_TOLLERANCE)) // horizontal
            {
                lines.Add(new Tuple<Point, Point>(bottomLeft, bottomRight));
            }
            else if (pointIsCloseToSegment(haptiQ.position, topLeft, topRight, NEARNESS_TOLLERANCE)) // horizontal
            {
                lines.Add(new Tuple<Point, Point>(topLeft, topRight));
            }
            else if (pointIsCloseToSegment(haptiQ.position, topLeft, bottomLeft, NEARNESS_TOLLERANCE)) // vertical
            {
                lines.Add(new Tuple<Point, Point>(topLeft, bottomLeft));
            }
            else if (pointIsCloseToSegment(haptiQ.position, topRight, bottomRight, NEARNESS_TOLLERANCE)) // vertical
            {
                lines.Add(new Tuple<Point, Point>(topRight, bottomRight));
            }
            else
            {
                behaviour = new BasicBehaviour(haptiQ, BasicBehaviour.TYPES.max);
            }
                   
            if (behaviour == null)
            {
                behaviour = new EdgeCornerBehaviour(haptiQ, lines);
            }
               
            return behaviour;
        }
Beispiel #2
0
        /// <summary>
        /// Handle behaviours on input
        /// </summary>
        /// <param name="haptiQ"></param>
        /// <returns></returns>
        public Tuple<BEHAVIOUR_RULES, IBehaviour, IBehaviour> handleInput(HaptiQ haptiQ)
        {
            if (this.Parent != null)
            {
                Tuple<STATE, IBehaviour> HaptiQState = _HaptiQBehaviours.ContainsKey(haptiQ.getID()) ? _HaptiQBehaviours[haptiQ.getID()] : null;
                if (pointIsInside(haptiQ.position))
                {
                    IBehaviour prevBehaviour = HaptiQState != null ? HaptiQState.Item2 : null;
                    IBehaviour currentBehaviour = chooseBehaviour(haptiQ);
                    currentBehaviour.updateNext(prevBehaviour);

                    BEHAVIOUR_RULES rule = BEHAVIOUR_RULES.SUBS;
                    if (currentBehaviour.Equals(prevBehaviour))
                    {
                        rule = BEHAVIOUR_RULES.NOPE;
                    }
                    _HaptiQBehaviours[haptiQ.getID()] = new Tuple<STATE, IBehaviour>(STATE.down, currentBehaviour);
                    return new Tuple<BEHAVIOUR_RULES, IBehaviour, IBehaviour>(rule, currentBehaviour, prevBehaviour);
                }
                else if (HaptiQState != null && HaptiQState.Item1 == STATE.down)
                {
                    IBehaviour prevBehaviour = HaptiQState.Item2;
                    IBehaviour currentBehaviour = new BasicBehaviour(haptiQ, BasicBehaviour.TYPES.flat);
                    BEHAVIOUR_RULES rule = BEHAVIOUR_RULES.SUBS;
                    if (currentBehaviour.Equals(prevBehaviour))
                    {
                        rule = BEHAVIOUR_RULES.NOPE;
                    }
                    _HaptiQBehaviours[haptiQ.getID()] = new Tuple<STATE, IBehaviour>(STATE.up, currentBehaviour);
                    return new Tuple<BEHAVIOUR_RULES, IBehaviour, IBehaviour>(rule, currentBehaviour, prevBehaviour);
                }
            }

            Tuple<BEHAVIOUR_RULES, IBehaviour, IBehaviour> retval = 
                new Tuple<BEHAVIOUR_RULES, IBehaviour, IBehaviour>(BEHAVIOUR_RULES.REMOVE,
                    _HaptiQBehaviours.ContainsKey(haptiQ.getID()) ? _HaptiQBehaviours[haptiQ.getID()].Item2 : null, null);
            _HaptiQBehaviours[haptiQ.getID()] = new Tuple<STATE, IBehaviour>(STATE.up, null);
            return retval;
        }