/// <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)); }
/// <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)); }
/// <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)); }
public override Rect GetEncapsulatingRect() { if (_arePointsDirty) { OnPointsFoundDirty(); } return(RectEx.FromPoints(_points)); }
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(); } } }
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; }
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()); }
public override Rect GetEncapsulatingRect() { return(RectEx.FromPoints(new List <Vector2> { BaseLeft, Tip, BaseRight })); }
public override Rect GetEncapsulatingRect() { return(RectEx.FromPoints(GetPoints())); }
public void Render() { if (_sharedLookAndFeel == null) { return; } if (IsActive) { Material material = MaterialPool.Get.SimpleColor; if (_sharedLookAndFeel.DrawBoxes) { material.SetColor(_sharedLookAndFeel.BoxLineColor); material.SetZTestEnabled(true); material.SetPass(0); var boundsQConfig = GetObjectBoundsQConfig(); foreach (var targetObject in _targetObjects) { if (targetObject == null) { continue; } OBB worldOBB = ObjectBounds.CalcWorldOBB(targetObject, boundsQConfig); if (worldOBB.IsValid) { GraphicsEx.DrawWireBox(worldOBB); } } } Camera camera = Camera.current; Vector2 screenSnapPivot = camera.WorldToScreenPoint(_snapPivotPoint); if (_sharedLookAndFeel.PivotShapeType == PivotPointShapeType.Circle) { material.SetZTestEnabled(false); material.SetColor(_sharedLookAndFeel.PivotPointFillColor); material.SetPass(0); const int numCirclePoints = 100; List <Vector2> pivotCirclePoints = PrimitiveFactory.Generate2DCircleBorderPointsCW(screenSnapPivot, _sharedLookAndFeel.PivotCircleRadius, numCirclePoints); GLRenderer.DrawTriangleFan2D(screenSnapPivot, pivotCirclePoints, camera); if (_sharedLookAndFeel.DrawPivotBorder) { material.SetColor(_sharedLookAndFeel.PivotPointBorderColor); material.SetPass(0); GLRenderer.DrawLineLoop2D(pivotCirclePoints, camera); } } else if (_sharedLookAndFeel.PivotShapeType == PivotPointShapeType.Square) { material.SetZTestEnabled(false); material.SetColor(_sharedLookAndFeel.PivotPointFillColor); material.SetPass(0); Rect pivotRect = RectEx.FromCenterAndSize(screenSnapPivot, Vector2Ex.FromValue(_sharedLookAndFeel.PivotSquareSideLength)); GLRenderer.DrawRect2D(pivotRect, camera); if (_sharedLookAndFeel.DrawPivotBorder) { material.SetColor(_sharedLookAndFeel.PivotPointBorderColor); material.SetPass(0); GLRenderer.DrawRectBorder2D(pivotRect, camera); } } } }
public void Render() { if (SharedLookAndFeel == null) { return; } if (IsActive && _grabSurfaceInfo.SurfaceType != GrabSurfaceType.Invalid) { Material material = MaterialPool.Get.SimpleColor; if (SharedLookAndFeel.DrawAnchorLines) { List <Vector3> linePoints = new List <Vector3>(_grabTargets.Count * 2); foreach (GrabTarget grabTarget in _grabTargets) { linePoints.Add(grabTarget.Transform.position); linePoints.Add(_grabSurfaceInfo.AnchorPoint); } material.SetZTestAlways(); material.SetColor(_sharedLookAndFeel.AnchorLineColor); material.SetPass(0); GLRenderer.DrawLines3D(linePoints); } if (SharedLookAndFeel.DrawObjectBoxes) { material.SetZTestLess(); material.SetColor(SharedLookAndFeel.ObjectBoxWireColor); material.SetPass(0); ObjectBounds.QueryConfig boundsQConfig = GetObjectBoundsQConfig(); foreach (GrabTarget grabTarget in _grabTargets) { OBB obb = ObjectBounds.CalcHierarchyWorldOBB(grabTarget.GameObject, boundsQConfig); if (obb.IsValid) { GraphicsEx.DrawWireBox(obb); } } } if (SharedLookAndFeel.DrawObjectPosTicks) { material.SetColor(SharedLookAndFeel.ObjectPosTickColor); material.SetPass(0); foreach (GrabTarget grabTarget in _grabTargets) { Vector2 screenPos = Camera.current.WorldToScreenPoint(grabTarget.Transform.position); GLRenderer.DrawRect2D(RectEx.FromCenterAndSize(screenPos, Vector2Ex.FromValue(SharedLookAndFeel.ObjectPosTickSize)), Camera.current); } } if (SharedLookAndFeel.DrawAnchorPosTick) { material.SetColor(SharedLookAndFeel.AnchorPosTickColor); material.SetPass(0); Vector2 anchorScreenPos = Camera.current.WorldToScreenPoint(_grabSurfaceInfo.AnchorPoint); GLRenderer.DrawRect2D(RectEx.FromCenterAndSize(anchorScreenPos, Vector2Ex.FromValue(SharedLookAndFeel.AnchorPosTickSize)), Camera.current); } } }
private void OnBorderPointsFoundDirty() { _borderPoints = PrimitiveFactory.Generate2DArcBorderPoints(_origin, _startPoint, _degreeAngleFromStart, _forceShortestArc, _numBorderPoints); _rect = RectEx.FromPoints(_borderPoints); _areBorderPointsDirty = false; }
public override Rect GetEncapsulatingRect() { return(RectEx.FromPoints(new Vector2[] { _startPoint, _endPoint })); }
private void CalculateRect() { _rect = RectEx.FromPoints(_cwPolyPoints); _isRectDirty = false; }
public override Rect GetEncapsulatingRect() { var cornerPoints = QuadMath.Calc2DQuadCornerPoints(_center, _size, _rotationDegrees); return(RectEx.FromPoints(cornerPoints)); }
public override Rect GetEncapsulatingRect() { System.Collections.Generic.List <Vector2> cornerPoints = QuadMath.Calc2DQuadCornerPoints(_center, _size, _rotationDegrees); return(RectEx.FromPoints(cornerPoints)); }