TangoARScreen.ViewportPointToCameraImagePoint C# (CSharp) Method

ViewportPointToCameraImagePoint() public method

Converts a normalized Unity viewport position into its corresponding normalized position on the color camera image.
public ViewportPointToCameraImagePoint ( Vector2 pos ) : Vector2
pos Vector2 Normalized position for the 3D viewport.
return Vector2
    public Vector2 ViewportPointToCameraImagePoint(Vector2 pos)
    {
        return new Vector2(Mathf.Lerp(m_uOffset, 1 - m_uOffset, pos.x),
                           Mathf.Lerp(m_vOffset, 1 - m_vOffset, pos.y));
    }

Usage Example

コード例 #1
0
ファイル: TangoPointCloud.cs プロジェクト: Lando121/TangoHack
    /// <summary>
    /// Estimates the depth of a point on a screen, based on nearest neighbors.
    /// </summary>
    /// <returns>
    /// <c>true</c> if a successful depth estimate was obtained.
    /// </returns>
    /// <param name="cam">The Unity camera.</param>
    /// <param name="pos">The point in pixel coordinates to perform depth estimation.</param>
    /// <param name="colorCameraPoint">
    /// The point (x, y, z), where (x, y) is the back-projection of the UV
    /// coordinates to the color camera space and z is the z coordinate of
    /// the point in the point cloud nearest to the user selection after
    /// projection onto the image plane. If there is not a point cloud point
    /// close to the user selection after projection onto the image plane,
    /// then the point will be set to (0.0, 0.0, 0.0) and isValidPoint will
    /// be set to false.
    /// </param>
    public bool EstimateDepthOnScreen(Camera cam, Vector2 pos, out Vector3 colorCameraPoint)
    {
        // Set up parameters
        Matrix4x4 colorCameraTUnityWorld = m_colorCameraTUnityCamera * cam.transform.worldToLocalMatrix;
        Vector2   normalizedPos          = cam.ScreenToViewportPoint(pos);

        // If the camera has a TangoARScreen attached, it is not displaying the entire color camera image.  Correct
        // the normalized coordinates by taking the clipping into account.
        TangoARScreen arScreen = cam.gameObject.GetComponent <TangoARScreen>();

        if (arScreen != null)
        {
            normalizedPos = arScreen.ViewportPointToCameraImagePoint(normalizedPos);
        }

        bool isValidPoint;
        int  returnType = TangoSupport.ScreenCoordinateToWorldNearestNeighbor(
            m_points,
            m_pointsCount,
            m_depthTimestamp,
            m_colorCameraIntrinsics,
            ref colorCameraTUnityWorld,
            normalizedPos,
            out colorCameraPoint,
            out isValidPoint);

        if (returnType != Common.ErrorType.TANGO_SUCCESS)
        {
            Debug.LogErrorFormat("TangoSupport.ScreenCoordinateToWorldNearestNeighbor failed with error code {0}.",
                                 returnType);
        }

        return((returnType == Common.ErrorType.TANGO_SUCCESS) && isValidPoint);
    }
All Usage Examples Of TangoARScreen::ViewportPointToCameraImagePoint