/// <summary>
    /// Load marker list xml from application storage.
    /// </summary>
    private void _LoadMarkerFromDisk()
    {
        // Attempt to load the exsiting markers from storage.
        string path = Application.persistentDataPath + "/" + m_curAreaDescription.m_uuid + ".xml";

        var serializer = new XmlSerializer(typeof(List <MarkerData>));
        var stream     = new FileStream(path, FileMode.Open);

        List <MarkerData> xmlDataList = serializer.Deserialize(stream) as List <MarkerData>;

        if (xmlDataList == null)
        {
            Debug.Log("AndroidInGameController._LoadMarkerFromDisk(): xmlDataList is null");
            return;
        }

        m_markerList.Clear();
        foreach (MarkerData mark in xmlDataList)
        {
            // Instantiate all markers' gameobject.
            GameObject temp = m_bloonController.AddMarkerByData(mark);
            m_markerList.Add(temp);

            // Set Audio Path
            BloonMarker markerScript = temp.GetComponent <BloonMarker>();
            if (!String.IsNullOrEmpty(mark.m_audioFilePath))
            {
                Debug.Log(string.Format("Mark has audio: {0}", mark.m_audioFilePath));
                markerScript.m_audioRecordingFilename = mark.m_audioFilePath;
            }

            // Set Scale
            temp.transform.localScale = new Vector3(mark.m_scaleFactor, mark.m_scaleFactor, mark.m_scaleFactor);
        }
    }
    /// <summary>
    /// Correct all saved marks when loop closure happens.
    ///
    /// When Tango Service is in learning mode, the drift will accumulate overtime, but when the system sees a
    /// preexisting area, it will do a operation to correct all previously saved poses
    /// (the pose you can query with GetPoseAtTime). This operation is called loop closure. When loop closure happens,
    /// we will need to re-query all previously saved marker position in order to achieve the best result.
    /// This function is doing the querying job based on timestamp.
    /// </summary>
    private void _UpdateMarkersForLoopClosures()
    {
        // Adjust mark's position each time we have a loop closure detected.
        foreach (GameObject obj in m_markerList)
        {
            BloonMarker tempMarker = obj.GetComponent <BloonMarker>();
            if (tempMarker.m_timestamp != -1.0f)
            {
                TangoCoordinateFramePair pair;
                TangoPoseData            relocalizedPose = new TangoPoseData();

                pair.baseFrame   = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION;
                pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
                PoseProvider.GetPoseAtTime(relocalizedPose, tempMarker.m_timestamp, pair);

                Matrix4x4 uwTDevice = TangoSupport.UNITY_WORLD_T_START_SERVICE
                                      * relocalizedPose.ToMatrix4x4()
                                      * m_poseController.m_dTuc;

                Matrix4x4 uwTMarker = uwTDevice * tempMarker.m_deviceTMarker;

                obj.transform.position = uwTMarker.GetColumn(3);
                obj.transform.rotation = Quaternion.LookRotation(uwTMarker.GetColumn(2), uwTMarker.GetColumn(1));
            }
        }
    }
Ejemplo n.º 3
0
    void _StoreAudioFile(BloonMarker marker)
    {
        string filename = string.Format(@"{0}.wav", System.DateTime.Now.Ticks);

        Debug.Log("StoreAudioFile Starting...");
        bool complete = SavWav.Save(filename, goAudioSource.clip);

        if (complete)
        {
            Debug.Log(string.Format("StoreAudioFile Complete: {0}", filename));
            marker.m_audioRecordingFilename = filename;
        }
        else
        {
            Debug.LogError("Error saving file...");
        }
    }
Ejemplo n.º 4
0
    public void StopRecording(BloonMarker marker)
    {
        Debug.Log("StopRecording");

        if (Microphone.IsRecording(null))
        {
            Debug.Log("StopRecording: End()");
            Microphone.End(null);
        }

        marker.m_isRecording = false;
        marker.RecordingComplete();

        // test audio
//		goAudioSource.Play(); //Playback the recorded audio

        _StoreAudioFile(marker);
    }
    private void _PlayBackBalloonAndPop(BloonMarker marker)
    {
        Debug.Log(string.Format("PlayBackBalloonAndPop: {0}", marker.m_audioRecordingFilename));

        m_balloonPopAudio.Play();

        if (!string.IsNullOrEmpty(marker.m_audioRecordingFilename))
        {
            m_micHelper.PlayRecording(marker.m_audioRecordingFilename);
        }

        marker.Pop();
        m_balloonPoppedListener(marker.gameObject);

        if (m_currentMarker)
        {
            m_currentMarker = null;
        }
    }
Ejemplo n.º 6
0
 public void StartRecording(BloonMarker marker)
 {
     if (micConnected)
     {
         Debug.Log("StartRecording: connected");
         //If the audio from any microphone isn't being captured
         if (!Microphone.IsRecording(null))
         {
             Debug.Log("StartRecording: isRecording:false");
             //Start recording and store the audio captured from the microphone at the AudioClip in the AudioSource
             marker.m_isRecording = true;
             goAudioSource.clip   = Microphone.Start(null, false, MAX_RECORDING_SECONDS, maxFreq);
         }
     }
     else         // No microphone
     {
         //Print a red "Microphone not connected!" message at the center of the screen
         Debug.LogError("No Microphone connected!");
     }
 }
    public void _HandleTouch(Touch t)
    {
        Camera     cam = Camera.main;
        RaycastHit hitInfo;

        m_touchCounter++;

        if (t.phase == TouchPhase.Began)           // start touch
        {
            Debug.Log(t.phase);

            m_touchCounter = 0;

//			bool hitObject = Physics.Raycast (cam.ScreenPointToRay (t.position), out hitInfo);
//			if (hitObject) {
//				GameObject tapped = hitInfo.collider.gameObject;
//				BloonMarker marker = tapped.GetComponent<BloonMarker> ();
//
//				Debug.LogFormat ("hitObject: {0}", tapped);
//
//				if (marker) {
//					_PlayBackBalloonAndPop (tapped.GetComponent<BloonMarker> ());
//					return;
//				}
//			}

            // tapped somewhere decent, add a balloon
            Debug.Log("Adding Balloon");
            StartCoroutine(_AddBalloon(t.position));
        }
        else if ((t.phase == TouchPhase.Moved || t.phase == TouchPhase.Stationary) && m_currentMarker == null)
        {
            Debug.Log("Waiting to ballon to be created...");
        }
        else if ((t.phase == TouchPhase.Moved || t.phase == TouchPhase.Stationary) && m_currentMarker)
        {
            // TODO do cool shit while moving around/recording
            if (m_currentMarker.m_isRecording)
            {
                m_currentMarker.Grow();
            }
        }
        else if (t.phase == TouchPhase.Ended && m_currentMarker)              // end touch
        {
            Debug.Log("Recording/TouchPhase complete");

            if (m_currentMarker.m_isRecording)
            {
                m_micHelper.StopRecording(m_currentMarker);
            }

//			bool hitObject = Physics.Raycast (cam.ScreenPointToRay (t.position), out hitInfo);
//			if (hitObject) {
//				GameObject tapped = hitInfo.collider.gameObject;
//				BloonMarker marker = tapped.GetComponent<BloonMarker> ();
//
//				Debug.LogFormat ("hitObject: {0}", tapped);
//
//				if (marker) {
//					_PlayBackBalloonAndPop (tapped.GetComponent<BloonMarker> ());
//					return;
//				}
//			}

            m_currentMarker = null;
        }
    }
    private IEnumerator _AddBalloon(Vector2 touchPosition)
    {
        m_findPlaneWaitingForDepth = true;

        // Turn on the camera and wait for a single depth update.
        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.MAXIMUM);
        while (m_findPlaneWaitingForDepth)
        {
            yield return(null);
        }

        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.DISABLED);

        // Find the plane.
        Camera cam = Camera.main;

        // Ensure the location is always facing the camera.  This is like a LookRotation, but for the Y axis.
        Vector3 up = Vector3.up;         // plane.normal;
        Vector3 forward;

        if (Vector3.Angle(Vector3.up, cam.transform.forward) < 175)
        {
            Vector3 right = Vector3.Cross(up, cam.transform.forward).normalized;
            forward = Vector3.Cross(right, up).normalized;
        }
        else
        {
            // Normal is nearly parallel to camera look direction, the cross product would have too much
            // floating point error in it.
            forward = Vector3.Cross(up, cam.transform.right);
        }

        Vector3 inFront = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.5f));

        // Instantiate marker object.
        GameObject newMarkObject = Instantiate(m_marker,
                                               inFront,
                                               Quaternion.LookRotation(forward, Vector3.up)
                                               ) as GameObject;

        BloonMarker markerScript = newMarkObject.GetComponent <BloonMarker>();

//		markerScript.m_type = m_currentMarkType;
//		markerScript.m_timestamp = (float)m_poseController.m_poseTimestamp;

//		Matrix4x4 uwTDevice = Matrix4x4.TRS(m_poseController.m_tangoPosition,
//			m_poseController.m_tangoRotation,
//			Vector3.one);
//		Matrix4x4 uwTMarker = Matrix4x4.TRS(newMarkObject.transform.position,
//			newMarkObject.transform.rotation,
//			Vector3.one);
//		markerScript.m_deviceTMarker = Matrix4x4.Inverse(uwTDevice) * uwTMarker;

//		m_markerList.Add(newMarkObject);

        m_balloonAddedListener(newMarkObject);


        m_currentMarker = markerScript;

        Debug.LogFormat("Balloon successfully Created: {0}", m_currentMarker);

        m_micHelper.StartRecording(m_currentMarker);
    }