コード例 #1
0
ファイル: Editor2D.cs プロジェクト: mattbettcher/kbPCB
        private void CreateGate()
        {
            // not gate
            var trianglePath = new Path2F
            {
                new PathKey2F
                {
                    Parameter     = 0,
                    Interpolation = SplineInterpolation.Linear,
                    Point         = new Vector2F(1, 0),
                },
                new PathKey2F
                {
                    Parameter     = 1,
                    Interpolation = SplineInterpolation.Linear,
                    Point         = new Vector2F(-0.25f, 0.5f),
                },
                new PathKey2F
                {
                    Parameter     = 2,
                    Interpolation = SplineInterpolation.Linear,
                    Point         = new Vector2F(-0.25f, -0.5f),
                },
                new PathKey2F
                {
                    Parameter     = 3,
                    Interpolation = SplineInterpolation.Linear,
                    Point         = new Vector2F(1, 0),
                }
            };

            var triangle = new PathFigure2F();

            triangle.Segments.Add(trianglePath);
            var outPinFigure = new PathFigure2F
            {
                Segments =
                {
                    new LineSegment2F()
                    {
                        Point1 = new Vector2F(1, 0), Point2 = new Vector2F(1.2f, 0)
                    }
                }
            };

            // Add figure to the scene.
            var notGateNode = new FigureNode(triangle)
            {
                Name            = "Not Gate",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(1, 0.2f, 0.2f),
                FillColor       = new Vector3F(1, 0.5f, 0.5f),
                FillAlpha       = 0.5f,
                PoseLocal       = new Pose(new Vector3F(0, 0, 0)),
                ScaleLocal      = new Vector3F(1),
                Children        = new SceneNodeCollection(3),
            };

            var pinFigure = new PathFigure2F
            {
                Segments =
                {
                    new LineSegment2F {
                        Point1 = new Vector2F(0, 0), Point2 = new Vector2F(0.2f, 0)
                    }
                }
            };
            var pinsFigure = new CompositeFigure();

            var output = new TransformedFigure(pinFigure)
            {
                Pose = new Pose(new Vector3F(1.0f, 0, 0))
            };

            pinsFigure.Children.Add(output);

            var ina = new TransformedFigure(pinFigure)
            {
                Pose = new Pose(new Vector3F(-0.25f - 0.2f, -0.25f, 0))
            };

            pinsFigure.Children.Add(ina);

            var inb = new TransformedFigure(pinFigure)
            {
                Pose = new Pose(new Vector3F(-0.25f - 0.2f, 0.25f, 0))
            };

            pinsFigure.Children.Add(inb);

            notGateNode.Children.Add(new FigureNode(pinsFigure)
            {
                Name            = "Pins",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(0, 0, 0),
                PoseLocal       = new Pose(new Vector3F(0, 0, 0)),
                ScaleLocal      = new Vector3F(1f),
            });


            Scene.Children.Add(notGateNode);
        }
コード例 #2
0
        // Add a flower shape.
        private void CreateFlower()
        {
            // Define single flower petal.
            var petalPath = new Path2F
            {
                new PathKey2F
                {
                    Parameter     = 0,
                    Interpolation = SplineInterpolation.Bezier,
                    Point         = new Vector2F(0, 0),
                    TangentIn     = new Vector2F(0, 0),
                    TangentOut    = new Vector2F(-0.2f, 0.2f)
                },
                new PathKey2F
                {
                    Parameter     = 1,
                    Interpolation = SplineInterpolation.Bezier,
                    Point         = new Vector2F(0, 1),
                    TangentIn     = new Vector2F(-0.3f, 1.1f),
                    TangentOut    = new Vector2F(0.3f, 1.1f)
                },
                new PathKey2F
                {
                    Parameter     = 2,
                    Interpolation = SplineInterpolation.Bezier,
                    Point         = new Vector2F(0, 0),
                    TangentIn     = new Vector2F(0.2f, 0.2f),
                    TangentOut    = new Vector2F(0, 0)
                }
            };

            var petal = new PathFigure2F();

            petal.Segments.Add(petalPath);

            // Duplicate and rotate flower petal several times.
            const int numberOfPetals = 9;
            var       flower         = new CompositeFigure();

            flower.Children.Add(petal);
            for (int i = 1; i < numberOfPetals; i++)
            {
                var transformedPetal = new TransformedFigure(petal)
                {
                    Pose = new Pose(Matrix33F.CreateRotationZ(i * ConstantsF.TwoPi / numberOfPetals))
                };
                flower.Children.Add(transformedPetal);
            }

            var flowerNode = new FigureNode(flower)
            {
                Name            = "Flower",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(1, 0.2f, 0.2f),
                FillColor       = new Vector3F(1, 0.5f, 0.5f),
                FillAlpha       = 1,
                PoseLocal       = new Pose(new Vector3F(3, 1, 0)),
                ScaleLocal      = new Vector3F(0.5f)
            };

            _scene.Children.Add(flowerNode);
        }
コード例 #3
0
ファイル: Editor2D.cs プロジェクト: mattbettcher/kbPCB
        // TODO(matt) - grid creation needs to be able to be customized and should also be to a specific scale
        // TODO(matt) - should also have an intuitive control panel with presets and real time feedback
        // Add a grid with thick major grid lines and thin stroked minor grid lines.
        private void CreateGrid()
        {
            var majorGridLines = new PathFigure2F();

            for (int i = 0; i <= 100; i++)
            {
                majorGridLines.Segments.Add(new LineSegment2F
                {
                    Point1 = new Vector2F(-50, -50 + i),
                    Point2 = new Vector2F(50, -50 + i),
                });
                majorGridLines.Segments.Add(new LineSegment2F
                {
                    Point1 = new Vector2F(-50 + i, -50),
                    Point2 = new Vector2F(-50 + i, 50),
                });
            }

            var minorGridLines = new PathFigure2F();

            for (int i = 0; i < 100; i++)
            {
                minorGridLines.Segments.Add(new LineSegment2F
                {
                    Point1 = new Vector2F(-50, -40.5f + i),
                    Point2 = new Vector2F(50, -40.5f + i),
                });
                minorGridLines.Segments.Add(new LineSegment2F
                {
                    Point1 = new Vector2F(-40.5f + i, -50),
                    Point2 = new Vector2F(-40.5f + i, 50),
                });
            }

            var majorLinesNode = new FigureNode(majorGridLines)
            {
                Name            = "Major grid lines",
                PoseLocal       = Pose.Identity,
                StrokeThickness = 1,
                StrokeColor     = new Vector3F(0.1f),
                StrokeAlpha     = 1f,
            };
            var minorLinesNode = new FigureNode(minorGridLines)
            {
                Name            = "Minor grid lines",
                PoseLocal       = Pose.Identity,
                StrokeThickness = 0.5f,
                StrokeColor     = new Vector3F(0.1f),
                StrokeAlpha     = 1f,
                //DashInWorldSpace = true,
                //StrokeDashPattern = new Vector4F(10, 4, 0, 0) / 200,
            };
            var gridNode = new SceneNode
            {
                Name      = "Grid",
                Children  = new SceneNodeCollection(),
                PoseLocal = new Pose(new Vector3F(0, -0.5f, 0)),
            };

            gridNode.Children.Add(majorLinesNode);
            gridNode.Children.Add(minorLinesNode);
            Scene.Children.Add(gridNode);
        }
コード例 #4
0
        // Add a 3D coordinate cross.
        private void CreateGizmo(SpriteFont spriteFont)
        {
            var gizmoNode = new SceneNode
            {
                Name       = "Gizmo",
                Children   = new SceneNodeCollection(),
                PoseLocal  = new Pose(new Vector3F(3, 2, 0)),
                ScaleLocal = new Vector3F(0.5f)
            };

            // Red arrow
            var arrow = new PathFigure2F();

            arrow.Segments.Add(new LineSegment2F {
                Point1 = new Vector2F(0, 0), Point2 = new Vector2F(1, 0)
            });
            arrow.Segments.Add(new LineSegment2F {
                Point1 = new Vector2F(1, 0), Point2 = new Vector2F(0.9f, 0.02f)
            });
            arrow.Segments.Add(new LineSegment2F {
                Point1 = new Vector2F(1, 0), Point2 = new Vector2F(0.9f, -0.02f)
            });
            var figureNode = new FigureNode(arrow)
            {
                Name            = "Gizmo X",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(1, 0, 0),
                PoseLocal       = new Pose(new Vector3F(0, 0, 0))
            };

            gizmoNode.Children.Add(figureNode);

            // Green arrow
            var transformedArrow = new TransformedFigure(arrow)
            {
                Pose = new Pose(Matrix33F.CreateRotationZ(MathHelper.ToRadians(90)))
            };

            figureNode = new FigureNode(transformedArrow)
            {
                Name            = "Gizmo Y",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(0, 1, 0),
                PoseLocal       = new Pose(new Vector3F(0, 0, 0))
            };
            gizmoNode.Children.Add(figureNode);

            // Blue arrow
            transformedArrow = new TransformedFigure(arrow)
            {
                Pose = new Pose(Matrix33F.CreateRotationY(MathHelper.ToRadians(-90)))
            };
            figureNode = new FigureNode(transformedArrow)
            {
                Name            = "Gizmo Z",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(0, 0, 1),
                PoseLocal       = new Pose(new Vector3F(0, 0, 0))
            };
            gizmoNode.Children.Add(figureNode);

            // Red arc
            var arc = new PathFigure2F();

            arc.Segments.Add(
                new StrokedSegment2F(
                    new LineSegment2F {
                Point1 = new Vector2F(0, 0), Point2 = new Vector2F(1, 0),
            },
                    false));
            arc.Segments.Add(
                new ArcSegment2F
            {
                Point1 = new Vector2F(1, 0),
                Point2 = new Vector2F(0, 1),
                Radius = new Vector2F(1, 1)
            });
            arc.Segments.Add(
                new StrokedSegment2F(
                    new LineSegment2F {
                Point1 = new Vector2F(0, 1), Point2 = new Vector2F(0, 0),
            },
                    false));
            var transformedArc = new TransformedFigure(arc)
            {
                Scale = new Vector3F(0.333f),
                Pose  = new Pose(Matrix33F.CreateRotationY(MathHelper.ToRadians(-90)))
            };

            figureNode = new FigureNode(transformedArc)
            {
                Name            = "Gizmo YZ",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(1, 0, 0),
                FillColor       = new Vector3F(1, 0, 0),
                FillAlpha       = 0.5f,
                PoseLocal       = new Pose(new Vector3F(0, 0, 0))
            };
            gizmoNode.Children.Add(figureNode);

            // Green arc
            transformedArc = new TransformedFigure(arc)
            {
                Scale = new Vector3F(0.333f),
                Pose  = new Pose(Matrix33F.CreateRotationX(MathHelper.ToRadians(90)))
            };
            figureNode = new FigureNode(transformedArc)
            {
                Name            = "Gizmo XZ",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(0, 1, 0),
                FillColor       = new Vector3F(0, 1, 0),
                FillAlpha       = 0.5f,
                PoseLocal       = new Pose(new Vector3F(0, 0, 0))
            };
            gizmoNode.Children.Add(figureNode);

            // Blue arc
            transformedArc = new TransformedFigure(arc)
            {
                Scale = new Vector3F(0.333f),
            };
            figureNode = new FigureNode(transformedArc)
            {
                Name            = "Gizmo XY",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(0, 0, 1),
                FillColor       = new Vector3F(0, 0, 1),
                FillAlpha       = 0.5f,
                PoseLocal       = new Pose(new Vector3F(0, 0, 0))
            };
            gizmoNode.Children.Add(figureNode);

            // Labels "X", "Y", "Z"
            var spriteNode = new SpriteNode(new TextSprite("X", spriteFont))
            {
                Color     = new Vector3F(1, 0, 0),
                Origin    = new Vector2F(0, 1),
                PoseLocal = new Pose(new Vector3F(1, 0, 0))
            };

            gizmoNode.Children.Add(spriteNode);
            spriteNode = new SpriteNode(new TextSprite("Y", spriteFont))
            {
                Color     = new Vector3F(0, 1, 0),
                Origin    = new Vector2F(0, 1),
                PoseLocal = new Pose(new Vector3F(0, 1, 0))
            };
            gizmoNode.Children.Add(spriteNode);
            spriteNode = new SpriteNode(new TextSprite("Z", spriteFont))
            {
                Color     = new Vector3F(0, 0, 1),
                Origin    = new Vector2F(0, 1),
                PoseLocal = new Pose(new Vector3F(0, 0, 1))
            };
            gizmoNode.Children.Add(spriteNode);

            _scene.Children.Add(gizmoNode);
        }