Exemplo n.º 1
0
        private void UpdateSizeBox()
        {
            var points = new Vector2F[4];

            var origin = -_TransformNode.CenterPosition * _TransformNode.Scale;

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

            var mat = _TransformNode.GetAncestorSpecificNode <TransformNode>()?.InheritedTransform ?? Matrix44F.Identity;

            mat = mat * Matrix44F.GetTranslation2D(_TransformNode.Position) * Matrix44F.GetRotationZ(MathHelper.DegreeToRadian(_TransformNode.Angle));
            for (int i = 0; i < points.Length; i++)
            {
                var vector = mat.Transform3D(new Vector3F(points[i].X, points[i].Y, 0));
                points[i] = new Vector2F(vector.X, vector.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));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Transformを計算します。
        /// </summary>
        /// <param name="position">座標</param>
        /// <param name="angle">角度(弧度法)</param>
        /// <param name="scale">拡大率</param>
        /// <returns></returns>
        internal static Matrix44F CalcTransform(Vector2F position, float angle, Vector2F scale)
        {
            var matPosition = Matrix44F.GetTranslation2D(position);
            var matRotate   = Matrix44F.GetRotationZ(angle);
            var matScale    = Matrix44F.GetScale2D(scale);

            return(matPosition * matRotate * matScale);
            // NOTE: 一気に計算したほうがよさそう
        }
        private void UpdateSizeBox()
        {
            var points = new Vector2F[4];

            var offset
                = ((AnchorTransformerNode.Parent?.GetAncestorSpecificNode <TransformNode>()?.Transfomer as AnchorTransformerNode)?.Size ?? default) * AnchorTransformerNode.AnchorMin;
            var origin = -AnchorTransformerNode.CenterPosition;

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

            var mat = AnchorTransformerNode.Parent.GetAncestorSpecificNode <TransformNode>()?.InheritedTransform ?? Matrix44F.Identity;

            mat = mat * Matrix44F.GetTranslation2D(offset + AnchorTransformerNode.Position) * Matrix44F.GetRotationZ(MathHelper.DegreeToRadian(AnchorTransformerNode.Angle));
            for (int i = 0; i < points.Length; i++)
            {
                var vector = mat.Transform3D(new Vector3F(points[i].X, points[i].Y, 0));
                points[i] = new Vector2F(vector.X, vector.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 UpdateAnchor()
        {
            var points = new Vector2F[2];

            var offset
                = ((AnchorTransformerNode.Parent?.GetAncestorSpecificNode <TransformNode>()?.Transfomer as AnchorTransformerNode)?.Size ?? default) * AnchorTransformerNode.AnchorMin;

            points[0] = -AnchorTransformerNode.Position;
            points[1] = AnchorTransformerNode.Size * (new Vector2F(1, 1) - AnchorTransformerNode.Pivot) + AnchorTransformerNode.RightBottom;

            var mat = AnchorTransformerNode.Parent.GetAncestorSpecificNode <TransformNode>()?.InheritedTransform ?? Matrix44F.Identity;

            mat = mat * Matrix44F.GetTranslation2D(offset + AnchorTransformerNode.Position) * Matrix44F.GetRotationZ(MathHelper.DegreeToRadian(AnchorTransformerNode.Angle));

            var horizon  = new Vector2F(-8, 0);
            var vertical = new Vector2F(0, -8);

            for (int i = 0; i < points.Length; i++)
            {
                var point1 = points[i] + horizon * MathF.Pow(-1, i);
                var point2 = points[i] + vertical * MathF.Pow(-1, i);

                var vector = mat.Transform3D(new Vector3F(points[i].X, points[i].Y, 0));
                points[i] = new Vector2F(vector.X, vector.Y);

                vector = mat.Transform3D(new Vector3F(point1.X, point1.Y, 0));
                point1 = new Vector2F(vector.X, vector.Y);

                vector = mat.Transform3D(new Vector3F(point2.X, point2.Y, 0));
                point2 = new Vector2F(vector.X, vector.Y);

                SetLine(_AnchorLines[i * 2], points[i], point1, new Color(255, 255, 255));
                SetLine(_AnchorLines[i * 2 + 1], points[i], point2, new Color(255, 255, 255));
            }
        }