예제 #1
0
 private void OnTextAnimated(HandType handType)
 {
     /*if(handType == HandType.StraightFlush)
      * {
      *  PsFireworks.Play();
      * }*/
 }
예제 #2
0
        public static Finger GetFinger(GameObject parent, FingerIndex index, HandType handType, Hand hand, device_type_t deviceType,
                                       GameObject phalange0, GameObject phalange1, GameObject phalange2)
        {
            Finger finger;

            switch (handType)
            {
            case HandType.Normal:
                finger = parent.AddComponent <RegularFinger>();
                break;

            case HandType.Physics:
                finger = parent.AddComponent <PhysicsFinger>();
                break;

            default:
                finger = parent.AddComponent <RegularFinger>();
                break;
            }
            finger.Index      = index;
            finger.HandType   = handType;
            finger.DeviceType = deviceType;
            finger.PhalangesGameObjects[1] = phalange0;
            finger.PhalangesGameObjects[2] = phalange1;
            finger.PhalangesGameObjects[3] = phalange2;
            finger.Hand = hand;
            return(finger);
        }
예제 #3
0
        public static int ScoreHand(List <Card> hand, Card sharedCard, HandType handType)
        {
            int score = 0;

            score += ScoreNibs(hand, sharedCard);                    // this is the only one where it matters which particular card is shared

            //
            //   DON't SORT BEFORE NIBS!!!
            List <Card> cards = new List <Card>(hand);

            if (sharedCard != null) // sharedCard null when calculating value of hand prior to seeing the shared card
            {
                cards.Add(sharedCard);
            }

            cards.Sort(Card.CompareCardsByRank);

            score += ScoreFifteens(cards);
            score += ScorePairs(cards);
            score += ScoreRuns(cards);
            score += ScoreFlush(cards, handType);


            return(score);
        }
예제 #4
0
        private static int ScoreFlush(List <Card> cards, HandType handType)
        {
            cards.Sort(Card.CompareCardsBySuit);
            int max = 0;
            int run = 1;

            for (int i = 0; i < cards.Count - 1; i++)
            {
                if (cards[i].Suit == cards[i + 1].Suit)
                {
                    run++;
                }
                else
                {
                    if (run > max)
                    {
                        max = run;
                    }
                    run = 1;
                }
            }

            if (handType == HandType.Crib && run == 5)
            {
                return(run);
            }

            if (handType == HandType.Regular && run > 3)
            {
                return(run);
            }

            return(0);
        }
예제 #5
0
        public HandEventType GetHandState(HandType handType)
        {
            HandEventType handEventType = HandEventType.None;

            if (!InteractionManager.Instance.IsInteractionInited())
            {
                return(handEventType);
            }
            else
            {
                switch (handType)
                {
                case HandType.Left:
                    handEventType = InteractionManager.Instance.GetLastLeftHandEvent();
                    break;

                case HandType.Right:
                    handEventType = InteractionManager.Instance.GetLastRightHandEvent();
                    break;

                default:
                    break;
                }
            }
            return(handEventType);
        }
예제 #6
0
        public void TestHandType(int handId, HandType expectedHandType, int expectedScore)
        {
            var score = new TexasHoldemHand.TexasHoldemScore(testCaseDictionary[handId]);

            Assert.AreEqual(expectedHandType, score.HandType);
            Assert.AreEqual(expectedScore, score.GetScore());
        }
예제 #7
0
 /// <summary>
 /// Place the building when grabbing
 /// </summary>
 /// <param name="hand">The hand that performed the grab</param>
 public override void OnOpen(HandType hand)
 {
     if (this.CanSwitchState() && this.hasPointed && (hand == HandType.LEFT || hand == HandType.RIGHT))
     {
         this.PlaceBuilding();
     }
 }
예제 #8
0
 /// <summary>
 /// If colliding with an other object, the indicator turns red and you cannot place a building.
 /// </summary>
 /// <param name="gameObject">the game object that was pointed at</param>
 /// <param name="handType">The hand that is pointing</param>
 public override void OnPoint(GameObject gameObject, HandType handType)
 {
     if (this.handType == handType)
     {
         this.ChangeOutlineRender(Color.red);
     }
 }
예제 #9
0
    /// <summary>
    /// Changes hands at will
    /// </summary>
    /// <param name="handType">Hand type to switch to</param>
    /// <param name="initialisation">Is this called during initialisation? (leave this to false during the game)</param>
    public void ShowHand(HandType handType, bool initialisation = false)
    {
        if (!initialisation && currentHand == null && handType == HandType.NONE) return;
        if (currentHand != null && currentHand.type == handType) return;

        foreach (var h in handsDictionary.Values) h.Hide();

        if (handType != HandType.NONE)
        {
            if (!handsDictionary.ContainsKey(handType))
            {
                Debug.LogError("You did not create a hand of type " + handType + "!");
                return;
            }

            if (currentHand == null || currentHand.type == HandType.NONE)
                handsDictionary[handType].Show();
            else
                handsDictionary[handType].ShowLater();
            this.currentHand = handsDictionary[handType];
        }
        else
        {
            this.currentHand = null;
        }
    }
예제 #10
0
        public static int GetHandValue(HandType value)
        {
            switch (value)
            {
                case HandType.Hight_card:
                    return HighCardHand.Val;

                case HandType.Pair:
                    return PairHand.Val;

                case HandType.Two_pair:
                    return TwoPairHand.Val;

                case HandType.Three_of_a_kind:
                    return ThreeOfAKindHand.Val;

                case HandType.Straight:
                    return StraightHand.Val;

                case HandType.Flush:
                    return FlushHand.Val;

                case HandType.Full_house:
                    return FullHouseHand.Val;

                case HandType.Four_of_a_kind:
                    return FourOfAKindHand.Val;

                case HandType.Straight_flush:
                    return StraightFlushHand.Val;

                default:
                    throw Utility.GetUnknownEnumValueException(value);
            }
        }
예제 #11
0
    private void CheckScore()
    {
        HandType hand = ScoreManager.Instance.CheckScore();

        _scoreText.gameObject.SetActive(true);
        _scoreText.text = $"{hand}: {(int)hand} points!";
    }
예제 #12
0
        internal static Sets GetSets(List <Card> cards, out HandType handType, out Rank rank)
        {
            Sets sets = GetSets(cards);

            // all sets must contain at least two sets (4+1, 3+2, 2+2+1, ...)
            if (sets.Count < 2)
            {
                throw new ArgumentException("GetSets requires at least five cards which should >=2 sets");
            }

            switch (sets[0].Size)
            {
            case 4:
                handType = HandType.FourOfAKind;
                break;

            case 3:
                handType = sets[1].Size == 2 ? HandType.FullHouse : HandType.ThreeOfAKind;
                break;

            case 2:
                handType = sets[1].Size == 2 ? HandType.TwoPair : HandType.Pair;
                break;

            default:
                handType = HandType.HighCard;
                break;
            }

            rank = sets[0].Rank;
            return(sets);
        }
예제 #13
0
        public Hand(
            ref Graphics GraphicsInterface,
            HandType TypeOfHand,
            ClockTime Time,
            ClockCentreCoordinates Coordinates,
            Int32 HandLength,
            Color HandColour,
            float HandThickness)
        {
            // Set specific hand properties.
            CoordinateStartX = Coordinates.X;
            CoordinateStartY = Coordinates.Y;
            Length           = HandLength;
            Colour           = HandColour;
            Thickness        = HandThickness;



            // What type of clock hand to create?
            switch (TypeOfHand)
            {
            case HandType.Milliseconds:
            {
                // 1 millisecond = 0.006 degrees.
                Angle = Time.Milliseconds * 0.006F;
                break;
            }


            case HandType.Seconds:
            {
                // 1 second = 6 degrees.
                Angle = Time.Seconds * 6;
                break;
            }

            case HandType.Minutes:
            {
                // 1 minute = 6 degrees.
                Angle = Time.Minutes * 6;
                break;
            }

            case HandType.Hours:
            {
                // 1 hour = 30 degrees + 0.5 degrees for each minute.
                Angle = Time.Hours * 30 + (Int32)(Time.Minutes * 0.5);
                break;
            }


            default:
                break;
            }



            GetEndCoordinates(Coordinates);
            DrawHand(ref GraphicsInterface);
        }
예제 #14
0
        public void HandTypesAreCorrectlyOrdered(
            [Values(HighCard, Pair, TwoPairs, ThreeOfAKind, Straight, Flush, FullHouse, FourOfAKind, StraightFlush)] HandType handType1,
            [Values(HighCard, Pair, TwoPairs, ThreeOfAKind, Straight, Flush, FullHouse, FourOfAKind, StraightFlush)] HandType handType2
            )
        {
            HandType[] handTypes = new HandType[] { handType1, handType2 };
            Hand[]     hands     = new Hand[] { new Hand(), new Hand() };

            for (int i = 0; i < 2; i++)
            {
                Card[] cards = exampleHands[handTypes[i]];
                foreach (Card card in cards)
                {
                    hands[i].AddCard(card);
                }
                Assert.AreEqual(hands[i].HandType, handTypes[i]);
            }

            int comp = hands[0].CompareTo(hands[1]);

            switch (handTypes[0].CompareTo(handTypes[1]))
            {
            case int c when c < 0:
                Assert.Less(comp, 0);
                break;

            case int c when c > 0:
                Assert.Greater(comp, 0);
                break;

            default:
                Assert.AreEqual(comp, 0);
                break;
            }
        }
예제 #15
0
 private void RaiseHandStateChanged(KinectBody body, HandType handType, HandState previousState)
 {
     if (this.HandStateChanged != null)
     {
         this.HandStateChanged(this, new KinectHandStateEventArgs(body, handType, previousState));
     }
 }
예제 #16
0
        public override float GetFingerValue(HandType hand, FingerName finger)
        {
            var value = 0f;
            //value = (hand == HandType.right) ? right.fingers[(int)finger]:left.fingers[(int)finger];
            SteamVR_Input_Sources source = (hand == HandType.right) ? SteamVR_Input_Sources.RightHand : SteamVR_Input_Sources.LeftHand;

            switch (finger)
            {
            case FingerName.Thumb:
                value = thumb.GetAxis(source);
                break;

            case FingerName.Index:
                value = index.GetAxis(source);
                break;

            case FingerName.Middle:
                value = middle.GetAxis(source);
                break;

            case FingerName.Ring:
                value = ring.GetAxis(source);
                break;

            case FingerName.Pinky:
                value = pinky.GetAxis(source);
                break;

            default:
                break;
            }
            return(value);
        }
예제 #17
0
    public void PlayHand(CardData[] cardDatas, HandType handType, int remainingCards, bool playingSet)
    {
        passTurnAmount       = 0;
        currentWinningPlayer = currentTurnPlayer;

        if (playingSet)                                                        //if this player played a set
        {
            if (previousPlayer != null && previousPlayer != currentTurnPlayer) //if previous 5 cards played by previous player is beaten by this player
            {
                previousPlayer.RpcSetEmotion(Character.Emotion.Sad);
            }
            else
            {
                currentTurnPlayer.RpcSetEmotion(Character.Emotion.Happy);
            }
        }

        ServerUpdatePlayedHand(cardDatas, handType);

        //if not game over
        if (remainingCards > 0)
        {
            previousPlayer = currentTurnPlayer;
            ServerNextPlayer();
        }
        else
        {
            //end game
            ServerNextState(StringEnum.GetStringValue(GameState.GameOver));
        }
    }
예제 #18
0
        void AssertHand(HandType expectedType, Rank expectedHighCard, string cards)
        {
            var target = new Hand(cards.Split(','));

            Assert.AreEqual(expectedType, target.Value, target.ToString());
            Assert.AreEqual(expectedHighCard, target.HighCard, target.ToString());
        }
예제 #19
0
 public void EnableHands(HandType type)
 {
     if (type == HandType.gadgets)
     {
         foreach (var gadget in gadgets)
         {
             gadget.gameObject.SetActive(true);
         }
         foreach (var con in interactionHands)
         {
             con.Detach();
             con.gameObject.SetActive(false);
         }
     }
     else if (type == HandType.interactionHands)
     {
         foreach (var gadget in gadgets)
         {
             gadget.Detach();
             gadget.gameObject.SetActive(false);
         }
         foreach (var con in interactionHands)
         {
             con.gameObject.SetActive(true);
         }
     }
 }
예제 #20
0
    void GrabObject()
    {
        //if grabbing object that is currently being touched by hand
        GameObject obj = objectBeingTouched;

        if (obj == null)
        {
            obj = handModel.closestObject;
        }

        if (obj != null && obj.GetComponent <IGrabbable>().CanBeGrabbed())
        {
            objectBeingHeld = obj;
            photonView.RPC("GrabObjectNet", RpcTarget.All, objectBeingHeld.GetPhotonView().ViewID);
            objectBeingHeld.GetComponent <IGrabbable>().GetGrabbed(this.gameObject);

            if (obj.CompareTag("PrimaryWeapon"))
            {
                handType = HandType.PrimaryHand;
            }
            else if (obj.CompareTag("SecondaryWeapon"))
            {
                handType = HandType.OffHand;
            }
        }
    }
예제 #21
0
 public PushGesture(HandType hand, Button b, TriggerType tt)
 {
     this.hand    = hand;
     this.button  = b;
     this.tt      = tt;
     this.trigger = false;
 }
예제 #22
0
        /// <summary>
        ///     the score is set to what is in the Total field, not the ActualScore field
        /// </summary>
        /// <param name="type"></param>
        /// <param name="handType"></param>
        /// <param name="scoredelta"></param>
        /// <param name="difficulty"></param>
        /// <param name="muggins"></param>
        /// <returns></returns>
        public ScoreCollection UpdateScore(PlayerType type, HandType handType, long scoredelta, GameDifficulty difficulty)
        {
            ScoreCollection score = new ScoreCollection();

            if (handType == HandType.Crib)
            {
                score.ScoreType = ScoreType.Crib;;
                score           = UpdateScoreForCrib(type, scoredelta);
            }
            else
            {
                Player p = GetPlayer(type);
                score.ScoreType = ScoreType.Hand;
                if (p != null)
                {
                    int s = p.Hand.ScoreHand(_deck.SharedCard, score, handType);


                    if (p.Type == PlayerType.Computer)
                    {
                        scoredelta = s;
                    }

                    if (s == scoredelta)
                    {
                        score.Accepted = true;
                        p.Score       += score.Total;
                    }
                }
            }
            return(score);
        }
        public IHand GetHand(HandType type, bool preferRight = true)
        {
            IJoint left  = _joints[JointType.HAND_LEFT];
            IJoint right = _joints[JointType.HAND_RIGHT];

            switch (type)
            {
            case HandType.Left:
                return(left.Valid ? left as IHand : null);

            case HandType.Right:
                return(left.Valid ? left as IHand : null);

            default:
                if (preferRight && right.Valid || !left.Valid && right.Valid)
                {
                    return(right as IHand);
                }

                if (left.Valid)
                {
                    return(left as IHand);
                }

                return(null);
            }
        }
예제 #24
0
    private void HandleGrip(XRBaseInteractable interactable, HandType hand, bool value)
    {
        if (hand != HandData.handType)
        {
            return;
        }

        if (value)
        {
            _graspableObject = interactable.gameObject;

            Debug.Log("GRIP " + _graspableObject);

            onGrasp?.Invoke(hand, true, _graspableObject);
        }
        else
        {
            Debug.Log("UNGRIP " + _graspableObject);

            if (_graspableObject == interactable.gameObject)
            {
                _graspableObject = null;
            }

            onGrasp?.Invoke(hand, false, _graspableObject);
            //Grasp(false);
        }
    }
예제 #25
0
 public HandContainer(HandType type, MInstruction instruction, bool isActive)
 {
     this.Type         = type;
     this.Instruction  = instruction;
     this.IsActive     = isActive;
     this.ConstraintID = "Carry:" + type + ":" + System.Guid.NewGuid().ToString();
 }
예제 #26
0
        public static string GetString(this HandType x)
        {
            switch (x)
            {
            case HandType.Pass:
                return("Pass");

            case HandType.Single:
                return("Single");

            case HandType.Pair:
                return("Pair");

            case HandType.ThreeOfAKind:
                return("Three of a kind");

            case HandType.Straight:
                return("Straight");

            case HandType.FullHouse:
                return("Full House");

            case HandType.FourOfAKind:
                return("Four of a Kind");

            case HandType.StraightFlush:
                return("Straight Flush");

            case HandType.RoyalFlush:
                return("Royal Flush");

            default:
                return("Hand of God");
            }
        }
예제 #27
0
        public void TestHand(HandType handType, Card[] hand)
        {
            var game   = new Game("test", 20, 20);
            var result = game.GetHandResult(hand);

            Assert.Equal(handType, result.HandType);
        }
예제 #28
0
파일: Hand.cs 프로젝트: shawnnapora/Pods
        public int CompareTo(object?obj)
        {
            if (!(obj is Hand other))
            {
                throw new ArgumentException("Comparison of hand with non-hand");
            }

            int handComparison = HandType.CompareTo(other.HandType);

            if (handComparison != 0)
            {
                return(handComparison);
            }

            int rankComparison = Rank.CompareTo(other.Rank);

            if (rankComparison != 0)
            {
                return(rankComparison);
            }

            if (_sets == null)
            {
                return(0);
            }

            // if _sets isn't null under these conditions, other._sets must also be non-null
            return(_sets.CompareTo(other._sets !));
        }
예제 #29
0
 public PokerHand(List <Card> pHand, HandType pType)
 {
     sortedHand = pHand;
     sortedHand.Sort();
     Hand          = sortedHand;
     PokerHandType = pType;
 }
예제 #30
0
        public HandType Hand;         //Varint Enum

        public override void Read(byte[] array)
        {
            if (McVarint.TryParse(ref array, out var hand))
            {
                Hand = (HandType)hand;
            }
        }
예제 #31
0
        private void checkWin(HandType x, HandType y)
        {
            if (radioButton1.Checked)
            {
                bet = 10;
            }
            if (radioButton2.Checked)
            {
                bet = 50;
            }
            if (radioButton3.Checked)
            {
                bal = bal - 5;
            }

            if (x > y)
            {
                handwinloss.Text = "Dealer Wins"; bal = bal - bet;
            }
            if (x < y)
            {
                handwinloss.Text = " Player Wins"; wins++; bal = bal + bet;
            }
            if (x == y)
            {
                handwinloss.Text = "Draw";
            }
            wallet.Text   = "Wallet: $" + bal;
            handswon.Text = "Hands won:" + wins.ToString();
            currBet.Text  = "Bet: $" + bet;
        }
예제 #32
0
 private void RaiseHandStateChanged(KinectBody body, HandType handType, HandState previousState)
 {
     if (this.HandStateChanged != null)
     {
         this.HandStateChanged(this, new KinectHandStateEventArgs(body, handType, previousState));
     }
 }
예제 #33
0
    public static IList <string> Evaluate(IDictionary <string, PokerHand> hands)
    {
        var      len         = Enum.GetValues(typeof(HandType)).Length;
        var      winners     = new List <string>();
        HandType winningType = HandType.HighCard;

        foreach (var name in hands.Keys)
        {
            for (var handType = HandType.RoyalFlush;
                 (int)handType < len; handType = handType + 1)
            {
                var hand = hands[name];
                if (hand.IsValid(handType))
                {
                    int compareHands = 0, compareCards = 0;
                    if (winners.Count == 0 ||
                        (compareHands = winningType.CompareTo(handType)) > 0 ||
                        compareHands == 0 &&
                        (compareCards = hand.CompareTo(hands[winners[0]])) >= 0)
                    {
                        if (compareHands > 0 || compareCards > 0)
                        {
                            winners.Clear();
                        }
                        winners.Add(name);
                        winningType = handType;
                    }
                    break;
                }
            }
        }
        return(winners);
    }
예제 #34
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="body">Kinect body</param>
        /// <param name="handType">Hand type</param>
        /// <param name="previousHandState">Previous hand state</param>
        public KinectHandStateEventArgs(KinectBody body, HandType handType, HandState previousHandState)
        {
            if (body == null)
                throw new ArgumentNullException("body");

            this.body = body;
            this.handType = handType;
            this.previousHandState = previousHandState;
        }
예제 #35
0
        public HandValue(HandType type, params int[] kickers)
        {
            if (kickers.Length != 5)
            {
                throw new InvalidOperationException("Must provide 5 kickers");
            }

            Type = type;
            Kickers = kickers;
        }
예제 #36
0
	private void InitInputDevice()
	{
		if(null != inputObject)
			input = inputObject.GetComponent<IPanInputDevice>();
		if(input == null)
			input = GetComponent<IPanInputDevice>();
		if(input == null)
			throw new UnityException("Can not Init InputDevice");
		handType = input.GetHandType();
	}
예제 #37
0
        internal static bool TryGetHandType(int value, out HandType ht)
        {
            if (HighCardHand.Val == value)
            {
                ht = HandType.Hight_card;
                return true;
            }
            else if (PairHand.Val == value)
            {
                ht = HandType.Pair;
                return true;
            }
            else if (TwoPairHand.Val == value)
            {
                ht = HandType.Two_pair;
                return true;
            }
            else if (ThreeOfAKindHand.Val == value)
            {
                ht = HandType.Three_of_a_kind;
                return true;
            }
            else if (StraightHand.Val == value)
            {
                ht = HandType.Straight;
                return true;
            }
            else if (FlushHand.Val == value)
            {
                ht = HandType.Flush;
                return true;
            }
            else if (FullHouseHand.Val == value)
            {
                ht = HandType.Full_house;
                return true;
            }
            else if (FourOfAKindHand.Val == value)
            {
                ht = HandType.Four_of_a_kind;
                return true;
            }
            else if (StraightFlushHand.Val == value)
            {
                ht = HandType.Straight_flush;
                return true;
            }

            ht = (HandType)0;
            return false;
        }
예제 #38
0
        /// <summary>
        /// Get the nearest templateClass for the refContour
        /// </summary>
        /// <param name="refContour">the contour wich class's is to be found</param>
        /// <param name="r">the area of the contour</param>
        /// <param name="classes">the list of the classes within to search</param>
        /// <returns>the nearest class or "not found"</returns>
        public static FoundTemplateDesc GetNearestClass(Contour<Point> refContour, Rectangle r, List<TemplateClass> classes, HandType handType)
        {
            contourClasses = classes;
            List<FoundTemplateDesc> foundedTemplates = new List<FoundTemplateDesc>();
            Template refTemp = new Template(refContour, r.Height * r.Width);

            foreach (TemplateClass tc in contourClasses)
            {
                if (tc.htype == handType)
                {
                    FoundTemplateDesc templateDesc = TemplateFinder.CompareTemplates(tc, refTemp);
                    if (templateDesc != null) foundedTemplates.Add(templateDesc);
                }

            }

            foundedTemplates = foundedTemplates.OrderBy(t => t.rate).ToList();

            return (foundedTemplates.Count == 0) ? null : foundedTemplates.First();
        }
예제 #39
0
        public int ToHandTypeRank(HandType handType)
        {
            int rank;

            switch (handType)
            {
                case HandType.NoPair:
                    rank = 0;
                    break;
                case HandType.OnePair:
                    rank = 1;
                    break;
                case HandType.TwoPair:
                    rank = 2;
                    break;
                case HandType.Trips:
                    rank = 3;
                    break;
                case HandType.Straight:
                    rank = 4;
                    break;
                case HandType.Flush:
                    rank = 5;
                    break;
                case HandType.FullHouse:
                    rank = 6;
                    break;
                case HandType.Quads:
                    rank = 7;
                    break;
                case HandType.StraightFlush:
                    rank = 8;
                    break;
                default:
                    rank = -1;
                    break;
            }

            return rank;
        }
        private static void FindStraightDrawIn4Cards(int[] cardRanks, ref HandType result)
        {
            result = HandType.None;

            Array.Sort(cardRanks);

            bool straightDrawAvailable = true;
            int oneCardGapsFound = 0;

            for (int i = 0; i < 3; ++i)
            {
                if (cardRanks[i] + 1 == cardRanks[i + 1])
                    continue;

                if (cardRanks[i] + 2 == cardRanks[i + 1])
                {
                    ++oneCardGapsFound;
                    continue;
                }

                straightDrawAvailable = false;
                break;
            }

            if (straightDrawAvailable && oneCardGapsFound == 1)
                result = HandType.Gatshot;

            if (straightDrawAvailable && oneCardGapsFound == 0)
            {
                if (cardRanks[0] == 0/*A as one*/ || cardRanks[3] == 13 /*A*/)
                    result = HandType.Gatshot;
                else
                    result = HandType.OESD;
            }
        }
예제 #41
0
 //constructor
 public HandsJoinedMid(HandType handType = HandType.NULL)
 {
     this.handType = handType;
 }
예제 #42
0
 //constructor
 public HandForward(HandType handType = HandType.NULL)
 {
     this.handType = handType;
 }
예제 #43
0
 //constructor
 public HandExtToBody(HandType handType = HandType.NULL)
 {
     this.handType = handType;
 }
예제 #44
0
        /// <summary>
        /// extract the the contour and the hull of one hand
        /// </summary>
        /// <param name="depthImage">the depth image to manipulate</param>
        private void ExtractContourAndHull(Image<Gray, byte> depthImage, HandType handType)
        {
            using (MemStorage storage = new MemStorage())
            {
                Contour<Point> contours = depthImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage);
                Contour<Point> biggestContour = null;

                Double Result1 = 0;
                Double Result2 = 0;
                while (contours != null)
                {
                    Result1 = contours.Area;
                    if (Result1 > Result2)
                    {
                        Result2 = Result1;
                        biggestContour = contours;
                    }
                    contours = contours.HNext;
                }

                if (biggestContour != null)
                {
                    this.currentContour = biggestContour.ApproxPoly(biggestContour.Perimeter * 0.0025, storage);

                    //smooth contour
                    Point[] pc = currentContour.ToArray();
                    Point p;
                    for (int i = 2; i < pc.Length - 2; i++)
                    {
                        //triangular smooth
                        int X = (pc[i - 2].X + 2 * pc[i - 1].X + 3 * pc[i].X + 2 * pc[i + 1].X + pc[i + 2].X) / 9;
                        int Y = (pc[i - 2].Y + 2 * pc[i - 1].Y + 3 * pc[i].Y + 2 * pc[i + 1].Y + pc[i + 2].Y) / 9;

                        p = new Point(X, Y);
                        currentContour.RemoveAt(i);
                        currentContour.Insert(i, p);
                    }

                    //if (handType == HandType.LEFT)
                    //{
                    //    hull = biggestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_COUNTER_CLOCKWISE);
                    //}
                    //else
                    //{
                    //    hull = biggestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                    //}

                    //box = biggestContour.GetMinAreaRect();
                    //CircleF boxCircle = new CircleF(box.center, 5f);
                    //PointF[] points = box.GetVertices();

                    //handRect = box.MinAreaRect();

                    //Point[] ps = new Point[points.Length];
                    //for (int i = 0; i < points.Length; i++)
                    //    ps[i] = new Point((int)points[i].X, (int)points[i].Y);

                    //filteredHull = new Seq<Point>(storage);
                    //for (int i = 0; i < hull.Total; i++)
                    //{
                    //    if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
                    //    {
                    //        filteredHull.Push(hull[i]);
                    //    }
                    //}
                }
            }
        }
예제 #45
0
        /// <summary>
        /// check if the hand is moving
        /// </summary>
        /// <param name="handType">the type of the hand</param>
        /// <returns>true if the hand is moving</returns>
        private bool CheckForMovement(HandType handType)
        {
            Queue<Point3D> q;
            Vector3 v;

            if (handType == HandType.LEFT)
            {
                q = this.leftHandQueue;
            }
            else
            {
                q = this.rightHandQueue;
            }

            if (q.Count > 1)
            {
                v = new Vector3(q.ToArray()[0], q.ToArray()[q.Count - 1]);
                if (v.Norm() * 100 > 1)
                {
                    return true;
                }
            }

            return false;
        }
예제 #46
0
 public WaveUpInt(HandType handType = HandType.NULL)
 {
     this.handType = handType;
 }
 //constructor
 public HandsInDiagonalRightUp(HandType handType = HandType.NULL)
 {
     this.handType = handType;
 }
예제 #48
0
 public IHand GetHand(HandType type, bool preferRight = true)
 {
     return null;
 }
예제 #49
0
 //constructor
 public WaveUpBothExt(HandType handType = HandType.NULL)
 {
     this.handType = handType;
 }
예제 #50
0
 //constructor
 public WaveMidAndUp(HandType handType = HandType.NULL)
 {
     this.handType = handType;
 }
예제 #51
0
 //constructor
 public WaveMidExt(HandType handType = HandType.NULL)
 {
     this.handType = handType;
 }
예제 #52
0
 // Use this for initialization
 public void Initialize(DeckController controller, HandType handType)
 {
     deckController = controller;
     handOwner = handType;
     deckView = deckController.gameObject.GetComponent<DeckView>();
     gameCards = new List<GameCard> ();
 }
예제 #53
0
        /// <summary>
        /// find hands based on the informations provided by the skeleton
        /// </summary>
        /// <param name="skeleton">the skeleton provided by Kinect</param>
        /// <param name="depthFrame">the depthFrame</param>
        /// <returns>a handgesture as a string</returns>
        public string FindHandGesture(HandType handtype)
        {
            //reset the values for hand detection
            this.currentContour = null;
            this.depthImage = new Image<Gray, byte>(this.depthFrameWidth, this.depthFrameHeight);

            this.handJoint = KinectHelper.Instance.GetHandJoint(handtype, skeleton);
            float zhand = handJoint.Position.Z;
            JointType jointtype = (handtype == HandType.LEFT) ? JointType.HandLeft : JointType.HandRight;

            if (min < zhand && zhand < max && CheckOrientation(handtype))
            {
                //set the ROI around the hand
                Joint hand = skeleton.Joints[jointtype].ScaleTo((int)(this.depthFrameWidth * 1), (int)(this.depthFrameHeight * 1));
                PointF center = new PointF(hand.Position.X, hand.Position.Y);
                this.depthImage = new Image<Gray, byte>(this.depthFrameWidth, this.depthFrameHeight);
                depthImage.Bytes = GetEverythingBetween(min, max, depthFrame);
                recSize = new Size(75 - (int)(50 * (zhand - MinDepthDistance)), 90 - (int)(35.7 * (zhand - MinDepthDistance)));

                if (CheckRectangleIsInside(depthImageBoth.Width, depthImageBoth.Height, recSize, center))
                {
                    depthImage.ROI = new Rectangle((int)center.X - recSize.Width / 2, (int)center.Y - recSize.Height / 2, recSize.Width, recSize.Height);

                    if (!CheckForMovement(handtype))
                    {
                        //get the contour
                        ExtractContourAndHull(depthImage.Copy(), handtype);

                        //find the name of the gesture if there is one
                        if (this.currentContour != null)
                        {
                            FoundTemplateDesc result = TemplateFinder.GetNearestClass(this.currentContour, depthImage.ROI, this.templates, handtype);
                            if (result != null) return result.name.ToString();
                        }

                    }

                    if ((isLeftHandTracked == false && handtype == HandType.LEFT) || (isRightHandTracked == false && handtype == HandType.RIGHT))
                    {
                        if (handtype == HandType.RIGHT)
                        {
                            isRightHandTracked = true;
                        }
                        else
                        {
                            isLeftHandTracked = true;
                        }
                    }
                }
            }
            else
            {
                if (handtype == HandType.LEFT)
                {
                    isLeftHandTracked = false;
                }
                else
                {
                    isRightHandTracked = false;
                }
            }
            return null;
        }
        public IHand GetHand(HandType type, bool preferRight = true)
        {
            IJoint left = _joints[JointType.HAND_LEFT];
            IJoint right = _joints[JointType.HAND_RIGHT];
            switch (type)
            {
                case HandType.Left:
                    return left.Valid ? left as IHand : null;

                case HandType.Right:
                        return left.Valid ? left as IHand : null;
                default:
                        if (preferRight && right.Valid || !left.Valid && right.Valid)
                        {
                            return right as IHand;
                        }

                        if (left.Valid)
                        {
                            return left as IHand;
                        }

                        return null;
            }
        }
예제 #55
0
        /// <summary>
        /// check if the orientations of the wrist and the hand are good for hand tracking
        /// </summary>
        /// <param name="handType">the type of the hand</param>
        /// <returns>true if the orientation os good enough to start hand detection</returns>
        private bool CheckOrientation(HandType handType)
        {
            Vector2 arm;
            Vector2 forArm;
            Vector2 wristToHand;

            double armAngle;
            double handAngle;

            if (handType == HandType.LEFT)
            {
                arm = new Vector2(skeleton.Joints[JointType.ShoulderLeft], this.skeleton.Joints[JointType.ElbowLeft], Axis.X);
                forArm = new Vector2(skeleton.Joints[JointType.ElbowLeft], skeleton.Joints[JointType.WristLeft], Axis.X);
                wristToHand = new Vector2(skeleton.Joints[JointType.WristLeft], skeleton.Joints[JointType.HandLeft], Axis.X);

                return (skeleton.Joints[JointType.HandLeft].Position.Y < skeleton.Joints[JointType.HipLeft].Position.Y) ? false : true;
            }
            else
            {
                arm = new Vector2(skeleton.Joints[JointType.ShoulderRight], skeleton.Joints[JointType.ElbowRight], Axis.X);
                forArm = new Vector2(skeleton.Joints[JointType.ElbowRight], skeleton.Joints[JointType.WristRight], Axis.X);
                wristToHand = new Vector2(skeleton.Joints[JointType.WristRight], skeleton.Joints[JointType.HandRight], Axis.X);

                return (skeleton.Joints[JointType.HandRight].Position.Y < skeleton.Joints[JointType.HipRight].Position.Y) ? false : true;
            }

            //armAngle = Vector2.Angle(arm, forArm) * 180 / Math.PI;
            //handAngle = Vector2.Angle(forArm, wristToHand) * 180 / Math.PI;

            //return ((armAngle > 55 && armAngle < 110) ) ? true : false;
            //return true;
        }
예제 #56
0
 /// <summary>
 /// return the left or right hand joint depending on the handtype
 /// </summary>
 /// <param name="handType">the hand desired</param>
 /// <param name="skeleton">the skeleton storing the hand</param>
 /// <returns>the hand joint</returns>
 public Joint GetHandJoint(HandType handType, Skeleton skeleton)
 {
     return (handType == HandType.LEFT) ? skeleton.Joints[JointType.HandLeft] : skeleton.Joints[JointType.HandRight];
 }
예제 #57
0
 //constructor
 public HandUp(HandType handType = HandType.NULL)
 {
     this.handType = handType;
 }
 public static string EncodeInteraction(int skeletonTrackingId, HandEventType handEventType, HandType handType, float x, float y, float pressExtent, bool isActive, bool isInteractive, bool isPressed, bool isTracked)
 {
     return string.Format(CultureInfo.InvariantCulture, "{0}|{1} {2} {3} {4} {5} {6} {7} {8} {9} {10}", InteractionFrameType, skeletonTrackingId, handEventType, handType, x, y, pressExtent, isActive, isInteractive, isPressed, isTracked);
 }
 /// <summary>
 /// return the hand queue owning the last hand positions
 /// </summary>
 /// <param name="handType">the handtype</param>
 /// <returns>the handQueue</returns>
 internal Queue<StandardHelper.Geomertry.Point3D> GetHandQueue(HandType handType)
 {
     if (handType == HandType.LEFT)
     {
         return this.leftHandQueue;
     }
     else
     {
         return this.rightHandQueue;
     }
 }
예제 #60
0
 private Hand CreateHand(Vector2 origin, HandType type)
 {
     var rectangle = new Rectangle ((int)origin.X, (int)origin.Y, (int)HAND_WIDTH, (int)HAND_HEIGHT);
     var hand = HandFactory.CreateUserHand (rectangle);
     hand.Type = type;
     return hand;
 }