using UnityEngine;
using System.Collections;
using Windows.Kinect;

public class JointPosition : MonoBehaviour 
{
	public Transform kinectPosition;

    public Windows.Kinect.JointType _jointType;
    public GameObject _bodySourceManager;
    private BodySourceManager _bodyManager;

	// Use this for initialization
	void Start () 
    {
	
	}
	
	// Update is called once per frame
	void Update () 
    {
        if (_bodySourceManager == null)
        {
            return;
        }

        _bodyManager = _bodySourceManager.GetComponent<BodySourceManager>();
        if (_bodyManager == null)
        {
            return;
        }

        Body[] data = _bodyManager.GetData();
        if (data == null)
        {
            return;
        }

        // get the first tracked body...
        foreach (Body body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
               //this.gameObject.transform.position = new Vector3
               // this.gameObject.transform.localPosition =  body.Joints[_jointType].Position;
                var pos = body.Joints[_jointType].Position;

				Vector3 tempVector = new Vector3(-pos.X ,  pos.Y , pos.Z );
				transform.position = tempVector;
//				transform.position = kinectPosition.TransformPoint (tempVector);
                break;
            }
        }
	}
}
