Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
    }
Exemplo n.º 3
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);
    }
Exemplo n.º 4
0
    // Add a chain-like figure using TransformedFigure and CompositeFigure.
    private void CreateChain()
    {
      var ellipse = new EllipseFigure
      {
        IsFilled = false,
        RadiusX = 1f,
        RadiusY = 1f,
      };

      var compositeFigure = new CompositeFigure();
      for (int i = 0; i < 9; i++)
      {
        var transformedEllipse = new TransformedFigure(ellipse)
        {
          Scale = new Vector3F(0.4f, 0.2f, 1),
          Pose = new Pose(new Vector3F(-2 + i * 0.5f, 0, 0), Matrix33F.CreateRotationX(ConstantsF.PiOver2 * (i % 2)))
        };
        compositeFigure.Children.Add(transformedEllipse);
      }

      _scene.Children.Add(new FigureNode(compositeFigure)
      {
        Name = "Chain",
        StrokeThickness = 2,
        StrokeColor = new Vector3F(0.1f),
        StrokeAlpha = 1,
        PoseLocal = new Pose(new Vector3F(0, 3, 0)),
      });
    }