/// <summary>
        ///     Get the id for trackbody tab of a track body object
        ///     if is unknow create a new object
        /// </summary>
        /// <param name="trackingId">trackingId give by kinect sensor </param>
        /// <returns>index id in the tab of body </returns>
        private static int GetBodyId(ulong trackingId)
        {
            var firstId = 5;

            for (var i = 0; i < TrackBody.Length; i++)
            {
                if (TrackBody[i] == null)
                {
                    // save the lower id null
                    if (firstId > i)
                    {
                        firstId = i;
                    }
                }
                else
                {
                    if (TrackBody[i].Id == trackingId)
                    {
                        //if the trackid is know return the index id
                        return(i);
                    }
                }
            }
            //if i dont found id i create a new object and return this index in tab
            TrackBody[firstId] = new TrackBody(trackingId, firstId);
            return(firstId);
        }
Exemple #2
0
        /// <summary>
        ///     Display some feedback and update text on screen
        /// </summary>
        /// <param name="trackBody">Trackbody object </param>
        /// <param name="activeBody">number of index body for edit the right label </param>
        private void DisplayFeedback(TrackBody trackBody, int activeBody)
        {
            //change counter
            trackBody.Counter++;
            var blockCount = (TextBlock)FindName("CountP" + activeBody);

            if (blockCount != null)
            {
                blockCount.Text = "Count: " + trackBody.Counter;
            }

            //display audio feedback
            HitSound.Play();

            //display visual feedback
            //move point on screen
            var point = trackBody.GoalJoint1.Scale(_sensor.CoordinateMapper);

            Hit.Margin = new Thickness(point.X - 50, point.Y - 40, 1920 - point.X - 50, 1080 - point.Y - 40);
            //start animation
            var sb = FindResource("HitAnimation") as Storyboard;

            if (sb == null)
            {
                return;
            }
            Storyboard.SetTarget(sb, Hit);
            sb.Begin();
        }
Exemple #3
0
        /// <summary>
        ///     Check is hand is stay more than 3 seconds hover the StartButton
        /// </summary>
        /// <param name="trackedBody">Trackbody object </param>
        /// <returns>True if is stay more than 3 seconds else False </returns>
        private bool CheckIsStay(TrackBody trackedBody)
        {
            if (GameActive)
            {
                return(false);
            }

            var ishover = false;

            if (_gameMode == 3)
            {
                if (_isReadable)
                {
                    ishover = IsHover(ActiveHandGm3 == JointType.HandLeft ? trackedBody.HandLeft : trackedBody.HandRight);
                }
            }
            else
            {
                ishover = IsHover(trackedBody.HandLeft, trackedBody.HandRight);
            }

            if (ishover)
            {
                if (trackedBody.HandHover) // hand have been already hover at previous check
                {
                    if (!trackedBody.TimerStay.TimerActive)
                    {
                        return(true);
                    }
                    var lowerPlayer = GetLowerTimer();
                    // update le timer
                    if (lowerPlayer != null)
                    {
                        TextStartButton.Text = lowerPlayer.TimerStay.Timers.ToString();
                    }
                    return(false);
                }
                trackedBody.HandHover = true;
                trackedBody.TimerStay.ActiveTimer(0, 3, 0);
                //TextStartButton.Text = timers.ToString();
                return(false);
            }
            trackedBody.HandHover = false;
            TextStartButton.Text  = _startButtonText;
            if (trackedBody.TimerStay.TimerActive)
            {
                trackedBody.TimerStay.StopTimer();
            }
            return(false);
        }
        /// <summary>
        ///     Get the player with the higer score of the game
        /// </summary>
        /// <returns>Best player with TrackBody Object </returns>
        private static TrackBody GetBestplayer()
        {
            var       bestScore  = 0;
            TrackBody bestPlayer = null;

            foreach (var body in TrackBody)
            {
                if (body == null)
                {
                    continue;
                }
                body.Gm3NextPoint = 0;
                if (body.Counter <= bestScore)
                {
                    continue;
                }
                bestScore  = body.Counter;
                bestPlayer = body;
            }
            return(bestPlayer);
        }
        /// <summary>
        ///     get player with lower timer
        /// </summary>
        /// <returns>Best player with TrackBody Object</returns>
        private static TrackBody GetLowerTimer()
        {
            var       lowerTimer  = 4;
            TrackBody lowerPlayer = null;

            foreach (var body in TrackBody)
            {
                if (body == null)
                {
                    continue;
                }
                if (!body.TimerStay.TimerActive)
                {
                    continue;
                }
                if (body.TimerStay.Timers >= lowerTimer)
                {
                    continue;
                }
                lowerTimer  = body.Counter;
                lowerPlayer = body;
            }
            return(lowerPlayer);
        }