示例#1
0
        public void ScaleToAspect(AspectMode mode, float ratio)
        {
            if (mode == AspectMode.Ignore)
            {
                return;
            }

            if (Width <= 0 && Height <= 0)
            {
                return;
            }

            //assert(ratio > 0);

            float expectedWidth = Height * ratio;
            bool  keepHeight    = (mode == AspectMode.Shrink)
                                  ? expectedWidth <= Width
                                  : expectedWidth >= Width;

            if (keepHeight)
            {
                Width = expectedWidth;
            }
            else
            {
                Height = Width / ratio;
            }
        }
        static Vector4 GetTextureST(float srcAspect, float dstAspect, AspectMode mode)
        {
            switch (mode)
            {
            case AspectMode.None:
                return(new Vector4(1, 1, 0, 0));

            case AspectMode.Fit:
                if (srcAspect > dstAspect)
                {
                    float s = srcAspect / dstAspect;
                    return(new Vector4(1, s, 0, (1 - s) / 2));
                }
                else
                {
                    float s = dstAspect / srcAspect;
                    return(new Vector4(s, 1, (1 - s) / 2, 0));
                }

            case AspectMode.Fill:
                if (srcAspect > dstAspect)
                {
                    float s = dstAspect / srcAspect;
                    return(new Vector4(s, 1, (1 - s) / 2, 0));
                }
                else
                {
                    float s = srcAspect / dstAspect;
                    return(new Vector4(1, s, 0, (1 - s) / 2));
                }
            }
            throw new System.Exception("Unknown aspect mode");
        }
 /// <summary>
 /// Create a crop texture input.
 /// </summary>
 /// <param name="input">Backing texture input to receive cropped frames.</param>
 public CropTextureInput(ITextureInput input)
 {
     this.input        = input;
     this.material     = new Material(Shader.Find(@"Hidden/NCPX/CropFilter"));
     this.frameSizeInv = new Vector2(1f / input.frameSize.width, 1f / input.frameSize.height);
     this.rect         = new RectInt(0, 0, input.frameSize.width, input.frameSize.height);
     this.aspectMode   = 0;
 }
示例#4
0
 /// <summary>
 /// Create a crop texture input.
 /// </summary>
 /// <param name="recorder">Media recorder to receive video frames.</param>
 /// <param name="textureInput">Backing texture input for committing frames to recorder.</param>
 public CropTextureInput(IMediaRecorder recorder, ITextureInput textureInput = null)
 {
     this.recorder   = recorder;
     this.input      = textureInput ?? new TextureInput(recorder);
     this.material   = new Material(Shader.Find(@"Hidden/NCPX/CropTextureInput"));
     this.cropRect   = new RectInt(0, 0, recorder.frameSize.width, recorder.frameSize.height);
     this.aspectMode = 0;
 }
示例#5
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         if (BgColor != null)
         {
             hashCode = hashCode * 59 + BgColor.GetHashCode();
         }
         if (Camera != null)
         {
             hashCode = hashCode * 59 + Camera.GetHashCode();
         }
         if (Domain != null)
         {
             hashCode = hashCode * 59 + Domain.GetHashCode();
         }
         if (AspectMode != null)
         {
             hashCode = hashCode * 59 + AspectMode.GetHashCode();
         }
         if (AspectRatio != null)
         {
             hashCode = hashCode * 59 + AspectRatio.GetHashCode();
         }
         if (XAxis != null)
         {
             hashCode = hashCode * 59 + XAxis.GetHashCode();
         }
         if (YAxis != null)
         {
             hashCode = hashCode * 59 + YAxis.GetHashCode();
         }
         if (ZAxis != null)
         {
             hashCode = hashCode * 59 + ZAxis.GetHashCode();
         }
         if (DragMode != null)
         {
             hashCode = hashCode * 59 + DragMode.GetHashCode();
         }
         if (HoverMode != null)
         {
             hashCode = hashCode * 59 + HoverMode.GetHashCode();
         }
         if (UiRevision != null)
         {
             hashCode = hashCode * 59 + UiRevision.GetHashCode();
         }
         if (Annotations != null)
         {
             hashCode = hashCode * 59 + Annotations.GetHashCode();
         }
         return(hashCode);
     }
 }
示例#6
0
 public Camera2D(GraphicsDevice device, int cWidth, int cHeight, AspectMode cAspect = AspectMode.Expand)
 {
     Camera = new Camera(device)
     {
         Width      = cWidth,
         Height     = cHeight,
         ResizeMode = cAspect
     };
     Camera.Debug.IsVisible = false;
     Camera.Position        = Vector2.Zero;
 }
示例#7
0
    Vector2 GetAspectSize(Vector2 source, Vector2 ToFit, AspectMode mode)
    {
        Vector2 result = Vector2.one;

        //數值越高越長
        float ratio       = source.x / source.y;
        float screenRatio = ToFit.x / ToFit.y;

        if (mode == AspectMode.Expand)
        {
            if (ratio > screenRatio)
            {
                //此處照片比畫面長, 固定螢幕短邊, 計算長邊
                result = new Vector2(ToFit.y / source.y * source.x, ToFit.y);
            }
            else
            {
                //此處照片比畫面短, 固定螢幕長邊, 計算短邊
                result = new Vector2(ToFit.x, ToFit.x / source.x * source.y);
            }
        }
        else
        {
            if (ratio > screenRatio)
            {
                //相反
                result = new Vector2(ToFit.x, ToFit.x / source.x * source.y);
            }
            else
            {
                //相反
                result = new Vector2(ToFit.y / source.y * source.x, ToFit.y);
            }
        }

        return(result);
    }
示例#8
0
        public bool Equals([AllowNull] Scene other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return((BgColor == other.BgColor && BgColor != null && other.BgColor != null && BgColor.Equals(other.BgColor)) &&
                   (Camera == other.Camera && Camera != null && other.Camera != null && Camera.Equals(other.Camera)) &&
                   (Domain == other.Domain && Domain != null && other.Domain != null && Domain.Equals(other.Domain)) &&
                   (AspectMode == other.AspectMode && AspectMode != null && other.AspectMode != null && AspectMode.Equals(other.AspectMode)) &&
                   (AspectRatio == other.AspectRatio && AspectRatio != null && other.AspectRatio != null && AspectRatio.Equals(other.AspectRatio)) &&
                   (XAxis == other.XAxis && XAxis != null && other.XAxis != null && XAxis.Equals(other.XAxis)) &&
                   (YAxis == other.YAxis && YAxis != null && other.YAxis != null && YAxis.Equals(other.YAxis)) &&
                   (ZAxis == other.ZAxis && ZAxis != null && other.ZAxis != null && ZAxis.Equals(other.ZAxis)) &&
                   (DragMode == other.DragMode && DragMode != null && other.DragMode != null && DragMode.Equals(other.DragMode)) &&
                   (HoverMode == other.HoverMode && HoverMode != null && other.HoverMode != null && HoverMode.Equals(other.HoverMode)) &&
                   (UiRevision == other.UiRevision && UiRevision != null && other.UiRevision != null && UiRevision.Equals(other.UiRevision)) &&
                   (Equals(Annotations, other.Annotations) || Annotations != null && other.Annotations != null && Annotations.SequenceEqual(other.Annotations)));
        }
        public static Rect GetUVRect(float srcAspect, float dstAspect, AspectMode mode)
        {
            Vector4 texST = GetTextureST(srcAspect, dstAspect, mode);

            return(new Rect(texST.z, texST.w, texST.x, texST.y));
        }
示例#10
0
 /// <summary>
 /// Change Aspect Mode
 /// </summary>
 /// <param name="mode">Mode to be changed</param>
 public void ChangeMode(AspectMode mode)
 {
     Mode = mode;
     Initialize();
 }