Exemplo n.º 1
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                var outerDiameter = OuterDiameter.Value(this);
                var innerDiameter = InnerDiameter.ClampIfNotCalculated(this, 0, outerDiameter - .1, ref valuesChanged);
                var sides         = Sides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);
                var ringSides     = RingSides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);

                var startingAngle = StartingAngle.ClampIfNotCalculated(this, 0, 360 - .01, ref valuesChanged);
                var endingAngle   = EndingAngle.ClampIfNotCalculated(this, startingAngle + .01, 360, ref valuesChanged);

                var ringPhaseAngle = RingPhaseAngle.Value(this);
                if (!Advanced)
                {
                    ringSides      = Math.Max(3, (int)(sides / 2));
                    startingAngle  = 0;
                    endingAngle    = 360;
                    ringPhaseAngle = 0;
                }

                innerDiameter = Math.Min(outerDiameter - .1, innerDiameter);

                using (new CenterAndHeightMaintainer(this))
                {
                    var poleRadius     = (outerDiameter / 2 - innerDiameter / 2) / 2;
                    var toroidRadius   = innerDiameter / 2 + poleRadius;
                    var path           = new VertexStorage();
                    var angleDelta     = MathHelper.Tau / ringSides;
                    var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle);
                    var ringAngle      = ringStartAngle;
                    var circleCenter   = new Vector2(toroidRadius, 0);
                    path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
                    for (int i = 0; i < ringSides - 1; i++)
                    {
                        ringAngle += angleDelta;
                        path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle)));
                    }

                    path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));

                    var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                    var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                    Mesh = VertexSourceToMesh.Revolve(path, sides, startAngle, endAngle);
                }
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                var outerDiameter = OuterDiameter.Value(this);
                var innerDiameter = InnerDiameter.ClampIfNotCalculated(this, 0, outerDiameter - .1, ref valuesChanged);
                var sides         = Sides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);
                var startingAngle = StartingAngle.ClampIfNotCalculated(this, 0, 360 - .01, ref valuesChanged);
                var endingAngle   = EndingAngle.ClampIfNotCalculated(this, startingAngle + .01, 360, ref valuesChanged);
                var height        = Height.Value(this);

                using (new CenterAndHeightMaintainer(this))
                {
                    if (!Advanced)
                    {
                        startingAngle = 0;
                        endingAngle   = 360;
                    }

                    innerDiameter = Math.Min(outerDiameter - .1, innerDiameter);

                    var path = new VertexStorage();
                    path.MoveTo(outerDiameter / 2, -height / 2);
                    path.LineTo(outerDiameter / 2, height / 2);
                    path.LineTo(innerDiameter / 2, height / 2);
                    path.LineTo(innerDiameter / 2, -height / 2);
                    path.LineTo(outerDiameter / 2, -height / 2);

                    var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                    var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                    Mesh = VertexSourceToMesh.Revolve(path, sides, startAngle, endAngle);
                }
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 3
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                var outerDiameter = OuterDiameter.Value(this);
                var innerDiameter = InnerDiameter.ClampIfNotCalculated(this, 0, outerDiameter - .1, ref valuesChanged);
                var sides         = Sides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);
                var startingAngle = StartingAngle.ClampIfNotCalculated(this, 0, 360 - .01, ref valuesChanged);
                var endingAngle   = EndingAngle.ClampIfNotCalculated(this, startingAngle + .01, 360, ref valuesChanged);
                var height        = Height.Value(this);
                var roundSegments = RoundSegments.ClampIfNotCalculated(this, 2, 90, ref valuesChanged);

                using (new CenterAndHeightMaintainer(this, MaintainFlags.Origin | MaintainFlags.Bottom))
                {
                    if (!Advanced)
                    {
                        startingAngle = 0;
                        endingAngle   = 360;
                    }

                    innerDiameter = Math.Min(outerDiameter - .1, innerDiameter);

                    var path  = new VertexStorage();
                    var width = (outerDiameter - innerDiameter) / 2;
                    var r     = innerDiameter / 2;
                    path.MoveTo(r, 0);
                    path.LineTo(r + width, 0);
                    var range = 360 / 4.0;

                    if (!Advanced)
                    {
                        path.LineTo(r + width, height);
                        path.LineTo(r, height);
                    }
                    else
                    {
                        switch (Round)
                        {
                        case RoundTypes.None:
                            path.LineTo(r + width, height);
                            path.LineTo(r, height);
                            break;

                        case RoundTypes.Down:
                            if (Direction == RoundDirection.Inner)
                            {
                                path.LineTo(r + width, height);
                                for (int i = 1; i < roundSegments - 1; i++)
                                {
                                    var angle = range / (roundSegments - 1) * i;
                                    var rad   = MathHelper.DegreesToRadians(angle);
                                    path.LineTo(r + Math.Cos(rad) * width, height - Math.Sin(rad) * height);
                                }
                            }
                            else
                            {
                                for (int i = 1; i < roundSegments - 1; i++)
                                {
                                    var angle = range / (roundSegments - 1) * i;
                                    var rad   = MathHelper.DegreesToRadians(angle);
                                    path.LineTo(r + width - Math.Sin(rad) * width, height - Math.Cos(rad) * height);
                                }
                                path.LineTo(r, height);
                            }
                            break;

                        case RoundTypes.Up:
                            if (Direction == RoundDirection.Inner)
                            {
                                path.LineTo(r + width, height);
                                for (int i = 1; i < roundSegments - 1; i++)
                                {
                                    var angle = range / (roundSegments - 1) * i;
                                    var rad   = MathHelper.DegreesToRadians(angle);
                                    path.LineTo(r + width - Math.Sin(rad) * width, Math.Cos(rad) * height);
                                }
                            }
                            else
                            {
                                for (int i = 1; i < roundSegments - 1; i++)
                                {
                                    var angle = range / (roundSegments - 1) * i;
                                    var rad   = MathHelper.DegreesToRadians(angle);
                                    path.LineTo(r + Math.Cos(rad) * width, Math.Sin(rad) * height);
                                }
                                path.LineTo(r, height);
                            }
                            break;
                        }
                    }

                    var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                    var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                    Mesh = VertexSourceToMesh.Revolve(path, sides, startAngle, endAngle);
                }
            }

            Invalidate(InvalidateType.DisplayValues);

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }