Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        transform.localPosition = Vector3.Lerp(transform.localPosition, FTWPClient.planePosition, speed);

        int tPort = int.Parse(targetPort);

        // Convert local position in the kinect space to a world space position.
        OSCMessage m;

        m = new OSCMessage("/ftwp/position");
        m.Append <float>(transform.position.x);
        m.Append <float>(transform.position.y);
        m.Append <float>(transform.position.z);
        client.SendTo(m, targetHost, tPort);
    }
Exemple #2
0
    public static void SendMessage(OSCMessage m, string host, int port)
    {
        if (Instance.LogOutgoing)
        {
            string args = "";
            for (int i = 0; i < m.Data.Count; i++)
            {
                args += (i > 0 ? ", " : "") + m.Data[i].ToString();
            }

            Debug.Log("[OSCMaster | " + DateTime.Now.ToLocalTime() + "] " + m.Address + " : " + args);
        }

        var tempClient = new OSCClient(System.Net.IPAddress.Loopback, port);

        tempClient.SendTo(m, host, port);
        tempClient.Close();
    }
Exemple #3
0
    void Update()
    {
        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)
            {
                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))
            {
                Debug.Log("Destroy Body");
                GameObject.Destroy(_Bodies[trackingId].gameObject);
                _Bodies.Remove(trackingId);

                OSCMessage m;
                m = new OSCMessage("/k2m/body/left");
                m.Append <int>((int)trackingId);
                client.SendTo(m, targetHost, targetPort);
            }
        }

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

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId]                  = GameObject.Instantiate(bodyPrefab).GetComponent <K2MBody>();
                    _Bodies[body.TrackingId].trackingId       = (int)body.TrackingId;
                    _Bodies[body.TrackingId].transform.parent = transform;

                    OSCMessage m;
                    m = new OSCMessage("/k2m/body/entered");
                    m.Append <int>((int)body.TrackingId);
                    client.SendTo(m, targetHost, targetPort);
                }

                _Bodies[body.TrackingId].updateBody(body);
            }
        }

        if (sendOSC)
        {
            float sendTime = 1f / sendRate;
            if (Time.time - lastSendTime > sendTime)
            {
                sendBodiesData();
                lastSendTime = Time.time;
            }
        }
    }