using UnityEngine; namespace InteractiveVideo { /// /// The single place where the two coordinate conventions meet. /// /// TRACKING coordinates (the JSON, all of ): /// x 0 = left, 1 = right; y 0 = TOP, 1 = bottom. /// /// VIDEO UV (the RenderTexture the VideoPlayer writes, the mask RenderTexture, the shader): /// x 0 = left, 1 = right; y 0 = BOTTOM, 1 = top. /// /// Nothing else in the code base may flip Y. If a convention ever changes, change it here. /// public static class VideoCoordinates { public static Vector2 TrackingToUv(Vector2 tracking) => new Vector2(tracking.x, 1f - tracking.y); public static Vector2 UvToTracking(Vector2 uv) => new Vector2(uv.x, 1f - uv.y); /// Rect in tracking space (yMin = top edge) to a rect in UV space (yMin = bottom edge). public static Rect TrackingToUv(Rect tracking) => Rect.MinMaxRect(tracking.xMin, 1f - tracking.yMax, tracking.xMax, 1f - tracking.yMin); public static bool IsInsideUnitSquare(Vector2 p) => p.x >= 0f && p.x <= 1f && p.y >= 0f && p.y <= 1f; } }