public void setlastProjTransform(int proj, HoloTransform t) { lock (_lock) { _lastProjTransform[proj] = t; } }
HoloTransform LoadProjectorTransform(HoloID proj) { HoloTransform projTr = null; if (System.IO.File.Exists(GetSaveFileName(ProjectorID))) { projTr = UnityEngine.JsonUtility.FromJson <HoloTransform>(System.IO.File.ReadAllText(GetSaveFileName(ProjectorID))); //Debug.Log("Load " + GetSaveFileName(ProjectorID)); } else { //Debug.Log("Load unable to find " + GetSaveFileName(ProjectorID)); } return(projTr); }
void SaveProjectorTransform() { //PlayerPrefs.SetFloat(ProjectorID.ToString() + "PosX", CalibrationObject.transform.localPosition.x); //PlayerPrefs.SetFloat(ProjectorID.ToString() + "PosY", CalibrationObject.transform.localPosition.y); //PlayerPrefs.SetFloat(ProjectorID.ToString() + "PosZ", CalibrationObject.transform.localPosition.z); //PlayerPrefs.SetFloat(ProjectorID.ToString() + "RotX", CalibrationObject.transform.localRotation.x); //PlayerPrefs.SetFloat(ProjectorID.ToString() + "RotY", CalibrationObject.transform.localRotation.y); //PlayerPrefs.SetFloat(ProjectorID.ToString() + "RotZ", CalibrationObject.transform.localRotation.z); //PlayerPrefs.SetFloat(ProjectorID.ToString() + "RotW", CalibrationObject.transform.localRotation.w); //PlayerPrefs.Save(); //Debug.Log("Save " + CalibrationObject.transform.localPosition + " - " + CalibrationObject.transform.localRotation); HoloTransform projTr = new HoloTransform(CalibrationObject.transform.localPosition, CalibrationObject.transform.localRotation); System.IO.File.WriteAllText(GetSaveFileName(ProjectorID), UnityEngine.JsonUtility.ToJson(projTr)); }
void MoveProjector(string dest, string data) { HoloTransform ht = JsonUtility.FromJson <HoloTransform>(data); //Debug.Log("Move " + ProjectorID.ToString() + ": " + ht.position.ToString() + " - " + ht.rotation.ToString()); // return; if (!calibratingFine) { //Debug.Log("Start Fine Calib " + Time.time); OnStartFineProjectorCalibration(); lastFineCalibTime = Time.time; StartCoroutine(StopFineCalibration()); } lastFineCalibTime = Time.time; CalibrationObject.transform.position += CalibrationObject.transform.rotation * ht.position; CalibrationObject.transform.Rotate(ht.rotation.eulerAngles); //this.transform.rotation = ht.rotation; //Debug.Log("X: " + ht.rotation.eulerAngles.x); }
void MoveReference(string dest, string data) { HoloTransform ht = JsonUtility.FromJson <HoloTransform>(data); //Debug.Log("Move Reference " + ht.position.ToString() + " - " + ht.rotation.ToString()); // return; if (!calibratingFine) { //Debug.Log("Start Fine Calib " + Time.time); destroyAnchor(); calibratingFine = true; lastFineCalibTime = Time.time; StartCoroutine(StopFineCalibration()); } lastFineCalibTime = Time.time; this.transform.position += this.transform.rotation * ht.position; this.transform.Rotate(ht.rotation.eulerAngles); //this.transform.rotation = ht.rotation; //Debug.Log("X: " + ht.rotation.eulerAngles.x); }
void Start() { if (!HoloHelper.isHololens()) { return; } //WorldAnchorStore.GetAsync(AnchorStoreReady); // Add an AudioSource component and set up some defaults audioSource = gameObject.AddComponent <AudioSource>(); audioSource.playOnAwake = false; //audioSource.spatialize = true; //audioSource.spatialBlend = 1.0f; //audioSource.dopplerLevel = 0.0f; //audioSource.rolloffMode = AudioRolloffMode.Custom; // Load the Sphere sounds from the Resources folder startClip = Resources.Load <AudioClip>("calibrationStart"); stopClip = Resources.Load <AudioClip>("calibrationStop"); //CalibrationObject = transform.FindChild("ProjectorObj").gameObject; //CalibrationObject = transform.FindChild("ProjectorObj").gameObject.transform.FindChild("ProjectorMesh").gameObject; CalibrationObject = this.gameObject; CalibrationMeshObj = transform.FindChild("ProjectorMesh").gameObject; SceneObject = GameObject.Find("SceneObj").gameObject; #if UNITY_WSA_10_0 && !UNITY_EDITOR // Set up a GestureRecognizer to detect Select gestures. recognizer = new GestureRecognizer(); recognizer.TappedEvent += (source, tapCount, ray) => { this.OnSelect(); }; //recognizer.StartCapturingGestures(); #endif HoloTransform savedTransform = LoadProjectorTransform(ProjectorID); if (savedTransform != null) { Debug.Log("Save found for " + ProjectorID.ToString()); CalibrationObject.transform.localPosition = savedTransform.position; CalibrationObject.transform.localRotation = savedTransform.rotation; } //if (PlayerPrefs.HasKey(ProjectorID.ToString() + "PosX") && PlayerPrefs.HasKey(ProjectorID.ToString() + "PosY") && PlayerPrefs.HasKey(ProjectorID.ToString() + "PosZ")) { // Vector3 pos = new Vector3(PlayerPrefs.GetFloat(ProjectorID.ToString() + "PosX"), PlayerPrefs.GetFloat(ProjectorID.ToString() + "PosY"), PlayerPrefs.GetFloat(ProjectorID.ToString() + "PosZ")); // Debug.Log("ProjPos " + pos); // CalibrationObject.transform.localPosition = pos; //} //if (PlayerPrefs.HasKey(ProjectorID.ToString() + "RotX") && PlayerPrefs.HasKey(ProjectorID.ToString() + "RotY") && PlayerPrefs.HasKey(ProjectorID.ToString() + "RotZ") && PlayerPrefs.HasKey(ProjectorID.ToString() + "RotW")) //{ // Quaternion rot = new Quaternion(PlayerPrefs.GetFloat(ProjectorID.ToString() + "RotX"), PlayerPrefs.GetFloat(ProjectorID.ToString() + "RotY"), PlayerPrefs.GetFloat(ProjectorID.ToString() + "RotZ"), PlayerPrefs.GetFloat(ProjectorID.ToString() + "RotW")); // Debug.Log("ProjRot " + rot); // CalibrationObject.transform.localRotation = rot; //} if (showCalibration) { OnShowCalibration(); } RemoteCmdHandler.Instance.RegisterForCmd(RemoteCmdType.MoveRef, ProjectorID.ToString(), MoveProjector); }
// 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; }