コード例 #1
0
ファイル: Unit_Page.xaml.cs プロジェクト: xenic719/kinect
 //返回按鍵,關閉聲音撥放計算
 private void back_Click(object sender, RoutedEventArgs e)
 {
     times  = 0;
     second = 0;
     unit   = 0;
     action = 0;
     res[0] = 0;
     res[1] = 0;
     finish = 0;
     VideoElement.Stop();
     GoodElement.Stop();
     LeftNegativeElement.Stop();
     LeftPositiveElement.Stop();
     RightNegativeElement.Stop();
     RightPositiveElement.Stop();
     BGMusicElement.Stop();
     this.NavigationService.Navigate(menu);
 }
コード例 #2
0
ファイル: Unit_Page.xaml.cs プロジェクト: xenic719/kinect
 private void timer_Tick()
 {
     if (sec > 0)
     {
         LeftNegativeElement.Stop();
         LeftPositiveElement.Stop();
         RightNegativeElement.Stop();
         RightPositiveElement.Stop();
         if (sec == 75)
         {
             GoodElement.Stop();
             GoodElement.Play();
             failSecond = 1;
         }
         sec--;
         A.Value = sec;  //timerText是介面上的一個TextBlock
     }
     else
     {
         timer.Stop();
     }
 }
コード例 #3
0
ファイル: Unit_Page.xaml.cs プロジェクト: xenic719/kinect
        //判斷動作播放指導聲音
        private void FailMessage(float [] res)
        {
            int TensNum = 0, DigitsNum;

            if (failSecond % 150 == 0)
            {
                LeftPositiveElement.Stop();
                RightPositiveElement.Stop();
                LeftNegativeElement.Stop();
                RightNegativeElement.Stop();
                GoodElement.Stop();
                OneElement.Stop();
                TwoElement.Stop();
                ThreeElement.Stop();
                FourElement.Stop();
                FiveElement.Stop();
                SixElement.Stop();
                SevenElement.Stop();
                EightElement.Stop();
                NineElement.Stop();
                TenElement.Stop();
                ElevenElement.Stop();
                TwelveElement.Stop();
                ThirteenElement.Stop();
                FourteenElement.Stop();
                FifteenElement.Stop();
                SixteenElement.Stop();
                SeventeenElement.Stop();
                EighteenElement.Stop();
                NineteenElement.Stop();
                CMoneElement.Stop();
                CMtwoElement.Stop();
                CMthreeElement.Stop();


                Console.WriteLine(res[1]);
                if (res[1] < 0)
                {
                    res[1] = -res[1];
                }
                res[1]          = Convert.ToInt32(res[1] * 83 / 0.6);
                TensNum         = Convert.ToInt32(res[1] / 10);
                DigitsNum       = Convert.ToInt32(res[1] % 10);
                totaldifferece += res[1];
                Console.WriteLine(TensNum + "/n" + DigitsNum);

                if (res[0] == 1)
                {
                    wrongnumber++;
                    LeftPositiveElement.Play();
                }
                else if (res[0] == 2)
                {
                    wrongnumber++;
                    LeftNegativeElement.Play();
                }
                else if (res[0] == 3)
                {
                    wrongnumber++;
                    RightPositiveElement.Play();
                }
                else if (res[0] == 4)
                {
                    wrongnumber++;
                    RightNegativeElement.Play();
                }

                //計算與標準動作差距
                if (TensNum == 1)
                {
                    TenElement.Play();
                }
                else if (TensNum == 2)
                {
                    TwoElement.Play();
                }
                else if (TensNum == 3)
                {
                    ThreeElement.Play();
                }
                else if (TensNum == 4)
                {
                    FourElement.Play();
                }
                else if (TensNum == 5)
                {
                    FiveElement.Play();
                }
                else if (TensNum == 6)
                {
                    SixElement.Play();
                }
                else if (TensNum == 7)
                {
                    SevenElement.Play();
                }
                else if (TensNum == 8)
                {
                    EightElement.Play();
                }
                else if (TensNum == 9)
                {
                    NineElement.Play();
                }


                if (DigitsNum == 1)
                {
                    ElevenElement.Play();
                }
                else if (DigitsNum == 2)
                {
                    TwelveElement.Play();
                }
                else if (DigitsNum == 3)
                {
                    ThirteenElement.Play();
                }
                else if (DigitsNum == 4)
                {
                    FourteenElement.Play();
                }
                else if (DigitsNum == 5)
                {
                    FifteenElement.Play();
                }
                else if (DigitsNum == 6)
                {
                    SixteenElement.Play();
                }
                else if (DigitsNum == 7)
                {
                    SeventeenElement.Play();
                }
                else if (DigitsNum == 8)
                {
                    EighteenElement.Play();
                }
                else if (DigitsNum == 9)
                {
                    NineteenElement.Play();
                }


                if (TensNum == 0)
                {
                    CMoneElement.Play();
                }
                else if (TensNum >= 1)
                {
                    if (DigitsNum == 0)
                    {
                        CMtwoElement.Play();
                    }
                    else
                    {
                        CMthreeElement.Play();
                    }
                }
            }
        }
コード例 #4
0
ファイル: Unit_Page.xaml.cs プロジェクト: xenic719/kinect
        void runtime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            bool receivedData = false;

            using (SkeletonFrame SFrame = e.OpenSkeletonFrame())
            {
                if (SFrame != null)
                {
                    Skeleton[] FrameSkeletons = new Skeleton[SFrame.SkeletonArrayLength];
                    SFrame.CopySkeletonDataTo(FrameSkeletons);
                    skeletons = new Skeleton[SFrame.SkeletonArrayLength];
                    SFrame.CopySkeletonDataTo(skeletons);
                    // The image processing took too long. More than 2 frames behind.
                    receivedData = true;
                }
            }

            if (receivedData)
            {
                Skeleton currentSkeleton = (from s in skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
                if (currentSkeleton != null)
                {
                    //取得骨架關節點 3D(X、Y、Z)座標值。
                    head           = currentSkeleton.Joints[JointType.Head];
                    rightHand      = currentSkeleton.Joints[JointType.HandRight];
                    leftHand       = currentSkeleton.Joints[JointType.HandLeft];
                    leftShoulder   = currentSkeleton.Joints[JointType.ShoulderLeft];
                    rightShoulder  = currentSkeleton.Joints[JointType.ShoulderRight];
                    centerShoulder = currentSkeleton.Joints[JointType.ShoulderCenter];
                    leftAnkle      = currentSkeleton.Joints[JointType.AnkleLeft];
                    rightAnkle     = currentSkeleton.Joints[JointType.AnkleRight];
                    leftElbow      = currentSkeleton.Joints[JointType.ElbowLeft];
                    rightElbow     = currentSkeleton.Joints[JointType.ElbowRight];
                    leftFoot       = currentSkeleton.Joints[JointType.FootLeft];
                    rightFoot      = currentSkeleton.Joints[JointType.FootRight];
                    leftHip        = currentSkeleton.Joints[JointType.HipLeft];
                    rightHip       = currentSkeleton.Joints[JointType.HipRight];
                    centerHip      = currentSkeleton.Joints[JointType.HipCenter];
                    leftKnee       = currentSkeleton.Joints[JointType.KneeLeft];
                    rightKnee      = currentSkeleton.Joints[JointType.KneeRight];
                    leftWrist      = currentSkeleton.Joints[JointType.WristLeft];
                    rightWrist     = currentSkeleton.Joints[JointType.WristRight];
                    spine          = currentSkeleton.Joints[JointType.Spine];

                    //設定紅點座標
                    SetEllipsePosition(ellipseHead, head, false);
                    SetEllipsePosition(ellipseLeftHand, leftHand, false);
                    SetEllipsePosition(ellipseRightHand, rightHand, false);
                    SetEllipsePosition(ellipseLeftFoot, leftFoot, false);
                    SetEllipsePosition(ellipseRightFoot, rightFoot, false);
                    SetEllipsePosition(ellipseLeftElbow, leftElbow, false);
                    SetEllipsePosition(ellipseRightElbow, rightElbow, false);
                    SetEllipsePosition(ellipseLeftAnkle, leftAnkle, false);
                    SetEllipsePosition(ellipseRightAnkle, rightAnkle, false);
                    SetEllipsePosition(ellipseLeftWrist, leftWrist, false);
                    SetEllipsePosition(ellipseRightWrist, rightWrist, false);
                    SetEllipsePosition(ellipseLeftShoulder, leftShoulder, false);
                    SetEllipsePosition(ellipseRightShoulder, rightShoulder, false);
                    SetEllipsePosition(ellipseLeftKnee, leftKnee, false);
                    SetEllipsePosition(ellipseRightKnee, rightKnee, false);
                    SetEllipsePosition(ellipseCenterShoulder, centerShoulder, false);
                    SetEllipsePosition(ellipseLeftHip, leftHip, false);
                    SetEllipsePosition(ellipseRightHip, rightHip, false);
                    SetEllipsePosition(ellipseCenterHip, centerHip, false);
                    SetEllipsePosition(ellipseSpine, spine, false);



                    actiontime++;

                    //設定頁面標籤內容
                    TimesLabel.Content    = times;
                    AllTimesLabel.Content = "5";

                    if (times == 0)
                    {
                        beforehour = Convert.ToInt32(DateTime.Now.ToString("hh"));
                        beforemin  = Convert.ToInt32(DateTime.Now.ToString("mm"));
                        beforesec  = Convert.ToInt32(DateTime.Now.ToString("ss"));
                    }

                    //當完成次數為5,改變動作與聲音
                    if (times == 5)
                    {
                        action++;
                        afterhour  = Convert.ToInt32(DateTime.Now.ToString("hh"));
                        aftermin   = Convert.ToInt32(DateTime.Now.ToString("mm"));
                        aftersec   = Convert.ToInt32(DateTime.Now.ToString("ss"));
                        actiontime = (afterhour - beforehour) * 60 * 60 + (aftermin - beforemin) * 60 + (aftersec - beforesec);

                        HttpGet();
                        actiontime     = 0;
                        wrongnumber    = 0;
                        differece      = 0;
                        totaldifferece = 0;

                        if (action <= 2)
                        {
                            changeVoice();
                        }
                        times = 0;
                    }



                    //判別單元
                    if (finish == 1)
                    {
                        if (AAction.handputdown(leftShoulder, leftHand, leftElbow, leftWrist, rightShoulder, rightHand, rightElbow, rightWrist))
                        {
                            finish = 0;
                        }
                    }
                    else if (finish == 2)
                    {
                        if (AAction.twoLeg(leftKnee, leftHip, rightKnee, rightHip))
                        {
                            finish = 0;
                        }
                    }
                    else if (finish == 0)
                    {
                        actionunit = unit;
                        actionname = action;
                        //判斷單元
                        if (unit == 1)
                        {
                            res        = UAC.Unit1_Check(action, leftShoulder, rightShoulder, leftElbow, rightElbow);
                            second     = unit_1.SecondSet();
                            failSecond = unit_1.failSecondSet();
                            loadingSet();
                            preTime = times;
                            times   = unit_1.StartUnit1(action, times, centerShoulder, leftShoulder, rightShoulder, leftHand, rightHand, leftElbow, rightElbow, leftWrist, rightWrist);
                        }
                        if (unit == 2)
                        {
                            res        = UAC.Unit2_Check(action, leftShoulder, rightShoulder, leftElbow, rightElbow);
                            second     = unit_2.SecondSet();
                            failSecond = unit_2.failSecondSet();
                            loadingSet();
                            preTime = times;
                            times   = unit_2.StartUnit2(action, times, centerShoulder, leftShoulder, rightShoulder, leftHand, rightHand, leftElbow, rightElbow, leftWrist, rightWrist, leftKnee, rightKnee);
                        }
                        if (unit == 3)
                        {
                            //a = UAC.Unit2_Check(action, leftShoulder, rightShoulder, leftElbow, rightElbow);
                            failSecond = unit_3.failSecondSet();
                            loadingSet();
                            preTime = times;
                            second  = unit_3.SecondSet();
                            times   = unit_3.StartUnit3(action, times, rightKnee, rightAnkle, rightHip, leftKnee, leftAnkle, leftHip);
                        }
                        if (unit == 4)
                        {
                            wrongnumber = unit_4.failSecondSet();
                            failSecond  = unit_4.failSecondSet();
                            loadingSet();
                            preTime = times;
                            second  = unit_4.SecondSet();
                            times   = unit_4.StartUnit4(action, times, rightKnee, rightAnkle, rightFoot, leftKnee, leftAnkle, leftFoot);
                        }

                        if (unit == 5)
                        {
                            second        = WU.SecondSet();
                            times         = WU.StartUnit5(action, times, centerShoulder, leftShoulder, rightShoulder, leftHand, rightHand, leftElbow, rightElbow, leftWrist, rightWrist, leftKnee, rightKnee, head);
                            label.Content = "第" + times + "次";
                        }
                    }

                    //回傳次數為1000時表示已完成所有動作,重置所有變數、聲音並回歸Menu頁面
                    if (times == 1000)
                    {
                        times  = 0;
                        unit   = 0;
                        action = 0;
                        VideoElement.Stop();
                        GoodElement.Stop();
                        LeftNegativeElement.Stop();
                        LeftPositiveElement.Stop();
                        RightNegativeElement.Stop();
                        RightPositiveElement.Stop();
                        MessageBox.Show("恭喜您完成此單元訓練!");
                        this.NavigationService.Navigate(menu);
                    }
                    ResetTime();
                    FailMessage(res);
                    label.Content     = "第" + times + "次";
                    actselect.Content = action;
                    if (unit != 0)
                    {
                        actioning.Content = sign.ReturnAct(unit, action);
                    }
                }
            }
        }