コード例 #1
0
        /// <summary>
        /// Inverts the rectangle's Y coordinates in screen space. Useful when
        /// the rectangle needs to be expressed in coordinate systems with the
        /// Y axis going either up or down.
        /// </summary>
        public static Rect InvertScreenY(this Rect rect)
        {
            Vector2 center = rect.center;

            center.y = Screen.height - 1 - center.y;
            return(RectEx.FromCenterAndSize(center, rect.size));
        }
コード例 #2
0
        /// <summary>
        /// Places 'rect' below 'other' and sets its center to the same center
        /// as 'other' horizontally.
        /// </summary>
        public static Rect PlaceBelowCenterHrz(this Rect rect, Rect other)
        {
            float centerX = other.center.x;
            float centerY = other.center.y - other.size.y * 0.5f - rect.size.y * 0.5f;

            return(RectEx.FromCenterAndSize(new Vector2(centerX, centerY), rect.size));
        }
コード例 #3
0
        /// <summary>
        /// Calculates and returns the rectangle that encloses all the 2D shapes which belong to
        /// the handle. If the handle doesn't contain any 2D shapes or if none of them are marked
        /// as visible, a rectangle with the size of 0 will be returned. The 'Is2DVisible' property
        /// is ignored. The function will also return an empty rect if the 3D position of the owner
        /// gizmo falls behind the camera near plane (i.e. behind the camera).
        /// </summary>
        public Rect GetVisible2DShapesRect(Camera camera)
        {
            if (Num2DShapes == 0 ||
                !camera.IsPointInFrontNearPlane(Gizmo.Transform.Position3D))
            {
                return(new Rect());
            }

            var allRectPts = new List <Vector2>(Num2DShapes * 4);

            foreach (var shape in _2DShapes)
            {
                if (!shape.IsVisible)
                {
                    continue;
                }

                Rect shapeRect = shape.Shape.GetEncapsulatingRect();
                allRectPts.AddRange(shapeRect.GetCornerPoints());
            }

            if (allRectPts.Count == 0)
            {
                return(new Rect());
            }
            return(RectEx.FromPoints(allRectPts));
        }
コード例 #4
0
 public override Rect GetEncapsulatingRect()
 {
     if (_arePointsDirty)
     {
         OnPointsFoundDirty();
     }
     return(RectEx.FromPoints(_points));
 }
コード例 #5
0
        public void OnGUI()
        {
            var    sgLookAndFeel = _sceneGizmo.LookAndFeel;
            Camera gizmoCamera   = _sceneGizmo.SceneGizmoCamera.Camera;

            if (sgLookAndFeel.IsCamPrjSwitchLabelVisible)
            {
                if (_sceneGizmo.SceneGizmoCamera.SceneCamera != RTFocusCamera.Get.TargetCamera ||
                    !RTFocusCamera.Get.IsDoingProjectionSwitch)
                {
                    Texture2D labelTexture = gizmoCamera.orthographic ? sgLookAndFeel.CamOrthoModeLabelTexture : sgLookAndFeel.CamPerspModeLabelTexture;
                    GUIEx.PushColor(sgLookAndFeel.CamPrjSwitchLabelTint);

                    Rect drawRect = RectEx.FromTexture2D(labelTexture).PlaceBelowCenterHrz(gizmoCamera.pixelRect).InvertScreenY();
                    drawRect.center = new Vector2(drawRect.center.x, Screen.height - 1 - _labelQuad.Center.y);

                    GUI.DrawTexture(drawRect, labelTexture);
                    GUIEx.PopColor();
                }
                else
                {
                    Texture2D destLabelTexture   = sgLookAndFeel.CamOrthoModeLabelTexture;
                    Texture2D sourceLabelTexture = sgLookAndFeel.CamPerspModeLabelTexture;
                    if (RTFocusCamera.Get.PrjSwitchTransitionType == CameraPrjSwitchTransition.Type.ToPerspective)
                    {
                        destLabelTexture   = sgLookAndFeel.CamPerspModeLabelTexture;
                        sourceLabelTexture = sgLookAndFeel.CamOrthoModeLabelTexture;
                    }

                    AnimationCurve srcAnimCurve  = AnimationCurve.EaseInOut(0.0f, sgLookAndFeel.CamPrjSwitchLabelTint.a, 1.0f, 0.0f);
                    AnimationCurve destAnimCurve = AnimationCurve.EaseInOut(0.0f, 0.0f, 1.0f, sgLookAndFeel.CamPrjSwitchLabelTint.a);

                    float destAlpha = destAnimCurve.Evaluate(RTFocusCamera.Get.PrjSwitchProgress);
                    float srcAlpha  = srcAnimCurve.Evaluate(RTFocusCamera.Get.PrjSwitchProgress);

                    GUIEx.PushColor(ColorEx.KeepAllButAlpha(sgLookAndFeel.CamPrjSwitchLabelTint, srcAlpha));
                    Rect drawRect = RectEx.FromTexture2D(sourceLabelTexture).PlaceBelowCenterHrz(gizmoCamera.pixelRect).InvertScreenY();
                    drawRect.center = new Vector2(drawRect.center.x, Screen.height - 1 - _labelQuad.Center.y);
                    GUI.DrawTexture(drawRect, sourceLabelTexture);
                    GUIEx.PopColor();

                    GUIEx.PushColor(ColorEx.KeepAllButAlpha(sgLookAndFeel.CamPrjSwitchLabelTint, destAlpha));
                    drawRect        = RectEx.FromTexture2D(destLabelTexture).PlaceBelowCenterHrz(gizmoCamera.pixelRect).InvertScreenY();
                    drawRect.center = new Vector2(drawRect.center.x, Screen.height - 1 - _labelQuad.Center.y);
                    GUI.DrawTexture(drawRect, destLabelTexture);
                    GUIEx.PopColor();
                }
            }
        }
コード例 #6
0
        private void UpdateTransform()
        {
            var    sgLookAndFeel = _sceneGizmo.LookAndFeel;
            Camera gizmoCamera   = _sceneGizmo.SceneGizmoCamera.Camera;

            Texture2D labelTexture = gizmoCamera.orthographic ? sgLookAndFeel.CamOrthoModeLabelTexture : sgLookAndFeel.CamPerspModeLabelTexture;
            Rect      labelRect    = RectEx.FromTexture2D(labelTexture);

            // Note: Use the maximum texture size to account for textures of different sizes. When
            //       drawing the label, we will keep the original texture size to avoid stretching
            //       but we will place its center at '_labelQuad.Center' to avoid sudden changes in
            //       position when doing projection switches.
            labelRect.size = sgLookAndFeel.CalculateMaxPrjSwitchLabelRectSize();
            labelRect      = labelRect.PlaceBelowCenterHrz(_sceneGizmo.SceneGizmoCamera.Camera.pixelRect);

            _labelQuad.Center = labelRect.center;
            _labelQuad.Size   = labelRect.size;
        }
コード例 #7
0
ファイル: Gizmo.cs プロジェクト: BertSlot/Gevel-Configurator
        public Rect GetVisible2DHandlesRect(Camera camera)
        {
            var allRectPts = new List <Vector2>();
            int numHandles = _handles.Count;

            for (int handleIndex = 0; handleIndex < numHandles; ++handleIndex)
            {
                var  handle     = _handles[handleIndex];
                Rect handleRect = handle.GetVisible2DShapesRect(camera);
                if (handleRect.width != 0 || handleRect.height != 0)
                {
                    allRectPts.AddRange(handleRect.GetCornerPoints());
                }
            }

            if (allRectPts.Count != 0)
            {
                return(RectEx.FromPoints(allRectPts));
            }
            return(new Rect());
        }
コード例 #8
0
 private void CalculateRect()
 {
     _rect        = RectEx.FromPoints(_cwPolyPoints);
     _isRectDirty = false;
 }
コード例 #9
0
        public override Rect GetEncapsulatingRect()
        {
            var cornerPoints = QuadMath.Calc2DQuadCornerPoints(_center, _size, _rotationDegrees);

            return(RectEx.FromPoints(cornerPoints));
        }
コード例 #10
0
 public override Rect GetEncapsulatingRect()
 {
     return(RectEx.FromPoints(GetExtentPoints()));
 }
コード例 #11
0
 public override Rect GetEncapsulatingRect()
 {
     return(RectEx.FromPoints(new Vector2[] { _startPoint, _endPoint }));
 }
コード例 #12
0
 public override Rect GetEncapsulatingRect()
 {
     return(RectEx.FromPoints(new List <Vector2> {
         BaseLeft, Tip, BaseRight
     }));
 }
コード例 #13
0
 private void OnBorderPointsFoundDirty()
 {
     _borderPoints         = PrimitiveFactory.Generate2DArcBorderPoints(_origin, _startPoint, _degreeAngleFromStart, _forceShortestArc, _numBorderPoints);
     _rect                 = RectEx.FromPoints(_borderPoints);
     _areBorderPointsDirty = false;
 }