김다솜

파일입출력으로 Trainner 움직이기

This diff could not be displayed because it is too large.
......@@ -266,4 +266,77 @@ class CharacterSkeleton
}
}
public void dasomset_trainer(float[] jt, int[] st, int offset, bool mirrored, bool move)
{
if (isSavedPosition == false && jointState[JointType_SpineBase] != TrackingState_NotTracked)
{
isSavedPosition = true;
int j = offset * jointCount + JointType_SpineBase;
savedPosition = new Vector3(jt[j * 3], jt[j * 3 + 1], jt[j * 3 + 2]);
}
for (int i = 0; i < jointCount; i++)
{
int j = offset * jointCount + i;
if (mirrored)
{
joint[i] = new Vector3(-jt[j * 3], jt[j * 3 + 1], -jt[j * 3 + 2]);
}
else
{
joint[i] = new Vector3(jt[j * 3], jt[j * 3 + 1], savedPosition.z * 2 - jt[j * 3 + 2]);
}
jointState[i] = st[j];
}
if (mirrored)
{
swapJoint(JointType_ShoulderLeft, JointType_ShoulderRight);
swapJoint(JointType_ElbowLeft, JointType_ElbowRight);
swapJoint(JointType_WristLeft, JointType_WristRight);
swapJoint(JointType_HandLeft, JointType_HandRight);
swapJoint(JointType_HipLeft, JointType_HipRight);
swapJoint(JointType_KneeLeft, JointType_KneeRight);
swapJoint(JointType_AnkleLeft, JointType_AnkleRight);
swapJoint(JointType_FootLeft, JointType_FootRight);
swapJoint(JointType_HandTipLeft, JointType_HandTipRight);
swapJoint(JointType_ThumbLeft, JointType_ThumbRight);
}
for (int i = 0; i < targetBone.Length; i++)
{
int s = jointSegment[2 * i], e = jointSegment[2 * i + 1];
trackingSegment[targetBone[i]] = joint[e] - joint[s];
trackingState[targetBone[i]] = System.Math.Min(jointState[e], jointState[s]);
}
Vector3 waist = joint[JointType_HipRight] - joint[JointType_HipLeft];
waist = new Vector3(waist.x, 0, waist.z);
Quaternion rot = Quaternion.FromToRotation(Vector3.right, waist);
Quaternion rotInv = Quaternion.Inverse(rot);
Vector3 shoulder = joint[JointType_ShoulderRight] - joint[JointType_ShoulderLeft];
shoulder = new Vector3(shoulder.x, 0, shoulder.z);
Quaternion srot = Quaternion.FromToRotation(Vector3.right, shoulder);
Quaternion srotInv = Quaternion.Inverse(srot);
humanoid.transform.rotation = Quaternion.identity;
foreach (HumanBodyBones bone in targetBone)
{
rigBone[bone].transform.rotation = rotInv * Quaternion.FromToRotation(Vector3.up, trackingSegment[bone]);
}
rigBone[HumanBodyBones.UpperChest].offset(srot);
Quaternion bodyRot = rot;
if (mirrored)
{
bodyRot = Quaternion.AngleAxis(180, Vector3.up) * bodyRot;
}
humanoid.transform.rotation = bodyRot;
if (move == true)
{
Vector3 m = joint[JointType_SpineBase];
if (mirrored) m = new Vector3(-7, m.y-9, -2);
humanoid.transform.position = m;
}
}
}
......
......@@ -6,6 +6,7 @@ using Kinect = Windows.Kinect;
using System.Runtime.InteropServices;
using System.IO;
using System;
using System.Threading;
public class Move : MonoBehaviour
{
......@@ -30,6 +31,15 @@ public class Move : MonoBehaviour
public bool move = true;
private System.IntPtr kinect;
//lsy
public string[] lines;
public int trainer_i = -1;
public int trainer_j = 0;
public float[] trainer_data1;
public int[] trainer_state;
//lsy end
public Text IfSpineIsStraight;
public Text HipBalance;
public Text AngleLeftKnee;
......@@ -41,11 +51,60 @@ public class Move : MonoBehaviour
string hipbal, leftkneewarning, rightkneewarning, leftsidehighkick, rightsidehighkick;
//lsy
void Trainer_Run()
{
if (trainer_j >= lines.Length - 3)
{
trainer_j = 0;
return;
}
trainer_i = -1;
trainer_data1 = new float[bodyCount * jointCount * 3];
trainer_state = new int[bodyCount * jointCount];
Debug.Log("초기화");
//Thread.Sleep(5000);
for (int k = 0; k < 25; k++)
{
Debug.Log("trainer_j: " + trainer_j);
Debug.Log("test1");
Debug.Log(lines[trainer_j]);
trainer_i++;
trainer_data1[trainer_i] = float.Parse(lines[trainer_j]);
Debug.Log("test2" + trainer_i);
trainer_i++;
trainer_data1[trainer_i] = float.Parse(lines[trainer_j + 1]);
Debug.Log("test3" + trainer_i);
trainer_i++;
trainer_data1[trainer_i] = float.Parse(lines[trainer_j + 2]);
Debug.Log("test4" + trainer_i);
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;
}
Debug.Log("test4-1");
skeleton_Trainnner.dasomset_trainer(trainer_data1, trainer_state, 0, true, true);
Debug.Log("test5");
Debug.Log(trainer_i);
Debug.Log("메모라인 : " + trainer_j);
trainer_j = trainer_j + 3;
}
Debug.Log("탈출!======================================================");
}
//lsy end
void Start()
{
skeleton_Trainnner = new CharacterSkeleton(Trainnner);
skeleton_Trainnne = new CharacterSkeleton(Trainnne);
//lsy
trainer_state = new int[bodyCount * jointCount];
trainer_data1 = new float[bodyCount * jointCount * 3];
lines = File.ReadAllLines(@"..\..\New_TEXT_File.txt");
Debug.Log("읽음");
//lsy end
}
private Dictionary<Kinect.JointType, Kinect.JointType> _BoneMap = new Dictionary<Kinect.JointType, Kinect.JointType>()
......@@ -82,6 +141,11 @@ public class Move : MonoBehaviour
void Update()
{
//lsy
Trainer_Run();
//lsy end
IfSpineIsStraight.text = "허리를 곧게: Tracking";
HipBalance.text = "양쪽 힙 균형: Calculating";
AngleLeftKnee.text = "왼쪽 무릎 각도: Tracking";
......@@ -389,4 +453,4 @@ public class Move : MonoBehaviour
return Angles;
}
}
}
}
\ No newline at end of file
......