コード例 #1
0
ファイル: Touch.cs プロジェクト: barronds/XNARTS
        public void Init()
        {
            mCurrentGameTime = new GameTime();
            mContactCount    = eContactCount.Unknown;
            mMultiPoke_StartMaxSeparation = 0d;
            mMultiPoke_StartMaxSeparation = 0d;
            mStateMachine = new XStateMachine <eContactChange>(eContactChange.NoChange);

            txStateID start                = mStateMachine.CreateState(State_Start);
            txStateID no_contacts          = mStateMachine.CreateState(State_NoContacts);
            txStateID tracking_single_poke = mStateMachine.CreateState(State_SinglePoke);
            txStateID tracking_single_drag = mStateMachine.CreateState(State_SingleDrag);
            txStateID tracking_multi_poke  = mStateMachine.CreateState(State_MultiPoke);
            txStateID tracking_multi_drag  = mStateMachine.CreateState(State_MultiDrag);
            txStateID ignoring_contacts    = mStateMachine.CreateState(State_IgnoringContacts);
            txStateID tracking_4_contacts  = mStateMachine.CreateState(State_4Contacts);
            txStateID tracking_5_contacts  = mStateMachine.CreateState(State_5Contacts);

            mStateMachine.CreateTransition(no_contacts, tracking_single_poke, eContactChange.ZeroToOne, Transition_NoContacts_SinglePoke);
            mStateMachine.CreateTransition(no_contacts, tracking_multi_poke, eContactChange.ZeroToTwo, Transition_NoContacts_MultiPoke);
            mStateMachine.CreateTransition(no_contacts, ignoring_contacts, eContactChange.ZeroToMany, Transition_Trivial);
            mStateMachine.CreateTransition(no_contacts, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(no_contacts, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_single_poke, tracking_single_drag, eContactChange.StillToMoving, Transition_SinglePoke_SingleDrag);
            mStateMachine.CreateTransition(tracking_single_poke, no_contacts, eContactChange.OneToZero, Transition_SinglePoke_NoContacts);
            mStateMachine.CreateTransition(tracking_single_poke, tracking_multi_poke, eContactChange.OneToTwo, Transition_SinglePoke_MultiPoke);
            mStateMachine.CreateTransition(tracking_single_poke, ignoring_contacts, eContactChange.OneToMany, Transition_SinglePoke_IgnoringContacts);
            mStateMachine.CreateTransition(tracking_single_poke, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_single_poke, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_single_drag, tracking_multi_drag, eContactChange.SingleDragToMultiDrag, Transition_SingleDrag_MultiDrag);
            mStateMachine.CreateTransition(tracking_single_drag, no_contacts, eContactChange.OneToZero, Transition_SingleDrag_NoContacts);
            mStateMachine.CreateTransition(tracking_single_drag, ignoring_contacts, eContactChange.OneToMany, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_single_drag, ignoring_contacts, eContactChange.SingleDragToMultiDragTooSlow, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_single_drag, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_single_drag, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_multi_poke, no_contacts, eContactChange.TwoToZero, Transition_MultiPoke_NoContacts);
            mStateMachine.CreateTransition(tracking_multi_poke, tracking_multi_drag, eContactChange.StillToMoving, Transition_MultiPoke_MultiDrag);
            mStateMachine.CreateTransition(tracking_multi_poke, ignoring_contacts, eContactChange.TwoToOne, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_poke, ignoring_contacts, eContactChange.TwoToMany, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_poke, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_poke, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_multi_drag, no_contacts, eContactChange.TwoToZero, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_drag, ignoring_contacts, eContactChange.TwoToOne, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_drag, ignoring_contacts, eContactChange.TwoToMany, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_drag, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(tracking_multi_drag, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(ignoring_contacts, no_contacts, eContactChange.OneToZero, Transition_Trivial);
            mStateMachine.CreateTransition(ignoring_contacts, no_contacts, eContactChange.TwoToZero, Transition_Trivial);
            mStateMachine.CreateTransition(ignoring_contacts, no_contacts, eContactChange.ManyToZero, Transition_Trivial);
            mStateMachine.CreateTransition(ignoring_contacts, tracking_4_contacts, eContactChange.AnyToFour, Transition_Trivial);
            mStateMachine.CreateTransition(ignoring_contacts, tracking_5_contacts, eContactChange.AnyToFive, Transition_Trivial);

            mStateMachine.CreateTransition(start, no_contacts, eContactChange.NoInitialContacts, Transition_Trivial);
            mStateMachine.CreateTransition(start, ignoring_contacts, eContactChange.InitialContacts, Transition_Trivial);

            mStateMachine.CreateTransition(tracking_4_contacts, no_contacts, eContactChange.FourToZero, Transition_4Contacts_Any);
            mStateMachine.CreateTransition(tracking_4_contacts, ignoring_contacts, eContactChange.FourToAnyPositive, Transition_4Contacts_Any);

            mStateMachine.CreateTransition(tracking_5_contacts, no_contacts, eContactChange.FiveToZero, Transition_5Contacts_Any);
            mStateMachine.CreateTransition(tracking_5_contacts, ignoring_contacts, eContactChange.FiveToAnyPositive, Transition_5Contacts_Any);

            mStateMachine.SetStartingState(start);
        }
コード例 #2
0
ファイル: Touch.cs プロジェクト: barronds/XNARTS
        // state/transition helper functions
        private eContactChange UpdateTouchCount()
        {
            int            num_touches        = mTouches.Count();
            eContactCount  prev_contact_count = mContactCount;
            eContactChange count_change       = eContactChange.NoChange;

            eContactCount new_count = num_touches == 5 ? eContactCount.Five :
                                      num_touches == 4 ? eContactCount.Four :
                                      num_touches > 2 ? eContactCount.Many :
                                      num_touches > 1 ? eContactCount.Two :
                                      num_touches > 0 ? eContactCount.One :
                                      eContactCount.Zero;

            if (prev_contact_count == eContactCount.Zero)
            {
                count_change = new_count == eContactCount.One ? eContactChange.ZeroToOne :
                               new_count == eContactCount.Two ? eContactChange.ZeroToTwo :
                               new_count == eContactCount.Many ? eContactChange.ZeroToMany :
                               new_count == eContactCount.Four ? eContactChange.AnyToFour :
                               new_count == eContactCount.Five ? eContactChange.AnyToFive :
                               eContactChange.NoChange;
            }
            else if (prev_contact_count == eContactCount.One)
            {
                count_change = new_count == eContactCount.Zero ? eContactChange.OneToZero :
                               new_count == eContactCount.Two ? eContactChange.OneToTwo :
                               new_count == eContactCount.Many ? eContactChange.OneToMany :
                               new_count == eContactCount.Four ? eContactChange.AnyToFour :
                               new_count == eContactCount.Five ? eContactChange.AnyToFive :
                               eContactChange.NoChange;
            }
            else if (prev_contact_count == eContactCount.Two)
            {
                count_change = new_count == eContactCount.Zero ? eContactChange.TwoToZero :
                               new_count == eContactCount.One ? eContactChange.TwoToOne :
                               new_count == eContactCount.Many ? eContactChange.TwoToMany :
                               new_count == eContactCount.Four ? eContactChange.AnyToFour :
                               new_count == eContactCount.Five ? eContactChange.AnyToFive :
                               eContactChange.NoChange;
            }
            else if (prev_contact_count == eContactCount.Many)
            {
                count_change = new_count == eContactCount.Zero ? eContactChange.ManyToZero :
                               new_count == eContactCount.One ? eContactChange.ManyToOne :
                               new_count == eContactCount.Two ? eContactChange.ManyToTwo :
                               new_count == eContactCount.Four ? eContactChange.AnyToFour :
                               new_count == eContactCount.Five ? eContactChange.AnyToFive :
                               eContactChange.NoChange;
            }
            else if (prev_contact_count == eContactCount.Four)
            {
                count_change = new_count == eContactCount.Four ? eContactChange.NoChange :
                               new_count == eContactCount.Zero ? eContactChange.FourToZero :
                               eContactChange.FourToAnyPositive;
            }
            else if (prev_contact_count == eContactCount.Five)
            {
                count_change = new_count == eContactCount.Five ? eContactChange.NoChange :
                               new_count == eContactCount.Zero ? eContactChange.FiveToZero :
                               eContactChange.FiveToAnyPositive;
            }
            else if (prev_contact_count == eContactCount.Unknown)
            {
                count_change = (new_count == eContactCount.Zero) ?
                               eContactChange.NoInitialContacts :
                               eContactChange.InitialContacts;
            }
            else
            {
                XUtils.Assert(false);
            }

            mContactCount = new_count;
            return(count_change);
        }