Пример #1
0
 void Start()
 {
     //grab_offset = Vector3.zero;
     activeObject = null;
     CurrentBody  = null;
     //meshNum = 0;
 }
Пример #2
0
    private void RefreshBodyObject(Windows.Kinect.Body body)
    {
        Kinect.JointType jt = Kinect.JointType.Head;

        Kinect.Joint sourceJoint = body.Joints[jt];

        //set head/camera position on screen

        var headObjects = GameObject.FindGameObjectsWithTag("Head");
        var head        = headObjects[0];

        head.transform.localPosition = GetVector3FromJoint(sourceJoint);
    }
Пример #3
0
    /*** Update with every frame *****/
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

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

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

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                //Debug.Log("Null Body");
                continue;
              }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                main_camera.transform.parent = null;
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);

                if(IDToFirstBody == trackingId)
                {

                    IsFirstBody = true;
                }
            }
        }

        foreach(var body in data)
        {
            if (body == null)
            {
                //Debug.Log("Null Body");
                continue;
            }
            if(body.IsTracked)
            {

                if(IsFirstBody)// Start Detecting only one body
                {
                    Debug.Log("It Is First Body, ID: " + body.TrackingId);
                    //put rotation

                    CurrentBody = body;
                    IDToFirstBody = body.TrackingId;
                    IsFirstBody =false;

                    if(!_Bodies.ContainsKey(body.TrackingId))
                    {
                        _Bodies[body.TrackingId] = CreateBodyObject (body.TrackingId);
                    }

                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
                getHandCoordinates(CurrentBody, _Bodies[body.TrackingId]);

            }
        }
    }
Пример #4
0
 void Start()
 {
     //grab_offset = Vector3.zero;
     //activeObject = null;
     OnMove = false;
     CurrentBody = null;
     IsReleased = true;
     //ColorMap = new Color[]{Color.black, Color.white, Color.blue, Color.cyan, Color.gray, Color.green, Color.magenta, Color.red, Color.yellow};
     //Color Map for Furniture
     ColorMap = new Color[]{
         Color.black,
         new Color32 (96, 60, 61, 255),
         new Color32 (196, 175, 163, 255),
         new Color32 (228, 206, 160, 255),
         new Color32 (209, 164, 119, 255),
         new Color32 (200, 121, 87, 255),
         new Color32 (199, 196, 82, 255),
         new Color32 (196, 196, 196, 255),
         new Color32 (178, 191, 203, 255),
         new Color32 (115, 126, 136, 255),
         new Color32 (42, 70, 66, 255),
         new Color32 (196, 179, 199, 255),
         new Color32 (175, 138, 177, 255),
         new Color32 (224, 224, 224, 255),
         new Color32 (84, 168, 181, 255),
         new Color32 (90, 124, 155, 255)
     };
     colorIndex = 0;
     closest = null;
     //meshNum = 0;
 }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

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

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }
        if (frameCount == 0)
            firstBody = data [0];

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
        for (int i=0; i<data.Length; i++) {

        //foreach(var body in data)
        //{
            if (data[i] == null)
            {
                continue;
            }

            if(data[i].IsTracked)
            {
                //data[i] = NormalizedBody(data[i],firstBody);
                //RefreshBodyObject(data[i],firstBody);
                RefreshBodyObjectOrientation (data[i]);
                /*Debug.Log("ELBOW RIGHT-> "+
                          "W: "+data[i].JointOrientations [Kinect.JointType.ElbowRight].Orientation.W *Mathf.Rad2Deg +
                          "X: "+data[i].JointOrientations [Kinect.JointType.ElbowRight].Orientation.X *Mathf.Rad2Deg+
                          "Y: "+data[i].JointOrientations [Kinect.JointType.ElbowRight].Orientation.Y *Mathf.Rad2Deg+
                          "Z: "+data[i].JointOrientations [Kinect.JointType.ElbowRight].Orientation.Z *Mathf.Rad2Deg
                          );*/
            }
        }
        /*
        //record skeleton and store to memory first
        if (Recording) {
            //bodyFrames.Clear();
            Debug.Log("Recording...");
            MySkeleton skel = new MySkeleton();
            skel.JointId = new int[data[0].Joints.Count];
            skel.Position = new Vector3Serializer[data[0].Joints.Count];
            skel.Rotation = new QuaternionSerializer[data[0].Joints.Count];
            //GetVector3FromJoint(body.Joints[Kinect.JointType.SpineBase]);
            for(int i=0;i<data[0].Joints.Count;i++){
                //Vector3 a=GetVector3FromJoint(data[0].Joints[(Kinect.JointType)i]);
                skel.Position[i]= new Vector3Serializer(GetVector3FromJoint(data[0].Joints[(Kinect.JointType)i]));
            }
            bodyFrames.Add(skel);
        }
        if (Metadata) {
            //bodyFrames.Clear();
            MySkeleton skel = new MySkeleton ();
            Debug.Log ("recording metadata");
            skel.JointId = new int[data[0].Joints.Count];
            skel.Position = new Vector3Serializer[data[0].Joints.Count];
            skel.Rotation = new QuaternionSerializer[data[0].Joints.Count];
            for(int i=0;i<data[0].Joints.Count;i++){
                skel.Position[i] = new Vector3Serializer(GetVector3FromJoint(data[0].Joints[(Kinect.JointType)i]));
            }
            Debug.Log("asu"+skel.Position[0].getVector());
            bodyFrames.Add(skel);

        }
        //serialize (store recorded skeleton as binary)
        if (isSaving) {
            Debug.Log("saving...");
            isSaving = false;
            serialize(bodyFrames);
            bodyFrames.Clear();
        }
        if(isSavingMetadata){
            serializeLength(bodyFrames);
            Debug.Log("Skeletons count:"+boneLengths.Count);
            Debug.Log("saving metadata");
            isSavingMetadata = false;
            bodyFrames.Clear();
        }
        frameCount++;
        */
    }
Пример #6
0
    /*** Update with every frame *****/
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

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

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

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                //Debug.Log("Null Body");
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                main_camera.transform.parent = null;
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);


                if (IDToFirstBody == trackingId)
                {
                    IsFirstBody = true;
                }
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                //Debug.Log("Null Body");
                continue;
            }


            //main_camera.transform.position = new Vector3 (0, 0.92f, -4.26f);

            if (body.IsTracked)
            {
                if (IsFirstBody)               // Start Detecting only one body
                {
                    Debug.Log("It Is First Body, ID: " + body.TrackingId);
                    //put rotation

                    CurrentBody   = body;
                    IDToFirstBody = body.TrackingId;
                    IsFirstBody   = false;

                    if (!_Bodies.ContainsKey(body.TrackingId))
                    {
                        _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                        //change coordinates
                        //_Bodies[body.TrackingId] = changePerspective(_Bodies[body.TrackingId]);
                        //_Bodies[body.TrackingId].transform.localScale = new Vector3(-1,1,-1);
                        //StartGrabbing(CurrentBody);
                    }
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
                getHandCoordinates(CurrentBody);
            }
        }
    }
Пример #7
0
 void Start()
 {
     //grab_offset = Vector3.zero;
     activeObject = null;
     CurrentBody = null;
     //meshNum = 0;
 }