BodyComparer.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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[] joints = bsv.body.GetComponentsInChildren<Transform>();
  21. int index = 0;
  22. for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
  23. {
  24. // Skip these joints
  25. if (jt == Kinect.JointType.Head || jt == Kinect.JointType.ThumbLeft || jt == Kinect.JointType.ThumbRight
  26. || jt == Kinect.JointType.HandLeft || jt == Kinect.JointType.HandRight
  27. || jt == Kinect.JointType.HandTipLeft || jt == Kinect.JointType.HandTipRight)
  28. continue;
  29. JointsData jd = jointsDataDemo[i];
  30. Vector3 posJointDemo = new Vector3(jd.jointsPositionsX[(int)jt], jd.jointsPositionsY[(int)jt], jd.jointsPositionsZ[(int)jt]);
  31. float distance = (joints[index].position - posJointDemo).magnitude;
  32. if (distance > 0.2f)
  33. {
  34. joints[index].GetComponent<Renderer>().material.color = Color.red;
  35. }
  36. else
  37. {
  38. joints[index].GetComponent<Renderer>().material.color = Color.white;
  39. }
  40. index++;
  41. }
  42. float waitTime = 1;
  43. if (i < recordingTimesDemo.Count - 1)
  44. {
  45. waitTime = recordingTimesDemo[i + 1] - recordingTimesDemo[i];
  46. }
  47. yield return new WaitForSeconds(waitTime);
  48. }
  49. }
  50. // TODO: maybe at the end need to make all of them white?
  51. }