BodyComparer.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Kinect = Windows.Kinect;
  5. // TODO: Implementing color feedback
  6. public class BodyComparer : MonoBehaviour
  7. {
  8. public BodySourceView bsv;
  9. private List<JointsData> jointsDataDemo = new List<JointsData>();
  10. private List<float> recordingTimesDemo = new List<float>();
  11. public void SetDataDemo(List<JointsData> jointsDataDemo, List<float> recordingTimesDemo)
  12. {
  13. this.jointsDataDemo = jointsDataDemo;
  14. this.recordingTimesDemo = recordingTimesDemo;
  15. }
  16. public IEnumerator StartCompare()
  17. {
  18. for (int i = 0; i < jointsDataDemo.Count; i++)
  19. {
  20. Transform body = bsv.body.transform;
  21. for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
  22. {
  23. // Skip these joints
  24. if (jt == Kinect.JointType.Head || jt == Kinect.JointType.ThumbLeft || jt == Kinect.JointType.ThumbRight
  25. || jt == Kinect.JointType.HandLeft || jt == Kinect.JointType.HandRight
  26. || jt == Kinect.JointType.HandTipLeft || jt == Kinect.JointType.HandTipRight)
  27. continue;
  28. JointsData jd = jointsDataDemo[i];
  29. Vector3 posJointDemo = new Vector3(jd.jointsPositionsX[(int)jt], jd.jointsPositionsY[(int)jt], jd.jointsPositionsZ[(int)jt]);
  30. //float distance = (joints[index].position - posJointDemo).magnitude;
  31. float distance = (body.GetChild((int)jt).position - posJointDemo).magnitude;
  32. if (distance > 0.15f)
  33. {
  34. //joints[index].GetComponent<Renderer>().material.color = Color.red;
  35. body.GetChild((int)jt).GetComponent<Renderer>().material.color = Color.red;
  36. }
  37. else
  38. {
  39. //joints[index].GetComponent<Renderer>().material.color = Color.white;
  40. body.GetChild((int)jt).GetComponent<Renderer>().material.color = Color.white;
  41. }
  42. }
  43. float waitTime = 0.01f;
  44. if (i < recordingTimesDemo.Count - 1)
  45. {
  46. waitTime = recordingTimesDemo[i + 1] - recordingTimesDemo[i];
  47. }
  48. yield return new WaitForSeconds(waitTime);
  49. }
  50. // TODO: make all of them white
  51. }
  52. }