public void TransformCoordinates2d(ref Vector2 uv, DisplayUvCoordinateType inputType,
                                           DisplayUvCoordinateType outputType)
        {
            Vector2 uvOut = new Vector2(uv.x, uv.y);

            ExternApi.ArFrame_transformCoordinates2d(m_NativeSession.SessionHandle, m_NativeSession.FrameHandle,
                                                     inputType.ToApiCoordinates2dType(), 1, ref uv, outputType.ToApiCoordinates2dType(), ref uvOut);

            uv = uvOut;
        }
Example #2
0
        public static ApiCoordinates2dType ToApiCoordinates2dType(this DisplayUvCoordinateType coordinateType)
        {
            switch (coordinateType)
            {
            case DisplayUvCoordinateType.BackgroundImage:
                return(ApiCoordinates2dType.ImageNormalized);

            case DisplayUvCoordinateType.BackgroundTexture:
                return(ApiCoordinates2dType.TextureNormalized);

            case DisplayUvCoordinateType.UnityScreen:
                return(ApiCoordinates2dType.ViewNormalized);

            default:
                return(ApiCoordinates2dType.ViewNormalized);
            }
        }
Example #3
0
            /// <summary>
            /// Transforms a coordinate between the <c>source</c> and <c>target</c> display UV coordinate types.
            /// </summary>
            /// <remarks>
            /// This can be used for the conversion of coordinates accessed in the same Unity update.
            /// </remarks>
            /// <param name="coordinate">The coordinate to transform.</param>
            /// <param name="sourceType">The source type of the desired transformation matrix.</param>
            /// <param name="targetType">The target type of the desired transformation matrix.</param>
            /// <returns>A corresponding position in the target frame.</returns>
            public static Vector2 TransformCoordinate(Vector2 coordinate, DisplayUvCoordinateType sourceType,
                                                      DisplayUvCoordinateType targetType)
            {
                if (InstantPreviewManager.IsProvidingPlatform)
                {
                    InstantPreviewManager.LogLimitedSupportMessage("access 'Frame.TransformCoordinate'");
                    return(Vector2.zero);
                }

                var nativeSession = LifecycleManager.Instance.NativeSession;

                if (nativeSession == null)
                {
                    Debug.LogError("Cannot transform coordinate when native session is null.");
                    return(Vector2.zero);
                }

                nativeSession.FrameApi.TransformCoordinates2d(ref coordinate, sourceType, targetType);
                return(coordinate);
            }