コード例 #1
0
    public void processAvatarMessage(AvatarMessage av)
    {
        foreach (string s in av.calibrations)
        {
            string[] chunks = s.Split(';');
            string   id     = chunks[0];
            float    px     = float.Parse(chunks[1]);
            float    py     = float.Parse(chunks[2]);
            float    pz     = float.Parse(chunks[3]);
            float    rx     = float.Parse(chunks[4]);
            float    ry     = float.Parse(chunks[5]);
            float    rz     = float.Parse(chunks[6]);
            float    rw     = float.Parse(chunks[7]);

            Vector3    pi = new Vector3(px, py, pz);
            Quaternion ri = new Quaternion(rx, ry, rz, rw);

            GameObject cloudobj = new GameObject(id);
            cloudobj.transform.localPosition = Vector3.zero;
            cloudobj.transform.localRotation = Quaternion.identity;
            cloudobj.transform.localScale    = new Vector3(-1, 1, 1);
            cloudobj.AddComponent <PointCloudSimple>();
            PointCloudSimple cloud = cloudobj.GetComponent <PointCloudSimple>();
            _clouds.Add(id, cloud);
            _cloudGameObjects.Add(id, cloudobj);


            //
            GameObject origin = GameObject.Find("RemoteOrigin");
            cloudobj.transform.parent        = origin.transform;
            cloudobj.transform.localPosition = pi;
            cloudobj.transform.localRotation = ri;
        }
    }
コード例 #2
0
    public void processAvatarMessage(AvatarMessage av)
    {
        Sensors sensors = GameObject.Find("Main").GetComponent <Sensors>();

        foreach (string s in av.calibrations)
        {
            string[] chunks = s.Split(';');
            string   id     = chunks[0];
            float    px     = float.Parse(chunks[1]);
            float    py     = float.Parse(chunks[2]);
            float    pz     = float.Parse(chunks[3]);
            float    rx     = float.Parse(chunks[4]);
            float    ry     = float.Parse(chunks[5]);
            float    rz     = float.Parse(chunks[6]);
            float    rw     = float.Parse(chunks[7]);

            GameObject cloudobj = new GameObject(id);
            cloudobj.transform.localPosition = new Vector3(px, py, pz);
            cloudobj.transform.localRotation = new Quaternion(rx, ry, rz, rw);
            cloudobj.transform.localScale    = new Vector3(-1, 1, 1);
            cloudobj.AddComponent <PointCloudSimple>();


            PointCloudSimple cloud = cloudobj.GetComponent <PointCloudSimple>();
            _clouds.Add(id, cloud);
            _cloudGameObjects.Add(id, cloudobj);
            sensors.addSensor(id, new Vector3(px, py, pz), new Quaternion(rx, ry, rz, rw));
        }
        Camera.main.GetComponent <MouseOrbitImproved>().target = _cloudGameObjects.First().Value.transform;
    }
コード例 #3
0
    // PNG version

    /*void Update() {
     *  Texture2D texture2D = this.currentTexture;
     *  int x, y;
     *  for (int i = 0; i < texture2D.width; ++i)
     *  {
     *      for (int j = 0; j < texture2D.height; ++j)
     *      {
     *          x = this.FaceCenterX - (texture2D.width / 2) + i;
     *          y = this.FaceTexture.height - this.FaceCenterY + (texture2D.height / 2) - j;
     *          if (x > 0 && x < this.FaceTexture.width && y > 0 && y < this.FaceTexture.height)
     *          {
     *              //FaceTexture.SetPixel(x, y, message.colors[(i * message.width) + j].Color);
     *              FaceTexture.SetPixel(x, y, texture2D.GetPixel(i, j));
     *              //Debug.Log("(i * message.width) + j = " + ((i * message.width) + j));
     *          }
     *      }
     *  }
     *  this.FaceTexture.Apply();
     * }*/

    private void HandleAvatarMessage(NetworkMessage message)
    {
        AvatarMessage avatarMessage = message.ReadMessage <AvatarMessage>();

        if (avatarMessage != null)
        {
            this.OnAvatarMessage(avatarMessage);
            Debug.Log("AvatarMessage received");
        }
    }
コード例 #4
0
ファイル: Tracker.cs プロジェクト: rafaelkuffner/Hologramers
    public void broadCastCloudMessage(int mode)
    {
        UdpClient udp     = new UdpClient();
        string    message = AvatarMessage.createRequestMessage(mode, _listenPort);

        byte[]     data           = Encoding.UTF8.GetBytes(message);
        IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Broadcast, _trackerPort);

        Debug.Log("Sent request to port" + _trackerPort + " with content " + message);
        udp.Send(data, data.Length, remoteEndPoint);
    }
コード例 #5
0
    void Update()
    {
        while (_stringsToParse.Count > 0)
        {
            try
            {
                byte[] toProcess = _stringsToParse.First();
                if (toProcess != null)
                {
                    // TMA: THe first char distinguishes between a BodyMessage and a CloudMessage
                    if (Convert.ToChar(toProcess[0]) == 'C')
                    {
                        string   stringToParse = Encoding.ASCII.GetString(toProcess);
                        string[] splitmsg      = stringToParse.Split(MessageSeparators.L0);
                        message.set(splitmsg[1], toProcess, splitmsg[0].Length);
                        gameObject.GetComponent <Tracker>().setNewCloud(message);
                    }
                    else if (Convert.ToChar(toProcess[0]) == 'A')
                    {
                        Debug.Log("Got Calibration Message! ");
                        string        stringToParse = Encoding.ASCII.GetString(toProcess);
                        string[]      splitmsg      = stringToParse.Split(MessageSeparators.L0);
                        AvatarMessage av            = new AvatarMessage(splitmsg[1], toProcess);
                        gameObject.GetComponent <Tracker>().processAvatarMessage(av);
                    }
                    else if (Convert.ToChar(toProcess[0]) == 'S')
                    {
                        Debug.Log("Got Surfaces Message! ");
                        string stringToParse = Encoding.ASCII.GetString(toProcess);

                        string[] s = stringToParse.Split(MessageSeparators.L0);
                        if (s.Length == 2)
                        {
                            GameObject.Find("Main").GetComponent <Main>().receiveSurface(s[1]);
                        }
                        else
                        {
                            Debug.LogError("NO SURFACE");
                        }
                    }
                }
                _stringsToParse.RemoveAt(0);
            }
            catch (Exception exc) { _stringsToParse.RemoveAt(0); }
        }
    }
コード例 #6
0
    public override void OnClientConnect(NetworkConnection conn)
    {
        Debug.Log("[MultiAvatarNetworkManager:OnClientConnect]");
        AvatarMessage msg = new AvatarMessage();

        for (int i = 0; i < spawnPrefabs.Count; i++)
        {
            if (spawnPrefabs[i].Equals(playerPrefab))
            {
                msg.avatarIndex = i;
#if UNITY_WSA_10_0
                msg.avatarName = HololensConfig.instance.id;
#endif
                break;
            }
        }

        ClientScene.AddPlayer(conn, 0, msg);
    }
コード例 #7
0
    public void init()
    {
        _properties = GameObject.Find("Main").GetComponent <Properties>();

        GetComponent <UdpListener>().init();

        _clouds           = new Dictionary <string, PointCloudSimple> ();
        _cloudGameObjects = new Dictionary <string, GameObject>();

        UdpClient udp     = new UdpClient();
        string    message = AvatarMessage.createRequestMessage(1, int.Parse(_properties.localSetupInfo.ravatarListenPort)); // FIRST REQUEST

        byte[]     data           = Encoding.UTF8.GetBytes(message);
        IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Broadcast, int.Parse(_properties.remoteSetupInfo.trackerListenPort));

        Debug.Log("Sent request to port " + _properties.remoteSetupInfo.trackerListenPort + " with content " + message);
        udp.Send(data, data.Length, remoteEndPoint);
        started = true;
    }
コード例 #8
0
    public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader)
    {
        AvatarMessage message        = extraMessageReader.ReadMessage <AvatarMessage>();
        int           selectedAvatar = message.avatarIndex;

        Debug.Log("[MultiAvatarNetworkManager:OnServerAddPlayer] server add with message " + selectedAvatar);
        GameObject player = Instantiate(spawnPrefabs[selectedAvatar]);
        //if this is a hololens, lets add it's extra data for the Docent UI
        HololensAvatarLogic hlPlayer = player.GetComponent <HololensAvatarLogic>();

        if (hlPlayer != null)
        {
            string fullAddress = conn.address;
            //filter out the ipv4 address section
            System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(fullAddress, @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");
            hlPlayer.IP = match.Value;
            hlPlayer.ID = message.avatarName;
        }
        NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
    }
コード例 #9
0
    void Update()
    {
        if (_startConfig)
        {
            //udpRestart();
            _startConfig = false;
        }

        if (_start)
        {
            while (_stringsToParse.Count > 0)
            {
                try
                {
                    byte[] toProcess = _stringsToParse.First();
                    if (toProcess != null)
                    {
                        // TMA: THe first char distinguishes between a BodyMessage and a CloudMessage
                        if (Convert.ToChar(toProcess[0]) == 'C')
                        {
                            string   stringToParse = Encoding.ASCII.GetString(toProcess);
                            string[] splitmsg      = stringToParse.Split(MessageSeparators.L0);
                            message.set(splitmsg[1], toProcess, splitmsg[0].Length);
                            gameObject.GetComponent <Tracker>().setNewCloud(message);
                        }
                        else if (Convert.ToChar(toProcess[0]) == 'A')
                        {
                            Debug.Log("Got Calibration Message! ");
                            string        stringToParse = Encoding.ASCII.GetString(toProcess);
                            string[]      splitmsg      = stringToParse.Split(MessageSeparators.L0);
                            AvatarMessage av            = new AvatarMessage(splitmsg[1], toProcess);
                            gameObject.GetComponent <Tracker>().processAvatarMessage(av);
                        }
                    }
                    _stringsToParse.RemoveAt(0);
                }
                catch (Exception exc) { _stringsToParse.RemoveAt(0); }
            }
        }
    }
コード例 #10
0
    void Awake()
    {
        Debug.Log("Hello Tracker");
        _clouds           = new Dictionary <string, PointCloudSimple> ();
        _cloudGameObjects = new Dictionary <string, GameObject>();
        _loadConfig();



        UdpClient udp     = new UdpClient();
        string    message = AvatarMessage.createRequestMessage(1, TrackerProperties.Instance.listenPort);

        byte[]     data           = Encoding.UTF8.GetBytes(message);
        IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Broadcast, TrackerProperties.Instance.trackerPort);

        Debug.Log("Sent request to port" + TrackerProperties.Instance.trackerPort + " with content " + message);
        udp.Send(data, data.Length, remoteEndPoint);

        message = SurfaceMessage.createRequestMessage(TrackerProperties.Instance.listenPort);
        data    = Encoding.UTF8.GetBytes(message);
        Debug.Log("Sent request to port" + TrackerProperties.Instance.trackerPort + " with content " + message);
        udp.Send(data, data.Length, remoteEndPoint);
    }
コード例 #11
0
    private void OnAvatarMessage(AvatarMessage msg)
    {
        this.Body.position = msg.Position.V3 / 10;

        for (var i = 0; i < msg.Bones.Length; ++i)
        {
            switch ((KinectWrapper.NuiSkeletonPositionIndex)msg.Bones[i])
            {
            case KinectWrapper.NuiSkeletonPositionIndex.HipCenter:
                this.HipCenter.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.HipCenter.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.Spine:
                this.Spine.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.Spine.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.ShoulderCenter:
                this.ShoulderCenter.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.ShoulderCenter.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.Head:
                this.Head.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.Head.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.ShoulderLeft:
                this.ShoulderLeft.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.ShoulderLeft.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.ElbowLeft:
                this.ElbowLeft.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.ElbowLeft.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.WristLeft:
                this.WristLeft.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.WristLeft.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.HandLeft:
                this.HandLeft.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.HandLeft.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.ShoulderRight:
                this.ShoulderRight.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.ShoulderRight.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.ElbowRight:
                this.ElbowRight.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.ElbowRight.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.WristRight:
                this.WristRight.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.WristRight.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.HandRight:
                this.HandRight.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.HandRight.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.HipLeft:
                this.HipLeft.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.HipLeft.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.KneeLeft:
                this.KneeLeft.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.KneeLeft.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.AnkleLeft:
                this.AnkleLeft.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.AnkleLeft.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.FootLeft:
                this.FootLeft.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.FootLeft.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.HipRight:
                this.HipRight.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.HipRight.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.KneeRight:
                this.KneeRight.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.KneeRight.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.AnkleRight:
                this.AnkleRight.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.AnkleRight.rotation = msg.Rotations [i].Quaternion;
                break;

            case KinectWrapper.NuiSkeletonPositionIndex.FootRight:
                this.FootRight.position = this.transform.TransformPoint(msg.Positions [i].V3);
                this.FootRight.rotation = msg.Rotations [i].Quaternion;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
    }