Exemple #1
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

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

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

        trackedIds.Clear();
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

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



        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);
                _bodyFilters.Remove(trackingId);
                JointTracked.Remove(trackingId);
            }
        }



        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId]      = CreateBodyObject(body.TrackingId);
                    _bodyFilters[body.TrackingId] = new KinectJointFilter();                                                                               //initialize filter
                    _bodyFilters[body.TrackingId].Init(filterSmoothing, filterCorrection, filterPrediction, filterJitterRadius, filterMaxDeviationRadius); //set filter values here
                }


                RefreshBodyObject(body, _bodyFilters[body.TrackingId], _Bodies[body.TrackingId], body.TrackingId);
            }
        }

        floor = _BodyManager.GetFloor();
        if (floor != null)
        {
            if (positionFloorBool)
            {
                kinectSpaceObject.transform.localPosition = new Vector3(kinectSpaceObject.transform.localPosition.x, floor.W + floorOffset, kinectSpaceObject.transform.localPosition.z);
            }

            if (!float.IsNaN(floor.Tilt))
            {
                kinectSpaceObject.transform.localEulerAngles = new Vector3(-floor.Tilt, kinectSpaceObject.transform.localEulerAngles.y, kinectSpaceObject.transform.localEulerAngles.z);
            }
        }

        DelegateBodies();
    }