コード例 #1
0
        private void SetPoint(RenderedPolygon renderedPolygon, Vector2F point, float size, Color color)
        {
            Span <Vector2F> points = stackalloc Vector2F[4];

            points[0] = point + new Vector2F(-1f, -1f) * size / 2f;
            points[1] = point + new Vector2F(1f, -1f) * size / 2f;
            points[2] = point + new Vector2F(1f, 1f) * size / 2f;
            points[3] = point + new Vector2F(-1f, 1f) * size / 2f;

            var array = Vector2FArray.Create(points);

            renderedPolygon.CreateVertexesByVector2F(array);
            renderedPolygon.OverwriteVertexesColor(color);
        }
コード例 #2
0
        //internal void Update()
        //{
        //    var origin = _TransformNode.Position;

        //    UpdateSizeBox(origin);
        //    UpdatePivot();
        //    UpdateMargin(origin);
        //    UpdateAnchors();
        //}

        //private void UpdateSizeBox(Vector2F origin)
        //{
        //    var points = new Vector2F[4];

        //    points[0] = origin + new Vector2F();
        //    points[1] = origin + new Vector2F(_TransformNode.Size.X, 0);
        //    points[2] = origin + _TransformNode.Size;
        //    points[3] = origin + new Vector2F(0, _TransformNode.Size.Y);

        //    for (int i = 0; i < points.Length; i++)
        //    {
        //        var point1 = points[i];
        //        var point2 = points[(i + 1) % points.Length];

        //        SetLine(_SizeBoxLines[i], point1, point2, new Color(255, 128, 0));
        //    }
        //}

        //private void UpdatePivot()
        //{
        //    SetPoint(_PivotBox, _TransformNode.Position, 5f, new Color(255, 128, 0));
        //}

        //private void UpdateMargin(Vector2F origin)
        //{
        //    var ancestorSize = GetAncestorSize();

        //    SetLine(_LeftTop,
        //        ancestorSize * _TransformNode.AnchorMin,
        //        origin, new Color(255, 100, 100));
        //    SetLine(_RightBottom,
        //        ancestorSize * _TransformNode.AnchorMax,
        //        origin + _TransformNode.Size, new Color(100, 100, 255));
        //}

        //private void UpdateAnchors()
        //{
        //    var ancestorSize = GetAncestorSize();

        //    SetPoint(_AnchorMin, ancestorSize * _TransformNode.AnchorMin, 4, new Color(255, 0, 0));
        //    SetPoint(_AnchorMax, ancestorSize * _TransformNode.AnchorMax, 4, new Color(0, 0, 255));
        //}

        private void SetLine(RenderedPolygon renderedPolygon, Vector2F point1, Vector2F point2, Color color)
        {
            Span <Vector2F> positions = stackalloc Vector2F[4];
            var             vec       = point2 - point1;

            var side = new Vector2F(vec.Y, -vec.X).Normal;

            positions[0] = point1 - side;
            positions[1] = point1 + side;
            positions[2] = point2 + side;
            positions[3] = point2 - side;

            var array = Vector2FArray.Create(positions);

            renderedPolygon.CreateVertexesByVector2F(array);
            renderedPolygon.OverwriteVertexesColor(color);
        }
コード例 #3
0
ファイル: MathHelper.cs プロジェクト: nasa03/Altseed2-csharp
        /// <summary>
        /// 指定した頂点を全て含む長方形のうち左上と右下の座標を割り出します。
        /// </summary>
        /// <param name="min">左上の座標</param>
        /// <param name="max">右下の座標</param>
        /// <param name="positions">計算する座標</param>
        /// <exception cref="ArgumentNullException"><paramref name="positions"/>がnull</exception>
        internal static void GetMinMax(out Vector2F min, out Vector2F max, Vector2FArray positions)
        {
            var min_x = float.MaxValue;
            var min_y = float.MaxValue;
            var max_x = float.MinValue;
            var max_y = float.MinValue;

            if (positions == null)
            {
                throw new ArgumentNullException(nameof(positions), "引数がnullです");
            }
            var count = positions.Count;

            if (count == 0)
            {
                min = max = default;
                return;
            }
            for (int i = 0; i < count; i++)
            {
                var current = positions[i];
                if (min_x > current.X)
                {
                    min_x = current.X;
                }
                if (min_y > current.Y)
                {
                    min_y = current.Y;
                }
                if (max_x < current.X)
                {
                    max_x = current.X;
                }
                if (max_y < current.Y)
                {
                    max_y = current.Y;
                }
            }
            min = new Vector2F(min_x, min_y);
            max = new Vector2F(max_x, max_y);
        }