Esempio n. 1
0
    /// <summary>
    /// project a normalized point on a trapezoid
    /// </summary>
    /// <param name="trapezoid">the trapezoid</param>
    /// <param name="normPos">the normalize point</param>
    /// <returns>absolute point relative to the given trapezoid</returns>
    private Vector2 ProjectNormalizedPosition(UnityPlayerManagement.TrapezoidDefinition trapezoid, Vector2 normPos)
    {
        float worldY   = MathHelpers.UnclampedLerp(trapezoid.nearPlane, trapezoid.farPlane, normPos.y);
        float widthAtY = MathHelpers.UnclampedLerp(trapezoid.nearWidth, trapezoid.farWidth, normPos.y);
        float worldX   = -MathHelpers.UnclampedLerp(0, widthAtY / 2, normPos.x);

        return(new Vector2(worldX, worldY));
    }
Esempio n. 2
0
    /// <summary>
    /// normalize a point in world to its relative position to a trapezoid
    /// </summary>
    /// <param name="trapezoid">the trapezoid</param>
    /// <param name="worldPos">the world position</param>
    /// <returns>the relative position of the point relative to the trapezoid</returns>
    private Vector2 GetNormalizedTrapezoidPosition(UnityPlayerManagement.TrapezoidDefinition trapezoid, Vector3 worldPos)
    {
        float normalizedY = MathHelpers.UnclampedInverseLerp(trapezoid.nearPlane, trapezoid.farPlane, worldPos.z);

        float widthAtY    = MathHelpers.UnclampedLerp(trapezoid.nearWidth, trapezoid.farWidth, normalizedY);
        float normalizedX = MathHelpers.UnclampedInverseLerp(0, widthAtY / 2, worldPos.x);

        return(new Vector2(normalizedX, normalizedY));
    }
Esempio n. 3
0
    /// <summary>
    /// compute the screen position for a world 3d position
    /// </summary>
    /// <param name="worldPosition">the world point to map to screen</param>
    /// <returns>screen position corresponding to worldPosition</returns>
    Vector2 WorldToScreenProjection(Vector3 worldPosition)
    {
        UnityPlayerManagement.TrapezoidsPair trapezoidConfiguration = UnityPlayerManagement.GetAppliedTrapezoidsConfiguration();
        if (trapezoidConfiguration == null)
        {
            return(Vector2.zero);
        }
        UnityPlayerManagement.TrapezoidDefinition worldTrapezoid = trapezoidConfiguration.innerTrapezoid;

        Vector2 normalizedPosition = GetNormalizedTrapezoidPosition(worldTrapezoid, worldPosition);

        normalizedPosition.x = Mathf.Clamp(normalizedPosition.x, -1 - m_boundarySize, 1 + m_boundarySize);
        normalizedPosition.y = Mathf.Clamp(normalizedPosition.y, -m_boundarySize, 1 + m_boundarySize);

        Vector2 projectedPosition = ProjectNormalizedPosition(m_screenTrapezoid, normalizedPosition);

        projectedPosition.x += m_screenCoordinates.width / 2;

        return(projectedPosition);
    }