Пример #1
0
        // 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);
        } 
Пример #2
0
        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);
        }
Пример #3
0
    // Add some rectangles.
    private void CreateRectangles()
    {
      Figure figure = new RectangleFigure
      {
        IsFilled = false,
        WidthX = 1f,
        WidthY = 0.5f,
      };
      FigureNode figureNode = new FigureNode(figure)
      {
        Name = "Rectangle #1",
        StrokeThickness = 1,
        StrokeColor = new Vector3F(0.7f, 0.3f, 0.5f),
        StrokeAlpha = 1,
        PoseLocal = new Pose(new Vector3F(-2, 1, 0))
      };
      _scene.Children.Add(figureNode);

      figure = new RectangleFigure
      {
        IsFilled = false,
        WidthX = 0.5f,
        WidthY = 0.8f,
      };
      figureNode = new FigureNode(figure)
      {
        Name = "Rectangle #2",
        StrokeThickness = 3,
        StrokeColor = new Vector3F(0.2f, 0.3f, 0.3f),
        StrokeAlpha = 0.5f,
        StrokeDashPattern = new Vector4F(10, 2, 3, 2),
        DashInWorldSpace = false,
        PoseLocal = new Pose(new Vector3F(-1, 1, 0))
      };
      _scene.Children.Add(figureNode);

      figure = new RectangleFigure
      {
        IsFilled = true,
        WidthX = 0.6f,
        WidthY = 0.7f,
      };
      figureNode = new FigureNode(figure)
      {
        Name = "Rectangle #3",
        StrokeThickness = 2,
        StrokeColor = new Vector3F(0.3f, 0, 0.2f),
        StrokeAlpha = 1,
        StrokeDashPattern = new Vector4F(10, 2, 3, 2) / 100,
        DashInWorldSpace = true,
        FillColor = new Vector3F(0.7f, 0, 0.5f),
        FillAlpha = 0.5f,
        PoseLocal = new Pose(new Vector3F(-0, 1, 0))
      };
      _scene.Children.Add(figureNode);

      figure = new RectangleFigure
      {
        IsFilled = true,
        WidthX = 1f,
        WidthY = 0.2f,
      };
      figureNode = new FigureNode(figure)
      {
        Name = "Rectangle #4",
        StrokeThickness = 2,
        StrokeColor = new Vector3F(0, 0, 0),
        StrokeAlpha = 1,
        StrokeDashPattern = new Vector4F(1, 1, 1, 1) / 100,
        DashInWorldSpace = true,
        FillColor = new Vector3F(0.3f, 0.3f, 0.3f),
        FillAlpha = 0.5f,
        PoseLocal = new Pose(new Vector3F(1, 1, 0))
      };
      _scene.Children.Add(figureNode);

      figure = new RectangleFigure
      {
        IsFilled = true,
        WidthX = 0.4f,
        WidthY = 0.5f,
      };
      figureNode = new FigureNode(figure)
      {
        Name = "Rectangle #5",
        StrokeThickness = 2,
        StrokeColor = new Vector3F(0.3f),
        StrokeAlpha = 1,
        FillColor = new Vector3F(0.3f),
        FillAlpha = 1,
        PoseLocal = new Pose(new Vector3F(2, 1, 0))
      };
      _scene.Children.Add(figureNode);
    }
Пример #4
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);
    }
Пример #5
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);
    }
Пример #6
0
    // Add a random path.
    private void CreateRandomPath()
    {
      var path = new Path3F();
      var point = new Vector3F(0, 0, 0);
      path.Add(new PathKey3F
      {
        Interpolation = SplineInterpolation.CatmullRom,
        Parameter = 0,
        Point = point
      });
      for (int i = 1; i < 10; i++)
      {
        point += RandomHelper.Random.NextQuaternionF().Rotate(new Vector3F(0, 0.5f, 0));
        path.Add(new PathKey3F
        {
          Interpolation = SplineInterpolation.CatmullRom,
          Parameter = i,
          Point = point
        });
      }
      var pathFigure = new PathFigure3F();
      pathFigure.Segments.Add(path);

      var pathLineNode = new FigureNode(pathFigure)
      {
        Name = "RandomPath",
        PoseLocal = new Pose(new Vector3F(4, 1, 2)),
        StrokeThickness = 3,
        StrokeColor = new Vector3F(0.5f, 0.3f, 1),
        StrokeAlpha = 1f,
        DashInWorldSpace = true,
        StrokeDashPattern = new Vector4F(10, 1, 1, 1) / 100,
      };
      _scene.Children.Add(pathLineNode);
    }
Пример #7
0
    // Add some transparent figures to test alpha blending.
    private void CreateAlphaBlendedFigures()
    {
      var rectangle = new RectangleFigure
      {
        IsFilled = true,
        WidthX = 0.5f,
        WidthY = 0.9f,
      };

      var figureNode = new FigureNode(rectangle)
      {
        Name = "Rectangle #6",
        StrokeThickness = 2,
        StrokeColor = new Vector3F(0.1f, 0.2f, 0.3f),
        FillColor = new Vector3F(0.1f, 0.2f, 0.3f),
        StrokeAlpha = 0.5f,
        FillAlpha = 0.5f,
        PoseLocal = new Pose(new Vector3F(-4, 1, -2))
      };
      _scene.Children.Add(figureNode);

      figureNode = new FigureNode(rectangle)
      {
        Name = "Rectangle #7",
        StrokeThickness = 2,
        StrokeColor = new Vector3F(0.1f, 0.2f, 0.3f),
        FillColor = new Vector3F(0.1f, 0.2f, 0.3f),
        StrokeAlpha = 0.5f,
        FillAlpha = 0.5f,
        PoseLocal = new Pose(new Vector3F(-4, 1, -1))
      };
      _scene.Children.Add(figureNode);

      figureNode = new FigureNode(rectangle)
      {
        Name = "Rectangle #8",
        StrokeThickness = 2,
        StrokeColor = new Vector3F(0.1f, 0.2f, 0.3f),
        FillColor = new Vector3F(0.1f, 0.2f, 0.3f),
        StrokeAlpha = 0.5f,
        FillAlpha = 0.5f,
        PoseLocal = new Pose(new Vector3F(-4, 1, 0))
      };
      _scene.Children.Add(figureNode);

      figureNode = new FigureNode(rectangle)
      {
        Name = "Rectangle #9",
        StrokeThickness = 2,
        StrokeColor = new Vector3F(0.1f, 0.2f, 0.3f),
        FillColor = new Vector3F(0.1f, 0.2f, 0.3f),
        StrokeAlpha = 0.5f,
        FillAlpha = 0.5f,
        PoseLocal = new Pose(new Vector3F(-4, 1, 1))
      };
      _scene.Children.Add(figureNode);

      figureNode = new FigureNode(rectangle)
      {
        Name = "Rectangle #10",
        StrokeThickness = 2,
        StrokeColor = new Vector3F(0.1f, 0.2f, 0.3f),
        FillColor = new Vector3F(0.1f, 0.2f, 0.3f),
        StrokeAlpha = 0.5f,
        FillAlpha = 0.5f,
        PoseLocal = new Pose(new Vector3F(-4, 1, 2))
      };
      _scene.Children.Add(figureNode);
    }