Ejemplo n.º 1
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        //StreamWriter sw = new StreamWriter(new FileStream("a.txt", FileMode.Create));
        // sw.WriteLine("Hello");
        //sw.Close();
        // Debug.Log("바디트래킹됨=================" + num++);
        //NewBehaviourScript.test();
        // str += "바디트래킹됨=================" + num++ + "\n";



        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.Joint sourceJoint = body.Joints[jt];
            Kinect.Joint?targetJoint = null;

            ///////////////////////////
            Angles MyAngles   = new Angles();
            byte[] ReadAngles = MyAngles.GetVector(body);
            // ReadAngles[0].ToString();
            //Debug.Log("HipLeft " + ReadAngles[1].ToString());
            //Debug.Log("HipRight " + ReadAngles[2].ToString());
            //Debug.Log("KneeLeft " + ReadAngles[3].ToString());
            //Debug.Log("KneeRight " + ReadAngles[4].ToString());


            if (ReadAngles[1] - ReadAngles[2] <= 5)
            {
                hipbal = "양쪽 균형이 잡혀있습니다.";
            }
            else
            {
                hipbal = "양쪽 힘이 동일하지 않습니다. 균형을 잡으세요";
            }

            if (ReadAngles[5] > 90)
            {
                leftkneewarning = "왼쪽 무릎이 발끝을 넘어갔습니다.";
            }
            else
            {
                leftkneewarning = "";
            }
            if (ReadAngles[6] > 90)
            {
                rightkneewarning = "오른쪽 무릎이 발끝을 넘어갔습니다.";
            }
            else
            {
                rightkneewarning = "";
            }

            if (ReadAngles[7] < 45)
            {
                leftsidehighkick = "왼쪽 다리를 좀 더 높이 들어올리세요";
            }
            else
            {
                leftsidehighkick = "";
            }

            if (ReadAngles[8] < 45)
            {
                rightsidehighkick = "오른쪽 다리를 좀 더 높이 들어올리세요";
            }
            else
            {
                rightsidehighkick = "";
            }


            IfSpineIsStraight.text = "허리를 곧게: " + ReadAngles[0].ToString();
            HipBalance.text        = "양쪽 힙 균형: " + hipbal;
            AngleLeftKnee.text     = "왼쪽 무릎 각도: " + ReadAngles[3].ToString();
            AngleRightKnee.text    = "오른쪽 무릎 각도: " + ReadAngles[4].ToString();
            KneeToeLeft.text       = "올바르지 않은 자세: " + leftkneewarning;
            KneeToeRight.text      = "올바르지 않은 자세: " + rightkneewarning;
            LeftLegUp.text         = "왼쪽 다리 운동중: " + leftsidehighkick;
            RightLegUp.text        = "오른쪽 다리 운동중: " + rightsidehighkick;

            ///////////////////////////

            Debug.Log(body.Joints[Kinect.JointType.SpineBase].Position.X);
            if (body.Joints[jt].JointType.ToString() == "SpineBase")
            {
                Debug.Log(sourceJoint.Position.X);

                //str += sourceJoint.Position.X;
                //str += "\n";
                Debug.Log(sourceJoint.Position.Y);

                //str += sourceJoint.Position.Y;
                //str += "\n";
                Debug.Log(sourceJoint.Position.Z);
            }
            //str += body.Joints[jt].JointType;
            //str += "\n";


            //str += sourceJoint.Position.Z;
            //str += "\n";
            //Debug.Log("<<<<<<<<<<<<<<<<<");

            // str += "<<<<<<<<<<<<<<<<<<<\n";


            if (_BoneMap.ContainsKey(jt))
            {
                targetJoint = body.Joints[_BoneMap[jt]];
            }

            Transform jointObj = bodyObject.transform.Find(jt.ToString());
            jointObj.localPosition = GetVector3FromJoint(sourceJoint);

            LineRenderer lr = jointObj.GetComponent <LineRenderer>();
            if (targetJoint.HasValue)
            {
                lr.SetPosition(0, jointObj.localPosition);
                lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
                lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
            }
            else
            {
                lr.enabled = false;
            }
        }
    }
Ejemplo n.º 2
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        float[]  data1 = new float[bodyCount * jointCount * 3];
        int[]    state = new int[bodyCount * jointCount];
        int[]    id1   = new int[bodyCount];
        GCHandle gch   = GCHandle.Alloc(data1, GCHandleType.Pinned);
        GCHandle gch2  = GCHandle.Alloc(state, GCHandleType.Pinned);
        GCHandle gch3  = GCHandle.Alloc(id1, GCHandleType.Pinned);

        int i = -1;

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.Joint sourceJoint = body.Joints[jt];
            Kinect.Joint?targetJoint = null;



            if (_BoneMap.ContainsKey(jt))
            {
                targetJoint = body.Joints[_BoneMap[jt]];
            }
            Transform jointObj = bodyObject.transform.Find(jt.ToString());
            jointObj.localPosition = GetVector3FromJoint(sourceJoint);

            //Debug.Log(i);

            i++;
            data1[i] = sourceJoint.Position.X;
            i++;
            data1[i] = sourceJoint.Position.Y;
            i++;
            data1[i] = sourceJoint.Position.Z;
            if ((sourceJoint.Position.X + sourceJoint.Position.Y + sourceJoint.Position.Z) != 0)
            {
                state[i - 2] = 1;
            }
            skeleton_Trainnne.trainee_set(data1, state, 0, true, true, body.Joints[jt], jointObj);

            /*
             * LineRenderer lr = jointObj.GetComponent<LineRenderer>();
             * if (targetJoint.HasValue)
             * {
             *  //Debug.Log(jointObj.localPosition);
             *  //Debug.Log(GetVector3FromJoint(targetJoint.Value));
             *  lr.SetPosition(0, jointObj.localPosition);
             *  lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
             *  lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
             * }
             * else
             * {
             *  lr.enabled = false;
             * }
             */
        }

        ///////////////////////////
        Angles MyAngles = new Angles();

        byte[] ReadAngles = MyAngles.GetVector(body);

        if (exercise == "Squat")
        {
            //Squat_Title
            Squat_Title.SetActive(true);

            if (ReadAngles[1] - ReadAngles[2] <= 5)
            {
                HipBalance1.SetActive(false);
            }
            else
            {
                //"양쪽 힘이 동일하지 않습니다. \n균형을 잡으세요!";
                HipBalance1.SetActive(true);
            }

            if (ReadAngles[5] > 95 || ReadAngles[6] > 95)
            {
                //"엉덩이를 뒤로 더 빼세요!";
                PullHipBack2.SetActive(true);
            }
            else
            {
                PullHipBack2.SetActive(false);
            }

            if (ReadAngles[3] < 95 && ReadAngles[4] < 95)
            {
                Great5.SetActive(true);
            }
            else
            {
                great = "";
                Great5.SetActive(false);
            }

            ////////////운동 횟수 카운트//////////////////////
            if (ReadAngles[3] < 95 && ReadAngles[4] < 95 && workout &&
                workout_flag >= 95 && workout_flag2 >= 95)
            {
                Trainee_Count();
            }
            else
            {
                workout_flag  = ReadAngles[3];
                workout_flag2 = ReadAngles[4];
                workout       = true;
            }
        }
        else if (exercise == "SideHiKick")
        {
            //Title
            SideHighKick_Title.SetActive(true);

            if ((ReadAngles[7] < 45) && (ReadAngles[7] > 10) &&
                (sidehk_flag < ReadAngles[7]))
            {
                LegUp3.SetActive(true); //다리를 더 높이 들어올리세요
                Great5.SetActive(false);
            }
            else
            {
                LegUp3.SetActive(false);
                Great5.SetActive(false);

                //이전각도
                sidehk_flag = ReadAngles[7];
            }

            if (ReadAngles[7] >= 45)
            {
                Great5.SetActive(true); //Great
            }
            else
            {
                Great5.SetActive(false);
            }

            ////////운동 횟수 카운트////////////////////
            if (ReadAngles[7] > 45 && workout && workout_flag <= 45)
            {
                Trainee_Count();
            }
            else
            {
                workout_flag = ReadAngles[7];
                workout      = true;
            }
        }
        else if (exercise == "Lunge")
        {
            //Lunge_Title
            Lunge_Title.SetActive(true);

            if (!trainer_other_side)
            {
                if (ReadAngles[3] < 130 && ReadAngles[3] >= 91 && lunge_flag_l > ReadAngles[3])
                {
                    great = "";
                    Great5.SetActive(false);
                    KneeDown6.SetActive(true); //무릎을 더 굽혀주세요.
                }
                else if (ReadAngles[3] < 91)
                {
                    great = "GREAT!";
                    Great5.SetActive(true);
                    KneeDown6.SetActive(false);
                }
                else
                {
                    Great5.SetActive(false);
                    //KneeDown6.SetActive(false);
                }


                //////////////운동 횟수 카운트//////////////////
                //왼쪽
                if (ReadAngles[3] < 95 && workout && workout_flag >= 95)
                {
                    Trainee_Count();
                }
                else
                {
                    workout_flag = ReadAngles[3];
                    workout      = true;
                }
            }
            else
            {
                if (ReadAngles[4] < 130 && ReadAngles[4] >= 91 && lunge_flag_r > ReadAngles[4])
                {
                    great = "";
                    Great5.SetActive(false);
                    KneeDown6.SetActive(true); //무릎을 더 굽혀주세요.
                }
                else if (ReadAngles[4] < 91)
                {
                    great = "GREAT!";
                    Great5.SetActive(true);
                    KneeDown6.SetActive(false);
                }
                else
                {
                    Great5.SetActive(false);
                    //KneeDown6.SetActive(false);
                }


                //////////////운동 횟수 카운트//////////////////
                //오른쪽
                if (ReadAngles[4] < 95 && workout && workout_flag >= 95)
                {
                    Trainee_Count();
                }
                else
                {
                    workout_flag = ReadAngles[4];
                    workout      = true;
                }
            }


            lunge_flag_l = ReadAngles[3];
            lunge_flag_r = ReadAngles[4];
        }

        //공통된 사항
        if (ReadAngles[0] < 170 || ReadAngles[0] > 190)
        {
            spinestraight = "허리를 곧게 펴세요!";
            SpineStraight4.SetActive(true);
        }
        else
        {
            spinestraight = "";
            SpineStraight4.SetActive(false);
        }

        ///////////////////////////
    }