Showing
3 changed files
with
138 additions
and
1 deletions
New_TEXT_File.txt
0 → 100644
This diff could not be displayed because it is too large.
| ... | @@ -266,4 +266,77 @@ class CharacterSkeleton | ... | @@ -266,4 +266,77 @@ class CharacterSkeleton |
| 266 | } | 266 | } |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | + | ||
| 270 | + public void dasomset_trainer(float[] jt, int[] st, int offset, bool mirrored, bool move) | ||
| 271 | + { | ||
| 272 | + if (isSavedPosition == false && jointState[JointType_SpineBase] != TrackingState_NotTracked) | ||
| 273 | + { | ||
| 274 | + isSavedPosition = true; | ||
| 275 | + int j = offset * jointCount + JointType_SpineBase; | ||
| 276 | + savedPosition = new Vector3(jt[j * 3], jt[j * 3 + 1], jt[j * 3 + 2]); | ||
| 277 | + } | ||
| 278 | + for (int i = 0; i < jointCount; i++) | ||
| 279 | + { | ||
| 280 | + int j = offset * jointCount + i; | ||
| 281 | + if (mirrored) | ||
| 282 | + { | ||
| 283 | + joint[i] = new Vector3(-jt[j * 3], jt[j * 3 + 1], -jt[j * 3 + 2]); | ||
| 284 | + } | ||
| 285 | + else | ||
| 286 | + { | ||
| 287 | + joint[i] = new Vector3(jt[j * 3], jt[j * 3 + 1], savedPosition.z * 2 - jt[j * 3 + 2]); | ||
| 288 | + } | ||
| 289 | + jointState[i] = st[j]; | ||
| 290 | + } | ||
| 291 | + if (mirrored) | ||
| 292 | + { | ||
| 293 | + swapJoint(JointType_ShoulderLeft, JointType_ShoulderRight); | ||
| 294 | + swapJoint(JointType_ElbowLeft, JointType_ElbowRight); | ||
| 295 | + swapJoint(JointType_WristLeft, JointType_WristRight); | ||
| 296 | + swapJoint(JointType_HandLeft, JointType_HandRight); | ||
| 297 | + swapJoint(JointType_HipLeft, JointType_HipRight); | ||
| 298 | + swapJoint(JointType_KneeLeft, JointType_KneeRight); | ||
| 299 | + swapJoint(JointType_AnkleLeft, JointType_AnkleRight); | ||
| 300 | + swapJoint(JointType_FootLeft, JointType_FootRight); | ||
| 301 | + swapJoint(JointType_HandTipLeft, JointType_HandTipRight); | ||
| 302 | + swapJoint(JointType_ThumbLeft, JointType_ThumbRight); | ||
| 303 | + } | ||
| 304 | + for (int i = 0; i < targetBone.Length; i++) | ||
| 305 | + { | ||
| 306 | + int s = jointSegment[2 * i], e = jointSegment[2 * i + 1]; | ||
| 307 | + trackingSegment[targetBone[i]] = joint[e] - joint[s]; | ||
| 308 | + trackingState[targetBone[i]] = System.Math.Min(jointState[e], jointState[s]); | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + Vector3 waist = joint[JointType_HipRight] - joint[JointType_HipLeft]; | ||
| 312 | + waist = new Vector3(waist.x, 0, waist.z); | ||
| 313 | + Quaternion rot = Quaternion.FromToRotation(Vector3.right, waist); | ||
| 314 | + Quaternion rotInv = Quaternion.Inverse(rot); | ||
| 315 | + | ||
| 316 | + Vector3 shoulder = joint[JointType_ShoulderRight] - joint[JointType_ShoulderLeft]; | ||
| 317 | + shoulder = new Vector3(shoulder.x, 0, shoulder.z); | ||
| 318 | + Quaternion srot = Quaternion.FromToRotation(Vector3.right, shoulder); | ||
| 319 | + Quaternion srotInv = Quaternion.Inverse(srot); | ||
| 320 | + | ||
| 321 | + humanoid.transform.rotation = Quaternion.identity; | ||
| 322 | + foreach (HumanBodyBones bone in targetBone) | ||
| 323 | + { | ||
| 324 | + rigBone[bone].transform.rotation = rotInv * Quaternion.FromToRotation(Vector3.up, trackingSegment[bone]); | ||
| 325 | + } | ||
| 326 | + rigBone[HumanBodyBones.UpperChest].offset(srot); | ||
| 327 | + Quaternion bodyRot = rot; | ||
| 328 | + if (mirrored) | ||
| 329 | + { | ||
| 330 | + bodyRot = Quaternion.AngleAxis(180, Vector3.up) * bodyRot; | ||
| 331 | + } | ||
| 332 | + humanoid.transform.rotation = bodyRot; | ||
| 333 | + if (move == true) | ||
| 334 | + { | ||
| 335 | + Vector3 m = joint[JointType_SpineBase]; | ||
| 336 | + | ||
| 337 | + if (mirrored) m = new Vector3(-7, m.y-9, -2); | ||
| 338 | + humanoid.transform.position = m; | ||
| 339 | + } | ||
| 340 | + } | ||
| 341 | + | ||
| 269 | } | 342 | } | ... | ... |
| ... | @@ -6,6 +6,7 @@ using Kinect = Windows.Kinect; | ... | @@ -6,6 +6,7 @@ using Kinect = Windows.Kinect; |
| 6 | using System.Runtime.InteropServices; | 6 | using System.Runtime.InteropServices; |
| 7 | using System.IO; | 7 | using System.IO; |
| 8 | using System; | 8 | using System; |
| 9 | +using System.Threading; | ||
| 9 | 10 | ||
| 10 | public class Move : MonoBehaviour | 11 | public class Move : MonoBehaviour |
| 11 | { | 12 | { |
| ... | @@ -30,6 +31,15 @@ public class Move : MonoBehaviour | ... | @@ -30,6 +31,15 @@ public class Move : MonoBehaviour |
| 30 | public bool move = true; | 31 | public bool move = true; |
| 31 | private System.IntPtr kinect; | 32 | private System.IntPtr kinect; |
| 32 | 33 | ||
| 34 | + //lsy | ||
| 35 | + public string[] lines; | ||
| 36 | + public int trainer_i = -1; | ||
| 37 | + public int trainer_j = 0; | ||
| 38 | + public float[] trainer_data1; | ||
| 39 | + public int[] trainer_state; | ||
| 40 | + //lsy end | ||
| 41 | + | ||
| 42 | + | ||
| 33 | public Text IfSpineIsStraight; | 43 | public Text IfSpineIsStraight; |
| 34 | public Text HipBalance; | 44 | public Text HipBalance; |
| 35 | public Text AngleLeftKnee; | 45 | public Text AngleLeftKnee; |
| ... | @@ -41,11 +51,60 @@ public class Move : MonoBehaviour | ... | @@ -41,11 +51,60 @@ public class Move : MonoBehaviour |
| 41 | 51 | ||
| 42 | string hipbal, leftkneewarning, rightkneewarning, leftsidehighkick, rightsidehighkick; | 52 | string hipbal, leftkneewarning, rightkneewarning, leftsidehighkick, rightsidehighkick; |
| 43 | 53 | ||
| 54 | + //lsy | ||
| 55 | + void Trainer_Run() | ||
| 56 | + { | ||
| 57 | + if (trainer_j >= lines.Length - 3) | ||
| 58 | + { | ||
| 59 | + trainer_j = 0; | ||
| 60 | + return; | ||
| 61 | + } | ||
| 62 | + trainer_i = -1; | ||
| 63 | + trainer_data1 = new float[bodyCount * jointCount * 3]; | ||
| 64 | + trainer_state = new int[bodyCount * jointCount]; | ||
| 65 | + Debug.Log("초기화"); | ||
| 66 | + //Thread.Sleep(5000); | ||
| 67 | + for (int k = 0; k < 25; k++) | ||
| 68 | + { | ||
| 69 | + Debug.Log("trainer_j: " + trainer_j); | ||
| 70 | + Debug.Log("test1"); | ||
| 71 | + Debug.Log(lines[trainer_j]); | ||
| 72 | + | ||
| 73 | + trainer_i++; | ||
| 74 | + trainer_data1[trainer_i] = float.Parse(lines[trainer_j]); | ||
| 75 | + Debug.Log("test2" + trainer_i); | ||
| 76 | + trainer_i++; | ||
| 77 | + trainer_data1[trainer_i] = float.Parse(lines[trainer_j + 1]); | ||
| 78 | + Debug.Log("test3" + trainer_i); | ||
| 79 | + trainer_i++; | ||
| 80 | + trainer_data1[trainer_i] = float.Parse(lines[trainer_j + 2]); | ||
| 81 | + Debug.Log("test4" + trainer_i); | ||
| 82 | + if ((float.Parse(lines[trainer_j]) + float.Parse(lines[trainer_j + 1]) + float.Parse(lines[trainer_j + 2])) != 0) | ||
| 83 | + { | ||
| 84 | + trainer_state[trainer_i - 2] = 1; | ||
| 85 | + } | ||
| 86 | + Debug.Log("test4-1"); | ||
| 87 | + skeleton_Trainnner.dasomset_trainer(trainer_data1, trainer_state, 0, true, true); | ||
| 88 | + Debug.Log("test5"); | ||
| 89 | + Debug.Log(trainer_i); | ||
| 90 | + Debug.Log("메모라인 : " + trainer_j); | ||
| 91 | + trainer_j = trainer_j + 3; | ||
| 92 | + } | ||
| 93 | + Debug.Log("탈출!======================================================"); | ||
| 94 | + } | ||
| 95 | + //lsy end | ||
| 44 | 96 | ||
| 45 | void Start() | 97 | void Start() |
| 46 | { | 98 | { |
| 47 | skeleton_Trainnner = new CharacterSkeleton(Trainnner); | 99 | skeleton_Trainnner = new CharacterSkeleton(Trainnner); |
| 48 | skeleton_Trainnne = new CharacterSkeleton(Trainnne); | 100 | skeleton_Trainnne = new CharacterSkeleton(Trainnne); |
| 101 | + | ||
| 102 | + //lsy | ||
| 103 | + trainer_state = new int[bodyCount * jointCount]; | ||
| 104 | + trainer_data1 = new float[bodyCount * jointCount * 3]; | ||
| 105 | + lines = File.ReadAllLines(@"..\..\New_TEXT_File.txt"); | ||
| 106 | + Debug.Log("읽음"); | ||
| 107 | + //lsy end | ||
| 49 | } | 108 | } |
| 50 | 109 | ||
| 51 | private Dictionary<Kinect.JointType, Kinect.JointType> _BoneMap = new Dictionary<Kinect.JointType, Kinect.JointType>() | 110 | private Dictionary<Kinect.JointType, Kinect.JointType> _BoneMap = new Dictionary<Kinect.JointType, Kinect.JointType>() |
| ... | @@ -82,6 +141,11 @@ public class Move : MonoBehaviour | ... | @@ -82,6 +141,11 @@ public class Move : MonoBehaviour |
| 82 | 141 | ||
| 83 | void Update() | 142 | void Update() |
| 84 | { | 143 | { |
| 144 | + //lsy | ||
| 145 | + Trainer_Run(); | ||
| 146 | + //lsy end | ||
| 147 | + | ||
| 148 | + | ||
| 85 | IfSpineIsStraight.text = "허리를 곧게: Tracking"; | 149 | IfSpineIsStraight.text = "허리를 곧게: Tracking"; |
| 86 | HipBalance.text = "양쪽 힙 균형: Calculating"; | 150 | HipBalance.text = "양쪽 힙 균형: Calculating"; |
| 87 | AngleLeftKnee.text = "왼쪽 무릎 각도: Tracking"; | 151 | AngleLeftKnee.text = "왼쪽 무릎 각도: Tracking"; |
| ... | @@ -389,4 +453,4 @@ public class Move : MonoBehaviour | ... | @@ -389,4 +453,4 @@ public class Move : MonoBehaviour |
| 389 | return Angles; | 453 | return Angles; |
| 390 | } | 454 | } |
| 391 | } | 455 | } |
| 392 | -} | 456 | +} |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment