Exemple #1
0
    /// <summary>
    /// Wait for the next depth update, then find the nearest edge in the point
    /// cloud.
    /// </summary>
    /// <param name="touchPosition">Touch position on the screen.</param>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _WaitForDepth(Vector2 touchPosition)
    {
        m_waitingForDepth = true;

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

        m_tangoApplication.SetDepthCameraRate(
            TangoEnums.TangoDepthCameraRate.DISABLED);

        m_camera = Camera.main;
        int pointIndex = m_pointCloud.FindClosestPoint(m_camera, touchPosition, 10);

        if (pointIndex > -1)
        {
            m_currTouch = m_pointCloud.m_points[pointIndex];
            //_RenderCustomize(m_currTouch, new Vector3(m_currTouch[0] + 0.005f, m_currTouch[1], m_currTouch[2]));
            Debug.Log("<<<<<<<<<<<<<<<< mouse position: " + m_currTouch[0] + ", " + m_currTouch[1] + ", " + m_currTouch[2]);
        }

        TangoSupport.TangoSupportEdge[] edges;
        int  num_edges;
        bool edgeResult = m_pointCloud.FindEdges(m_imagebuffer, m_camera, touchPosition,
                                                 out edges, out num_edges);

        Debug.Log("<<<<<<<<<<< Edge result: " + edgeResult);

        if (edgeResult == true)
        {
            m_edgeCount    = num_edges;
            m_startPoint   = new Vector3[num_edges];
            m_endPoint     = new Vector3[num_edges];
            m_nearestPoint = new Vector3[num_edges];
            for (int i = 0; i < num_edges; i++)
            {
                Debug.Log("<<<<<<<<< starting point's x: " + edges[i].end_points_x1);
                m_startPoint[i] = new Vector3(edges[i].end_points_x1,
                                              edges[i].end_points_y1,
                                              edges[i].end_points_z1);
                Debug.Log("<<<<<<<<<< " + m_startPoint[i][0] + ", " + m_startPoint[i][1] + ", " + m_startPoint[i][2]);
                m_endPoint[i] = new Vector3(edges[i].end_points_x2,
                                            edges[i].end_points_y2,
                                            edges[i].end_points_z2);
                Debug.Log("<<<<<<<<<< " + m_endPoint[i][0] + ", " + m_endPoint[i][1] + ", " + m_endPoint[i][2]);
                m_nearestPoint[i] = new Vector3(edges[i].closest_point_on_edge_x,
                                                edges[i].closest_point_on_edge_y,
                                                edges[i].closest_point_on_edge_z);
                Debug.Log("<<<<<<<<<< " + m_nearestPoint[i][0] + ", " + m_nearestPoint[i][1] + ", " + m_nearestPoint[i][2]);
            }
            _RenderLine();
        }
    }