示例#1
0
 public SwipeState(SwipeState s)
 {
     this._start = s._start;
     this._end = s._end;
     this._pos = s.Pos;
     this._loc = s._loc;
 }
示例#2
0
        public ScenarioState finishState(ScenarioState next)
        {
            SwipeState swipeState = new SwipeState(this);
            // make sure these are the same type
            if (next.GetType().Equals(this.GetType()))
            {
                // make sure this is not state
                if (!this.isSameState(next))
                {
                    SwipeState nextState = (SwipeState)next;

                    // make gualState's start be the earlier of the two
                    if (nextState._start.CompareTo(swipeState._start) < 0)
                    {
                        swipeState._start = nextState._start;
                    }
                    // make gualState's start be the later of the two
                    if (nextState._end.CompareTo(swipeState._end) > 0)
                    {
                        swipeState._end = nextState._end;
                    }

                    if (this.Pos.Equals(SwipePosition.START) && nextState.Pos.Equals(SwipePosition.MOVING))
                    {
                        // if going from start state to moving state
                        // make the capped start state have the same location as moving state
                        swipeState._loc = nextState._loc;
                    }

                }
            }
            return swipeState;
        }
示例#3
0
        public void processSkeleton(Skeleton skeleton)
        {
            if (skeleton == null || this._history.History.Count == 0)
            {
                SwipeState currentState = new SwipeState(SwipePosition.NEUTRAL, DateTime.Now, DateTime.Now, new Point3D(0, 0, 0));
                this._history.addState(currentState);
                return;
            }
            this.Skeleton = skeleton;
            double armLength = this.computeArmLength();

            // determine currentState (i.e. last state on the history)
            ScenarioState ss = this._history.Peek();
            if (ss is SwipeState)
            {
                SwipeState prevState = (SwipeState)ss;

                if (prevState.End.CompareTo(DateTime.Now) >= 0)
                {
                    return;
                }
                Point3D handLocation = this.getHandLocation();

                // if curr is neutral
                // check if its straight
                if (prevState.Pos.Equals(SwipePosition.NEUTRAL))
                {
                    // determine whether arm is straight out
                    //

                    //TODO: MAKE THIS HAPPEN
                    Boolean isArmStraight = this.isArmStraight();
                    Boolean isHandInValidStartBoxLocation = this.isHandInValidStartBoxLocation();
                    Boolean isArmShoulderHeight = this.isArmShoulderHeight();
                    if (isArmStraight && isHandInValidStartBoxLocation && isArmShoulderHeight)
                    {
                        // create a start state with position
                        this._direction = VolumeSwipeDirection.CENTER;
                        SwipeState currentState = new SwipeState(SwipePosition.START, DateTime.Now, DateTime.Now, handLocation);
                        this._history.addState(currentState);
                    }
                }
                else if (prevState.Pos.Equals(SwipePosition.START))
                {
                    // previous state was start state
                    // two things happen
                    // still in start state, but moved within box
                    // or just turned into a move state
                    Boolean isHandInStartBox = this.isHandInStartBox();

                    if (isHandInStartBox)
                    {
                        // still start state
                        // just merge it
                        this._direction = VolumeSwipeDirection.CENTER;
                        SwipeState currentState = new SwipeState(SwipePosition.START, DateTime.Now, DateTime.Now, handLocation);
                        this._history.addState(currentState);
                    }
                    else
                    {
                        // went outside start box

                        Boolean isValidSwipeDirection = this.isValidSwipeDirection();
                        if (isValidSwipeDirection)
                        {
                            // hand moved in valid swipe direction, keep it moving
                            this._startBoxShoulderLocation = this.getShoulderLocation();
                            this._direction = this.computeCurrentSwipeDirection();

                            SwipeState currentState = new SwipeState(SwipePosition.MOVING, DateTime.Now, DateTime.Now, handLocation);
                            this._history.addState(currentState);
                        }
                        else
                        {
                            this._direction = VolumeSwipeDirection.NULL;
                            // hand moved outside of box in wrong direction or in bad position relating to cross line
                            // make it neutral
                            SwipeState currentState = new SwipeState(SwipePosition.NEUTRAL, DateTime.Now, DateTime.Now, handLocation);
                            this._history.addState(currentState);
                        }

                    }

                }
                else if (prevState.Pos.Equals(SwipePosition.MOVING))
                {
                    Boolean isWithinCorridor = this.isWithinCorridor();
                    Boolean isAfterFinishLine = this.isAfterFinishLine();
                    if (isWithinCorridor && isAfterFinishLine)
                    {
                        // add 3 seconds to make the state not destroyed by smoothing
                        this._direction = this.computeCurrentSwipeDirection();
                        SwipeState currentState = new SwipeState(SwipePosition.END, DateTime.Now, DateTime.Now, handLocation);
                        this._history.addState(currentState);
                    }
                    else if (isWithinCorridor)
                    {
                        this._direction = this.computeCurrentSwipeDirection();
                        SwipeState currentState = new SwipeState(SwipePosition.MOVING, DateTime.Now, DateTime.Now, handLocation);
                        this._history.addState(currentState);
                    }
                    else
                    {

                    Boolean isWithinCorridor2 = this.isWithinCorridor();
                    Boolean isAfterFinishLine2 = this.isAfterFinishLine();
                        // hand moved outside of box in wrong direction or in bad position relating to cross line
                        // make it neutral
                        this._direction = VolumeSwipeDirection.NULL;
                        SwipeState currentState = new SwipeState(SwipePosition.NEUTRAL, DateTime.Now, DateTime.Now, handLocation);
                        this._history.addState(currentState);
                    }
                }
                else if (prevState.Pos.Equals(SwipePosition.END))
                {
                    Boolean isWithinCorridor = this.isWithinCorridor();
                    Boolean isAfterFinishLine = this.isAfterFinishLine();
                    if (isAfterFinishLine)
                    {
                        this._direction = this.computeCurrentSwipeDirection();
                        SwipeState currentState = new SwipeState(SwipePosition.END, DateTime.Now, DateTime.Now, handLocation);
                        this._history.addState(currentState);
                    }
                    else if (isWithinCorridor && !isAfterFinishLine)
                    {
                        this._direction = this.computeCurrentSwipeDirection();
                        SwipeState currentState = new SwipeState(SwipePosition.MOVING, DateTime.Now, DateTime.Now, handLocation);
                        this._history.addState(currentState);
                    }
                    else
                    {
                        this._direction = VolumeSwipeDirection.NULL;
                        // prev state was end.  Now add neutral
                        SwipeState currentState = new SwipeState(SwipePosition.NEUTRAL, DateTime.Now, DateTime.Now, handLocation);
                        this._history.addState(currentState);
                    }
                }

            }
        }
示例#4
0
        /// <summary>
        /// when swipes get merged, their start and end times get merged
        /// the most recent position becomes the poisiton
        /// </summary>
        /// <param name="next"></param>
        /// <returns></returns>
        public ScenarioState mergeEqualStates(ScenarioState next)
        {
            SwipeState swipeState = new SwipeState(this);
            // make sure this is same state
            if (this.isSameState(next))
            {
                if (next.GetType().Equals(this.GetType()))
                {
                    SwipeState nextState = (SwipeState)next;

                    // make gualState's start be the earlier of the two
                    if (nextState._start.CompareTo(swipeState._start) < 0)
                    {
                        swipeState._start = nextState._start;

                    }

                    // make gualState's end be the later of the two
                    // and make its loc the one of the later state
                    if (nextState._end.CompareTo(swipeState._end) > 0)
                    {
                        swipeState._end = nextState._end;
                        if (nextState.Pos.Equals(SwipePosition.MOVING))
                        {
                            // only merge state location if merging two moving states
                            swipeState._loc = nextState.Loc;
                        }
                    }
                }
            }

            return swipeState;
        }