/// <summary> /// Function for unity3D code initialization /// </summary> void Start() { //Setup logger //load previous settings if (enable_logging) { StreamReader fileReader = null; string logFile = Application.persistentDataPath + "/log.txt"; if (File.Exists(logFile)) { fileReader = new StreamReader(logFile); logFileData = fileReader.ReadToEnd(); fileReader.Close(); } } //first few frames is not valid, have to wait for valid frame StartCoroutine(CheckTheValidityOfTexture()); //implement SlamFlex hooks mSendStringDelegate = new SlamFlexWrapper.SendStringDelegate(ReciveStringFromPlugin); mSendPoseDelegate = new SlamFlexWrapper.SendPoseDelegate(RecivePoseFromPlugin); mSendLogDelegate = new SlamFlexWrapper.SendLogDelegate(Logging); mSendArrayPointsDelegate = new SlamFlexWrapper.SendArrayPointsDelegate(ReciveArrayPointsFromPlugin); //initialize SLAMflex plugin SlamFlexWrapper.StartSlam(mSendStringDelegate, mSendPoseDelegate, mSendLogDelegate, mSendArrayPointsDelegate); }
/// <summary> /// Function for starting SLAMflex until enough points for generation of map is found /// </summary> /// <returns></returns> private IEnumerator AutoEnd() { autoend = true; while (autoend) { yield return(new WaitForSeconds(1f)); SlamFlexWrapper.StartPlaneDetection(); Debug.Log("AutoEnd finished"); } }
void Update() { //we have valid texture as input, each update send one frame to plugin if (textureOk && !planeRotationFound) { this._buf = (Color32[])this.w.GetPixels32(); m_PixelsHandle = GCHandle.Alloc(this._buf, GCHandleType.Pinned); current_State = SlamFlexWrapper.SetNewFrame(m_PixelsHandle.AddrOfPinnedObject(), this.w.width, this.w.height); m_PixelsHandle.Free(); } }
/// <summary> /// Function for unity3D GUI /// </summary> void OnGUI() { if (GUI.Button(new Rect(Screen.width * 0.9f, 0, Screen.width * 0.1f, Screen.width * 0.1f), "Exit")) { Debug.Log("Unity_ App exits"); Application.Quit(); } if (GUI.Button(new Rect(Screen.width - (Screen.width * 0.3f), (Screen.height - (Screen.width * 0.3f)), Screen.width * 0.3f, Screen.width * 0.3f), "Start Plane Detection")) { Debug.Log("Unity_ Tracking started"); planeRotationFound = false; this._ground_plane.SetActive(false); Camera.main.transform.eulerAngles = Vector3.zero; SlamFlexWrapper.StartPlaneDetection(); StartCoroutine(AutoEnd()); } if (GUI.Button(new Rect(0, (Screen.height - (Screen.width * 0.3f)), Screen.width * 0.3f, Screen.width * 0.3f), "Stop Plane Detection")) { Debug.Log("Unity_ Tracking stoped"); planeRotationFound = false; this._ground_plane.transform.position = orginalPlainePosition; this._ground_plane.SetActive(false); Camera.main.transform.eulerAngles = Vector3.zero; SlamFlexWrapper.StopSlam(); } string text = ""; if (autoend) { text = "\nMessages: " + userMessagesTextInstr + "\n" + userMessagesText + "\n" + userMessagesText1; } else { text = "\nMessages: " + userMessagesText + "\n" + userMessagesText1; } GUI.Label(new Rect(0f, 0f, 200, 200), "Current tracking state: " + current_State.ToString()); GUI.Label(new Rect(0, 100, 400, 400), text); }