public CrossCursor(SimpleShader simpleShader) : base(simpleShader) { InstasingList.Add(new VisualUniforms(Color.Black)); int count = 4; for (int i = 0; i < count; ++i) { double arg = Math.PI * 2 * (i + 0.5) / count; float cos = (float)Math.Cos(arg) * Delta / 2; float sin = (float)Math.Sin(arg) * Delta / 2; _verticesDefaultCursor.AddRange(Line(cos, sin, 0, 0, 2)); } _verticesWireCursor.AddRange(new [] { new Vector2(0, 0), new Vector2(2, 0), new Vector2(0, 2), new Vector2(7, 5), new Vector2(5, 7), new Vector2(5, 7), new Vector2(6, 8), new Vector2(6, 8), new Vector2(8, 6), new Vector2(8, 10), new Vector2(10, 8), }); Shape = _verticesDefaultCursor.ToArray(); }
public Field(int width, int height, SimpleShader simpleShader) : base(simpleShader) { Width = width; Height = height; EmploymentMatrix = new EmploymentMatrix(Width, Height); List <Vector2> vertices = new List <Vector2>(); for (int i = 0; i <= Height; i += (int)Delta) { vertices.AddRange(Line(new Vector2(0, i), new Vector2(Width, i), 1f)); } for (int i = 0; i <= Width; i += (int)Delta) { vertices.AddRange(Line(new Vector2(i, 0), new Vector2(i, Height), 1f)); } Shape = vertices.ToArray(); InstasingList.Add(new VisualUniforms(Color.LightGray)); CrossCursor = new CrossCursor(simpleShader); SelectRectangle = new DrawingVisual(simpleShader); SelectRectangle.InstasingList.Add(new VisualUniforms(new Color4(0, 0, 0.5f, 0.2f))); SelectRectangle.IsVisible = false; Childrens.Add(SelectRectangle); }
public RadialMenu(Field field, SimpleShader simpleShader) : base(simpleShader) { Field = field; Scale = new Vector2(0, 0); RoundGrid = new DrawingVisual(SimpleShader); RoundGrid.InstasingList.Add(new VisualUniforms(Color4.Black)); var vertices = new List <Vector2>(); vertices.AddRange(Round(new Vector2(0, 0), RadiusMenu, 2, 120)); vertices.AddRange(Round(new Vector2(0, 0), RadiusHole, 2, 120)); for (double i = 0; i < Math.PI * 2; i += Math.PI * 2 / ItemsCount) { var arg = i + Math.PI / ItemsCount; float sin = (float)Math.Sin(arg); float cos = (float)Math.Cos(arg); vertices.AddRange(Line( new Vector2(cos, sin) * RadiusHole, new Vector2(cos, sin) * RadiusMenu, 2)); } RoundGrid.Shape = vertices.ToArray(); Childrens.Add(RoundGrid); Arrow = new DrawingVisual(SimpleShader); Arrow.InstasingList.Add(new VisualUniforms(Color4.Black)); ArrowUpdate(RadiusHole); Childrens.Add(Arrow); Sectors = new DrawingVisual[ItemsCount]; for (int i = 0; i < ItemsCount; i++) { Sectors[i] = new DrawingVisual(SimpleShader); Sectors[i].InstasingList.Add(new VisualUniforms(Color4.AliceBlue)); vertices = new List <Vector2>(); float arg = (float)(i * Math.PI * 2 / ItemsCount + Math.PI / ItemsCount); vertices.AddRange(Sector(new Vector2(0, 0), MiddleRadius, arg, arg + (float)Math.PI * 2 / ItemsCount, RadiusMenu - RadiusHole, 20)); Sectors[i].Shape = vertices.ToArray(); Childrens.Add(Sectors[i]); } CreateRegister(); CreateSummator(); CreateSplitter(); // Register = new StreamingRegister(simpleShader, Visuals); // Register.Delta = Delta; // Register.Position = Translate + new Vector2(0, MiddleRadius); }
public Connector(SimpleShader simpleShader, ConnectorOrientation orientation, ConnectorType type) : base(simpleShader) { Orientation = orientation; Type = type; InstasingList.Add(new VisualUniforms(Color4.Black)); var vertices = new List <Vector2>(); vertices.AddRange(Circle(new Vector2(0, 0), 3, 12)); vertices.AddRange(Line(new Vector2(0, 0), new Vector2(Delta, 0), 2)); switch (Type) { case ConnectorType.Input: vertices.AddRange(Polyline(new[] { new Vector2(Delta / 2, Delta * 0.3f), new Vector2(Delta * 0.9f, 0), new Vector2(Delta / 2, -Delta * 0.3f), }, 2)); break; case ConnectorType.Output: vertices.AddRange(Polyline(new[] { new Vector2(Delta / 2, Delta * 0.3f), new Vector2(Delta * 0.1f, 0), new Vector2(Delta / 2, -Delta * 0.3f), }, 2)); break; } Shape = vertices.ToArray(); switch (Orientation) { case ConnectorOrientation.Left: Rotate = (float)0; break; case ConnectorOrientation.Top: Rotate = (float)Math.PI * 3 / 2; break; case ConnectorOrientation.Right: Rotate = (float)Math.PI; break; case ConnectorOrientation.Bottom: Rotate = (float)Math.PI / 2; break; } }
public TestVisualObject(SimpleShader simpleShader, Color4 color) : base(color) { SimpleShader = simpleShader; vId = GL.GenBuffer(); vao = GL.GenVertexArray(); GL.BindVertexArray(vao); GL.UseProgram(SimpleShader.ProgramId); var vertexPos = SimpleShader.GetAttribLocation("position"); GL.BindBuffer(BufferTarget.ArrayBuffer, vId); GL.VertexAttribPointer(vertexPos, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, IntPtr.Zero); GL.EnableVertexAttribArray(vertexPos); }
public DrawingVisual(SimpleShader simpleShader) { SimpleShader = simpleShader; InstasingList.CollectionChanged += (s, e) => { if (e.NewItems == null) { return; } foreach (VisualUniforms visualUniformse in e.NewItems) { visualUniformse.ParentModelMatrix = _modelMatrix; } }; Childrens.CollectionChanged += (s, e) => { if (e.NewItems == null) { return; } foreach (DrawingVisual drawingVisual in e.NewItems) { drawingVisual.ParentModelMatrix = _modelMatrix; } }; vId = GL.GenBuffer(); vao = GL.GenVertexArray(); GL.BindVertexArray(vao); GL.UseProgram(SimpleShader.ProgramId); var vertexPos = SimpleShader.GetAttribLocation("position"); GL.BindBuffer(BufferTarget.ArrayBuffer, vId); GL.VertexAttribPointer(vertexPos, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, IntPtr.Zero); GL.EnableVertexAttribArray(vertexPos); }
public Glyph7x5(char symbol, Vector2 position, SimpleShader shader) : base(shader) { Char = symbol; Translate = position; Shape = GetFillRectangle(new Vector2(0, 0), PixelWidth, PixelHeight); }
public DigitalComponent(SimpleShader shader) : base(shader) { InstasingList.Add(new VisualUniforms(Color4.Black)); }
public InseparableCode(bool[] gx, SimpleShader simpleShader) : base(simpleShader) { // if (gx.Length != 4) throw new Exception("Неправильный размер массива"); int gCount = gx.Length; streamingSource = new StreamingSource(new[] { 0, 1, 1, 0 }, simpleShader) { Translate = new Vector2(Delta * 1, Delta * 11) }; #region Register int regCount = gx.Length - 1; Registers = new StreamingRegister[regCount]; for (int i = 0; i < regCount; i++) { Registers[i] = new StreamingRegister(simpleShader) { Translate = new Vector2(Delta * 8 + i * Delta * 8, Delta * 10) }; } #endregion #region Sumators int sumCount = gx.Count(x => x) - 1; Splitters = new StreamingSplitter[sumCount]; Splitters[0] = new StreamingSplitter(simpleShader) { Translate = new Vector2(Delta * 7, Delta * 11) }; Summators = new StreamingSummator[sumCount]; for (int i = 1, j = 0; i < gx.Length; i++) { if (!gx[i]) { continue; } Summators[j] = new StreamingSummator(simpleShader, 2) { Up = true, Translate = new Vector2(Delta * 5 + i * Delta * 8, Delta * 3) }; j++; if (j >= sumCount) { continue; } Splitters[j] = new StreamingSplitter(simpleShader) { Translate = new Vector2(Delta * 7 + i * Delta * 8, Delta * 11) }; ConnectWire(Splitters[j], 0, Summators[j - 1], 1); } for (int i = 0; i < sumCount - 1; i++) { ConnectWire(Summators[i], 0, Summators[i + 1], 0); } for (int i = 1, j = 0; i < gx.Length - 1; i++) { if (!gx[i]) { ConnectWire(Registers[i - 1], 0, Registers[i], 0); } else { j++; ConnectWire(Registers[i - 1], 0, Splitters[j], 0); ConnectWire(Splitters[j], 1, Registers[i], 0); } } #endregion streamingReceiver = new StreamingReceiver(simpleShader) { Translate = new Vector2(Delta * 2 + Delta * gx.Length * 8, Delta * 5) }; ConnectWire(streamingSource, 0, Splitters[0], 0); ConnectWire(Splitters[0], 0, Summators[0], 0, new[] { new Vector2(Delta * 7, Delta * 5) }); ConnectWire(Splitters[0], 1, Registers[0], 0); ConnectWire(Registers.Last(), 0, Summators.Last(), 1, new[] { new Vector2(Delta * gx.Length * 8 - Delta * 1, Delta * 11) }); ConnectWire(Summators.Last(), 0, streamingReceiver, 0); foreach (var reg in Registers) { Childrens.Add(reg); } foreach (var spl in Splitters) { Childrens.Add(spl); } foreach (var summ in Summators) { Childrens.Add(summ); } Childrens.Add(streamingSource); Childrens.Add(streamingReceiver); ButtonTickZero = new Button(Delta, simpleShader) { Translate = new Vector2(Delta * 4, Delta * 10) }; Childrens.Add(ButtonTickZero); TestBit = new Glyph7x5('0', new Vector2(Delta * 3, Delta * 3), simpleShader); Childrens.Add(TestBit); ButtonTickZero.Click += (s, e) => { TestBit.Char = TestBit.Char == '0' ? '=' : '0'; }; ButtonTickOne = new Button(Delta, simpleShader) { Translate = new Vector2(Delta * 2, Delta * 10) }; Childrens.Add(ButtonTickOne); ButtonTickOne.Click += (s, e) => { streamingSource.Start(); }; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); SimpleShader = new SimpleShader("Shaders\\SimpleVertexShader.glsl", "Shaders\\SimpleFragmentShader.glsl"); TextureShader = new TextureShader("Shaders\\TexturedVertexShader.glsl", "Shaders\\TexturedFragmentShader.glsl"); TextureShader.UniformSampler2D.Value = 0; MyTexture2D = new Texture2D(); MyTexture2D.Generate(new Bitmap("Resources\\bitmap.png")); var spriteRenderer = new SpriteRenderer(); Random r = new Random(); for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { var mySprite = new SpriteRegister(MyTexture2D, spriteRenderer, TextureShader); mySprite.Position = new Vector2(50 * i, 50 * j); mySprite.UpdateModelMatrix(); mySprite.Color = new Color4((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble(), 1f); MySprites.Add(mySprite); } } InseparableCode = new InseparableCode(new[] { true, true, true, false, true }, SimpleShader); //LinearMachine =new MatrixToVisual(new[,] //{ // {true, true, true, }, // {true, true, true,}, // {false, true, true, }, // {true, true, false, }, // {true, true, true, } //}, SimpleShader); //menu = new RadialMenu(SimpleShader); Field = new Field(Width, Height, SimpleShader); menu = new RadialMenu(Field, SimpleShader); var delta = 10; GL.ClearColor(Color.Beige); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.AlphaTest); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // GL.PointSize(2); SimpleShader.UniformModelMatrix.Value = new Matrix3x2(1, 0, 0, 1, 0, 0); Vector2 coordMouseDown = new Vector2(0, 0); bool mouseScrollClicked = false; Vector2 oldTranslate = Translate; MouseDown += (s, a) => { Vector2 mousePos = PointToMouseCoord(a.Position); Vector2 mouseFieldPos = PositionToFieldCoord(mousePos); if (a.Button == MouseButton.Middle) { coordMouseDown = mousePos; mouseScrollClicked = true; oldTranslate = Translate; } if (a.Button == MouseButton.Left) { InseparableCode.MouseDown(mouseFieldPos); Field.MouseDown(mouseFieldPos); } if (a.Button == MouseButton.Right) { menu.Translate = mouseFieldPos; menu.Visible = true; } }; MouseMove += (s, a) => { Vector2 mousePos = PointToMouseCoord(a.Position); Vector2 mouseFieldPos = PositionToFieldCoord(mousePos); if (mouseScrollClicked) { Translate = oldTranslate + coordMouseDown - mousePos; } InseparableCode.MouseMove(mouseFieldPos); Field.MouseMove(mouseFieldPos); if (menu.Visible) { menu.MouseMove(mouseFieldPos); } }; MouseUp += (s, a) => { Vector2 mousePos = PointToMouseCoord(a.Position); Vector2 mouseFieldPos = PositionToFieldCoord(mousePos); if (a.Button == MouseButton.Left) { Field.MouseUp(mouseFieldPos); } if (a.Button == MouseButton.Middle) { mouseScrollClicked = false; } if (a.Button == MouseButton.Right) { menu.MouseUp(mouseFieldPos); menu.Visible = false; } }; MouseWheel += (s, a) => { Vector2 mousePos = new Vector2(a.Position.X, Height - a.Position.Y); var max = 4.0f; var min = 0.25f; float newScale = Scale + 0.25f * a.Delta / 2; if (newScale > max) { newScale = max; } if (newScale < min) { newScale = min; } var newTranslate = (mousePos + Translate) * newScale / Scale - mousePos; Translate = new Vector2((int)newTranslate.X, (int)newTranslate.Y); Scale = newScale; //this.Animation("Scale", newScale, 100); }; KeyDown += (s, a) => { if (a.Key == Key.Space) { Field.KeyPressSpace(); } else if (a.Key == Key.Delete || a.Key == Key.BackSpace) { Field.KeyDownRemove(); } }; Timer timer = new Timer(1000); timer.Elapsed += (s, a) => { Console.WriteLine($"FPS: {RenderFrequency:F2}, grad = {grad:F2}"); }; timer.AutoReset = true; //timer.Start(); }
public MatrixToVisual(bool[,] matrix, SimpleShader simpleShader) { Matrix = matrix; int icount = matrix.GetLength(0); int jcount = matrix.GetLength(1); WiresInputs = new Wire[icount]; WiresOutputs = new Wire[jcount]; DigitalComponent[] logicalXors = new DigitalComponent[jcount]; InOutPins = new DrawingVisual(simpleShader); var delta = 10; var x0 = delta * 5; var y0 = delta * 5; var bigStep = delta * 4; var xRight = x0 + 60 * delta; var circleR = delta; var xLineLeft = x0 + circleR; InOutPins.Shape = Round(Vector2.Zero, circleR, 4.0f, 50); for (int i = 0; i < icount; i++) { WiresInputs[i] = new Wire(simpleShader); WiresInputs[i].Thickness = 2.0f; WiresInputs[i].PointRadius = 3.0f; } float xBase = xLineLeft; var pinsCounts = new int[jcount]; for (int i = 0; i < icount; i++) { for (int j = 0; j < jcount; j++) { if (matrix[i, j]) { pinsCounts[j]++; } } } for (int j = 0; j < jcount; j++) { float xorX = xBase + delta * pinsCounts[j] * 2 + delta; int pinNum = 0; logicalXors[j] = new DigitalComponent(simpleShader); var rectHalfHeight = pinsCounts[j] * delta; //logicalXors[j].X = xorX; logicalXors[j].Delta = delta; logicalXors[j].PinsCount = pinsCounts[j]; logicalXors[j].CreateBuffer(); xBase = xorX + logicalXors[j].Width; WiresOutputs[j] = new Wire(simpleShader); WiresOutputs[j].Color = Color4.Red; WiresOutputs[j].Thickness = 2.0f; WiresOutputs[j].PointRadius = 3.0f; // WiresOutputs[j].AddLine(lineV1, lineV2); // WiresOutputs[j].AddPoint(pointOutPin, circleR - 4); WiresOutputs[j].CreateBuffer(); } xBase += delta * 2; for (int i = 0; i < icount; i++) { var y = y0 + (icount - i - 1 + jcount) * bigStep; WiresInputs[i].AddLine(new Vector2(xLineLeft, y), new Vector2(xBase, y)); WiresInputs[i].AddPoint(new Vector2(x0, y), circleR - 4); WiresInputs[i].AddPoint(new Vector2(xBase + circleR, y), circleR - 4); InOutPins.InstasingList.Add( new VisualUniforms(Color.Black) { Translate = new Vector2(x0, y) } ); } for (int i = 0; i < matrix.GetLength(1) + matrix.GetLength(0); i++) { var y = y0 + (icount - i - 1 + jcount) * bigStep; // vertices.AddRange(Round(new Vector2(xRight+circleR, y), circleR, 2.0f, 50, 0.1f)); InOutPins.InstasingList.Add( new VisualUniforms(Color.Black) { Translate = new Vector2(xBase + circleR, y) } ); } for (int i = 0; i < icount; i++) { WiresInputs[i].CreateBuffer(); } Visuals.AddRange(WiresInputs); Visuals.AddRange(WiresOutputs); Visuals.AddRange(logicalXors); Visuals.Add(InOutPins); }
public Wire(SimpleShader shader) : base(shader) { InstasingList.Add(new VisualUniforms(ZeroColor4)); }
public Button(float radius, SimpleShader simpleShader) : base(simpleShader) { Radius = radius; InstasingList.Add(new VisualUniforms(DefaultColor4)); Shape = Circle(new Vector2(0, 0), radius, 60); }