JointPosition.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. using System.Collections;
  3. using Windows.Kinect;
  4. public class JointPosition : MonoBehaviour
  5. {
  6. public Transform kinectPosition;
  7. public Windows.Kinect.JointType _jointType;
  8. public GameObject _bodySourceManager;
  9. private BodySourceManager _bodyManager;
  10. // Use this for initialization
  11. void Start ()
  12. {
  13. }
  14. // Update is called once per frame
  15. void Update ()
  16. {
  17. if (_bodySourceManager == null)
  18. {
  19. return;
  20. }
  21. _bodyManager = _bodySourceManager.GetComponent<BodySourceManager>();
  22. if (_bodyManager == null)
  23. {
  24. return;
  25. }
  26. Body[] data = _bodyManager.GetData();
  27. if (data == null)
  28. {
  29. return;
  30. }
  31. // get the first tracked body...
  32. foreach (Body body in data)
  33. {
  34. if (body == null)
  35. {
  36. continue;
  37. }
  38. if (body.IsTracked)
  39. {
  40. //this.gameObject.transform.position = new Vector3
  41. // this.gameObject.transform.localPosition = body.Joints[_jointType].Position;
  42. var pos = body.Joints[_jointType].Position;
  43. Vector3 tempVector = new Vector3(-pos.X , pos.Y , pos.Z );
  44. transform.position = tempVector;
  45. // transform.position = kinectPosition.TransformPoint (tempVector);
  46. break;
  47. }
  48. }
  49. }
  50. }