Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (bodyManager == null)
        {
            // print("bodyManager is null");
            return;
        }
        bodies = bodyManager.GetData();

        if (bodies == null)
        {
            // print("body is null");
            return;
        }

        foreach (var body in bodies)
        {
            if (body == null)
            {
                continue;
            }
            if (body.IsTracked)
            {
                // print("body is tracked");
                var cameraPos = body.Joints[trackedJoint].Position;
                var colorPos  = coordinateMapper.MapCameraPointToColorSpace(cameraPos);
                var worldPos  = FEMCalibrator.MapInducingPointToWorldSpace(colorPos);

                if (!Double.IsInfinity(worldPos.x) && !Double.IsInfinity(worldPos.y))
                {
                    gameObject.transform.position = worldPos;
                }

                if (this.trackedJoint == JointType.HandRight)
                {
                    print("colorPos: " + colorPos.X);
                    print("worldPos: " + worldPos);
                }
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (bodyManager == null)
        {
            Debug.Log("bodyManager is null");
            return;
        }

        bodies = bodyManager.GetData();

        if (bodies == null)
        {
            Debug.Log("bodies is null");
            return;
        }

        //bodies = Array.FindAll(bodies, body => (body.Joints[TrackedJoint].Position.Z < _limitZ && body.Joints[TrackedJoint].Position.X > _limitX));

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

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

            if (body.IsTracked)
            {
                print("body is Tracked!!");
                trackedIds.Add(body.TrackingId);
                trackedBodies.Add(body);
                if (_player1 == null)
                {
                    _player1 = body;
                    print("Player1: " + _player1.TrackingId);
                }

                if (_player1 != null)
                {
                    if (body.TrackingId != _player1.TrackingId)
                    {
                        _player2 = body;
                        print("Player2: " + _player2.TrackingId);
                    }

                    if (_player2 != null)
                    {
                        if (_player1.Joints [TrackedJoint].Position.X < _player2.Joints [TrackedJoint].Position.X)
                        {
                            _tempPlayer = _player1;
                            _player1    = _player2;
                            _player2    = _tempPlayer;
                        }
                    }
                }

                /*
                 * if (trackedBodies.Count > 1) {
                 *      if (body.TrackingId != _player1.TrackingId) {
                 *              _player2 = body;
                 *              print ("Player2: " + _player2.TrackingId);
                 *      }
                 *
                 *      if (_player2 != null) {
                 *              if (_player1.Joints [TrackedJoint].Position.X > _player2.Joints [TrackedJoint].Position.X) {
                 *                      _tempPlayer = _player1;
                 *                      _player1 = _player2;
                 *                      _player2 = _tempPlayer;
                 *              }
                 *      }
                 *
                 * }
                 */
            }
        }

        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);
                print("Destroy!");
            }
        }

        /*
         * foreach(var body in bodies)
         * {
         *      if (body == null)
         *      {
         *              continue;
         *      }
         *
         *      if(body.IsTracked)
         *      {
         *              if(!_Bodies.ContainsKey(body.TrackingId))
         *              {
         *                      _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
         *              }
         *
         *              RefreshBodyObject(body, _Bodies[body.TrackingId]);
         *      }
         * }
         *
         */


        if (_player1 != null)
        {
            Player1.SetActive(true);
            var cameraPos_r = _player1.Joints[TrackedJoint].Position;
            var colorPos_r  = coordinateMapper.MapCameraPointToColorSpace(cameraPos_r);
            var worldPos_r  = FEMCalibrator.MapInducingPointToWorldSpace(colorPos_r);

            if (!Double.IsInfinity(worldPos_r.x) && !Double.IsInfinity(worldPos_r.y))
            {
                Player1.transform.position = new Vector3(worldPos_r.x + 500, worldPos_r.y, 0);
            }
        }
        else
        {
            Player1.SetActive(false);
        }

        if (_player2 != null)
        {
            Player2.SetActive(true);
            var cameraPos_r = _player2.Joints[TrackedJoint].Position;
            var colorPos_r  = coordinateMapper.MapCameraPointToColorSpace(cameraPos_r);
            var worldPos_r  = FEMCalibrator.MapInducingPointToWorldSpace(colorPos_r);

            if (!Double.IsInfinity(worldPos_r.x) && !Double.IsInfinity(worldPos_r.y))
            {
                Player2.transform.position = new Vector3(worldPos_r.x - 100, worldPos_r.y, 0);
            }
        }
        else
        {
            Player2.SetActive(false);
        }

        //TrackingBodiesText.text = "Tracking Bodies: " + trackedBodies.Count;
    }