//lsy void Trainer_Run() { if (!trainer_check)//운동 끝났을 때 { trainer_timer += Time.deltaTime; if (trainer_timer > 3) { //Debug.Log("3초 됨 운동 끝!!!!!"); //결과씬이나 다른씬으로 trainer_check_outside = false; Squat_Title.SetActive(false); SideHighKick_Title.SetActive(false); Lunge_Title.SetActive(false); SceneManager.LoadScene("Result"); // Result씬으로 이동 } return; } //Thread.Sleep(50); if (trainer_j >= lines.Length - 3) { if (trainer_count < 20 && exercise == "Squat") { trainer_count++; //Debug.Log("카운트 : " + trainer_count); trainercnt = trainer_count + "/20"; Trainner_count.text = trainercnt; } if (trainer_count < 10 && exercise == "SideHiKick") { trainer_count++; // Debug.Log("카운트 : " + trainer_count); trainercnt = trainer_count + "/10"; Trainner_count.text = trainercnt; } if (trainer_count < 10 && exercise == "Lunge") { trainer_count++; // Debug.Log("카운트 : " + trainer_count); trainercnt = trainer_count + "/10"; Trainner_count.text = trainercnt; } if (trainer_count >= 20 && exercise == "Squat") { trainer_check = false;//스쿼트일때 운동 끝나는 시점!!!!! } if (trainer_count >= 10 && exercise == "SideHiKick") { if (!trainer_other_side) { if (trainer_timer > 3) { Right_Start.SetActive(false); trainer_count = 0; lines = lines_right; trainer_other_side = true; trainer_timer = 0; } else { Right_Start.SetActive(true); trainer_timer += Time.deltaTime; return; } } else { trainer_check = false;//사이드하이킥일때 운동 끝나는 시점!!!!! } } if (trainer_count >= 10 && exercise == "Lunge") { if (!trainer_other_side) { if (trainer_timer > 3) { Lunge_Right_Instruction.SetActive(false); trainer_speed = 10; trainer_count = 0; lines = lines_right; trainer_other_side = true; trainer_timer = 0; } else { Lunge_Right_Instruction.SetActive(true); trainer_timer += Time.deltaTime; return; } } else { trainer_check = false;//런지일때 운동 끝나는 시점!!!!! } } trainer_j = 0; return; } trainer_i = -1; trainer_data1 = new float[bodyCount * jointCount * 3]; trainer_state = new int[bodyCount * jointCount]; for (int k = 0; k < 25; k++) { trainer_i++; trainer_data1[trainer_i] = float.Parse(lines[trainer_j]); trainer_i++; trainer_data1[trainer_i] = float.Parse(lines[trainer_j + 1]); trainer_i++; trainer_data1[trainer_i] = float.Parse(lines[trainer_j + 2]); if ((float.Parse(lines[trainer_j]) + float.Parse(lines[trainer_j + 1]) + float.Parse(lines[trainer_j + 2])) != 0) { trainer_state[trainer_i - 2] = 1; } skeleton_Trainnner.trainer_set(trainer_data1, trainer_state, 0, true, true); trainer_j = trainer_j + 3; } if (speed < trainer_speed) { trainer_j -= 75; speed++; } else { // Debug.Log("다음"); // Debug.Log(trainer_j); speed = 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); } /////////////////////////// }