예제 #1
0
        public void DrawArcRectangle(Vector3 startPosition, Vector3 endPosition, float startRadius, float endRadius = 0)
        {
            if (rectangle[0] != null)
            {
                return;
            }

            if (endRadius <= 0)
            {
                endRadius = startRadius;
            }

            var difference = startPosition - endPosition;
            var rotation = difference.Rotated(MathUtil.DegreesToRadians(90));
            rotation.Normalize();

            var start = rotation * startRadius;
            var end = rotation * endRadius;

            var correctedEnd = startPosition.Extend(
                endPosition,
                startPosition.Distance2D(endPosition) - endRadius * 0.45f);

            var rightStartPosition = startPosition + start;
            var leftStartPosition = startPosition - start;
            var rightEndPosition = correctedEnd + end;
            var leftEndPosition = correctedEnd - end;

            rectangle[0] = DrawLine(rightStartPosition, rightEndPosition);
            rectangle[1] = DrawLine(rightStartPosition, leftStartPosition);
            rectangle[2] = DrawLine(leftStartPosition, leftEndPosition);
            rectangle[3] = DrawArc(endPosition, startPosition, endRadius);
        }
예제 #2
0
        public void UpdateRectaglePosition(
            Vector3 startPosition,
            Vector3 endPosition,
            float startWidth,
            float endWidth = 0)
        {
            if (rectangle[0] == null)
            {
                return;
            }

            if (endWidth <= 0)
            {
                endWidth = startWidth;
            }

            endPosition = startPosition.Extend(endPosition, startPosition.Distance2D(endPosition) + endWidth / 2);

            var difference = startPosition - endPosition;
            var rotation = difference.Rotated(MathUtil.DegreesToRadians(90));
            rotation.Normalize();

            var start = rotation * startWidth;
            var end = rotation * endWidth;

            var rightStartPosition = startPosition + start;
            var leftStartPosition = startPosition - start;
            var rightEndPosition = endPosition + end;
            var leftEndPosition = endPosition - end;

            rectangle[0].SetControlPoint(1, rightStartPosition);
            rectangle[0].SetControlPoint(2, rightEndPosition);

            rectangle[1].SetControlPoint(1, rightStartPosition);
            rectangle[1].SetControlPoint(2, leftStartPosition);

            rectangle[2].SetControlPoint(1, leftStartPosition);
            rectangle[2].SetControlPoint(2, leftEndPosition);

            rectangle[3].SetControlPoint(1, leftEndPosition);
            rectangle[3].SetControlPoint(2, rightEndPosition);
        }