void receiveMsg(IAsyncResult result) { // while (!endReceive) { //Debug.Log("RECEIVING"); #if UNITY_WSA_10_0 && !UNITY_EDITOR #else //var remoteEP = new IPEndPoint(IPAddress.Any, port); //udp.BeginReceive //var data = udp.Receive(ref remoteEP); // listen on port //Debug.Log("receive data from " + remoteEP.ToString()); IPEndPoint source = new IPEndPoint(0, 0); //byte[] message = udp.EndReceive(result, ref source); //Debug.Log("RECV " + Encoding.UTF8.GetString(message) + " from " + source); string message = Encoding.UTF8.GetString(udp.EndReceive(result, ref source)); //Debug.Log("RECV " + message + " from " + source); HoloPacket hp = JsonUtility.FromJson <HoloPacket>(message); switch (hp.type) { case HoloType.Transform: { switch (hp.id) { case HoloID.Hololens: lastHoloTransform = JsonUtility.FromJson <HoloTransform>(hp.data); //Debug.Log("Recv Holo " + lastHoloTransform.position.ToString() + " : " + lastHoloTransform.rotation.eulerAngles.ToString() + " from " + source); bHT = true; break; case HoloID.Projector1: case HoloID.Projector2: case HoloID.Projector3: case HoloID.Projector4: case HoloID.Projector5: case HoloID.Projector6: case HoloID.Projector7: case HoloID.Projector8: setlastProjTransform((int)hp.id, JsonUtility.FromJson <HoloTransform>(hp.data)); //Debug.Log("Recv " + hp.id .ToString() + getlastProjTransform((int)hp.id).position.ToString() + " : " + getlastProjTransform((int)hp.id).rotation.eulerAngles.ToString() + " from " + source); bPT = true; break; } break; } case HoloType.CameraParams: { lastHoloMatrices = JsonUtility.FromJson <HoloMatrices>(hp.data); bHM = true; break; } } //Debug.Log("HOLO " + ht.position.ToString() + " : " + ht.rotation.eulerAngles.ToString() + " from " + source); ++count_sps; // schedule the next receive operation once reading is done: udp.BeginReceive(new AsyncCallback(receiveMsg), udp); #endif } }
// Update is called once per frame void Update() { //Debug.Log("SENDING"); //while (true) //SendMessage("123456789123456789123456789123456789000", port); if (ReferenceRoot) { HoloTransform ht = new HoloTransform( Quaternion.Inverse(ReferenceRoot.transform.rotation) * (transform.position - ReferenceRoot.transform.position), Quaternion.Inverse(ReferenceRoot.transform.rotation) * transform.rotation); SendHoloPacket(port, HoloType.Transform, HoloID.Hololens, UnityEngine.JsonUtility.ToJson(ht)); } //else //{ // ht.rposition = new Vector3(1, 1, 1); // ht.rrotation = Quaternion.Euler(100, 100, 100); //} //if (ProjectorObj) //{ // HoloTransform ht = new HoloTransform( // Quaternion.Inverse(ReferenceRoot.transform.rotation) * (ProjectorObj.transform.position - ReferenceRoot.transform.position), // Quaternion.Inverse(ReferenceRoot.transform.rotation) * ProjectorObj.transform.rotation); // SendHoloPacket(port, HoloType.ProjectorTransform, UnityEngine.JsonUtility.ToJson(ht)); //} //else //{ // HoloTransform ht = new HoloTransform(new Vector3(1, 1, 1), Quaternion.Euler(100, 100, 100)); // SendHoloPacket(port, HoloType.ProjectorTransform, UnityEngine.JsonUtility.ToJson(ht)); // Debug.LogError("Proj obj not found"); //} foreach (GameObject p in ProjectorObjs) { HoloTransform ht = new HoloTransform( Quaternion.Inverse(ReferenceRoot.transform.rotation) * (p.transform.position - ReferenceRoot.transform.position), Quaternion.Inverse(ReferenceRoot.transform.rotation) * p.transform.rotation); //Debug.Log("Send Proj " + p.GetComponent<ProjectorCalibration>().ProjectorID.ToString() + (int)p.GetComponent<ProjectorCalibration>().ProjectorID); SendHoloPacket(port, HoloType.Transform, p.GetComponent <ProjectorCalibration>().ProjectorID, UnityEngine.JsonUtility.ToJson(ht)); } if (fixedParamsRate_count >= 60) { //retrieving camera prameters HoloMatrices hm = new HoloMatrices(); hm.holoProjMatrices[0] = Camera.main.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left); hm.holoProjMatrices[1] = Camera.main.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right); //hm.holoViewMatrices[0] = Camera.main.GetStereoViewMatrix(Camera.StereoscopicEye.Left); //hm.holoViewMatrices[1] = Camera.main.GetStereoViewMatrix(Camera.StereoscopicEye.Right); hm.convergence = Camera.main.stereoConvergence; hm.aspect = Camera.main.aspect; hm.fov = Camera.main.fieldOfView; hm.near = Camera.main.nearClipPlane; hm.far = Camera.main.farClipPlane; hm.isStereo = Camera.main.stereoEnabled; hm.vres = Camera.main.pixelHeight; hm.hres = Camera.main.pixelWidth; SendHoloPacket(port, HoloType.CameraParams, HoloID.Hololens, UnityEngine.JsonUtility.ToJson(hm)); fixedParamsRate_count = 0; } fixedParamsRate_count += fixedParamsRate; }