public void Draw(VertexArray vertices, RenderStates states) { if (!drawing) return; // Render states have changed, so flush and clear. if (!CompareStates(renderStates, states)) { Flush(); vertexArray.Clear(); renderStates = states; } // Exceeding maximum sprites, so flush and clear. if (DrawCount >= MaxSprites) { Flush(); DrawCount = 0; vertexArray.Clear(); } // Apply the transform to the four points var transform = states.Transform; // Append the vertices for (uint i = 0; i < vertices.VertexCount; i++) { var vertex = vertices[i]; var pos = transform.TransformPoint(vertex.Position.X, vertex.Position.Y); vertex.Position.X = pos.X; vertex.Position.Y = pos.Y; vertexArray.Append(vertex); } DrawCount++; // I think that's it? }
public LineSegment(SFML.Window.Vector2f start, SFML.Window.Vector2f end, SFML.Graphics.Color color) { Start = start; End = end; linePoints = new VertexArray(PrimitiveType.Lines); linePoints.Append(new Vertex(start) { Color = color }); linePoints.Append(new Vertex(end) { Color = color }); }
public LineSegment(SFML.Window.Vector2f start, SFML.Window.Vector2f end) { Start = start; End = end; linePoints = new VertexArray(PrimitiveType.Lines); linePoints.Append(new Vertex(start)); linePoints.Append(new Vertex(end)); }
public DebugView(Game game, PhysicsManager physicsManager) { _game = game; _physicsManager = physicsManager; _triangleVertices = new VertexArray(PrimitiveType.Triangles); _lineVertices = new VertexArray(PrimitiveType.Lines); _staticColor = new Color(100, 150, 100); _dynamicColor = new Color(100, 100, 150); }
protected override void UpdateDrawable() { base.UpdateDrawable(); if (fill == 1) { //draw box SFMLVertices = new VertexArray(PrimitiveType.Quads); Append(SFMLVertices, 0, 0); Append(SFMLVertices, Width, 0); Append(SFMLVertices, Width, Height); Append(SFMLVertices, 0, Height); } else { SFMLVertices = new VertexArray(PrimitiveType.TrianglesFan); if (fill > 0) { //draw center Append(SFMLVertices, HalfWidth, HalfHeight); //draw middle top Append(SFMLVertices, HalfWidth, 0); if (fill >= 0.125f) { //draw left top Append(SFMLVertices, 0, 0); } if (fill >= 0.375f) { //draw left bottom Append(SFMLVertices, 0, Height); } if (fill >= 0.625f) { //draw right bottom Append(SFMLVertices, Width, Height); } if (fill >= 0.875f) { //draw right top Append(SFMLVertices, Width, 0); } // get vector of angle var v = new Vector2(Util.PolarX(FillAngle, HalfWidth), Util.PolarY(FillAngle, HalfHeight)); // adjust length of vector to meet square var l = (float)Math.Max(Math.Abs(v.X), Math.Abs(v.Y)); if (l <= HalfWidth) { v.X /= l; v.Y /= l; } // append the vector Append(SFMLVertices, HalfWidth + (float)v.X * HalfWidth, HalfHeight + (float)v.Y * HalfHeight); } } }
public void LoadContent() { //verts = new VertexTypeList.PositionDiffuse2DTexture1[4] // { // new VertexTypeList.PositionDiffuse2DTexture1(new Vector3(1, -1, 0), Color.Transparent, new Vector2(1, 1)), // new VertexTypeList.PositionDiffuse2DTexture1(new Vector3(-1, -1, 0), Color.Transparent,new Vector2(0, 1)), // new VertexTypeList.PositionDiffuse2DTexture1(new Vector3(-1, 1, 0), Color.Transparent, new Vector2(0, 0)), // new VertexTypeList.PositionDiffuse2DTexture1(new Vector3(1, 1, 0), Color.Transparent, new Vector2(1, 0)) // }; vertex = new VertexArray(PrimitiveType.Lines, 4); vertex[0] = new Vertex(new Vector2(1,-1), Color.Transparent.ToSFMLColor(),new Vector2(1,1)); vertex[1] = new Vertex(new Vector2(-1, -1), Color.Transparent.ToSFMLColor(), new Vector2(0, 1)); vertex[2] = new Vertex(new Vector2(-1, 1), Color.Transparent.ToSFMLColor(), new Vector2(0, 0)); vertex[3] = new Vertex(new Vector2(1, 1), Color.Transparent.ToSFMLColor(), new Vector2(1, 0)); }
public void Draw(RenderTarget target, RenderStates states) { VertexArray vertices = new VertexArray(PrimitiveType.Lines); for (int x = 0; x < viewSize.X; x += size) { vertices.Append(new Vertex(sim.Window.MapPixelToCoords(new Vector2i(x - viewOffset.X, 0)), color)); vertices.Append(new Vertex(sim.Window.MapPixelToCoords(new Vector2i(x - viewOffset.X, (int)viewSize.Y)), color)); } for (int y = 0; y < viewSize.Y; y += size) { vertices.Append(new Vertex(sim.Window.MapPixelToCoords(new Vector2i(0, y - viewOffset.Y)), color)); vertices.Append(new Vertex(sim.Window.MapPixelToCoords(new Vector2i((int)viewSize.X, y - viewOffset.Y)), color)); } vertices.Draw(target, states); }
public Tilemap(TextureAtlas atlas, int width, int height, float tileTextureDimension, float tileWorldDimension, Tile[,] tiles) { _atlas = atlas; _width = width; _height = height; _tileSize = tileTextureDimension; _cellSize = tileWorldDimension; Tiles = tiles; _vertexArray = new VertexArray(PrimitiveType.Quads, (uint)(width * height * 4)); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { AddTileVertices(tiles[x, y], new Vector2f(x, y)); } } }
protected override void UpdateDrawable() { base.UpdateDrawable(); Color nextColor = ColorA; Color rowColor = nextColor; SFMLVertices = new VertexArray(PrimitiveType.Quads); for (float j = 0; j < Height; j += GridHeight) { for (float i = 0; i < Width; i += GridWidth) { SFMLVertices.Append(new Vertex(new Vector2f(i, j), nextColor.SFMLColor)); SFMLVertices.Append(new Vertex(new Vector2f(i + GridWidth, j), nextColor.SFMLColor)); SFMLVertices.Append(new Vertex(new Vector2f(i + GridWidth, j + GridHeight), nextColor.SFMLColor)); SFMLVertices.Append(new Vertex(new Vector2f(i, j + GridHeight), nextColor.SFMLColor)); nextColor = nextColor == ColorA ? ColorB : ColorA; } rowColor = nextColor = rowColor == ColorA ? ColorB : ColorA; } }
public Tilemap(Texture tileset, int width, int height, float tileTextureDimension, float tileWorldDimension) { this.tileset = tileset; this.width = width; this.height = height; this.tileTextureDimension = tileTextureDimension; this.tileWorldDimension = tileWorldDimension; vertexArray = new VertexArray(PrimitiveType.Quads, (uint)(width * height * 4)); Tile tile = new Tile(1, 2, Color.White); for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { AddTileVertices(tile, new Vector2f((float)x, (float)y)); } } }
public void DrawSimpleLine(int x1, int y1, int x2, int y2, Color color = new Color()) { if (!ArePointsOnScreen(x1, y1, x2, y2)) { return; } var zoom = GetZoom(); int real_x1 = (int)(x1 * zoom); int real_x2 = (int)(x2 * zoom); int real_y1 = (int)(y1 * zoom); int real_y2 = (int)(y2 * zoom); SFML.Graphics.VertexArray line = new SFML.Graphics.VertexArray(); line.PrimitiveType = SFML.Graphics.PrimitiveType.Lines; line.Append(new Vertex(new SFML.System.Vector2f(real_x1, real_y1), new SFML.Graphics.Color(color.R, color.G, color.B, color.A))); line.Append(new Vertex(new SFML.System.Vector2f(real_x2, real_y2), new SFML.Graphics.Color(color.R, color.G, color.B, color.A))); RenderWindow.Draw(line); }
public VisbilityMap(Vector2f center, float radius) { _center = center; _radius = radius; _maxRayDistance = (float)Math.Sqrt(2 * (radius * radius)) + 0.5f; _segments = new List<Segment>(); _bounds = new List<Segment>(new Segment[4]); _visibleSegments = new List<Segment>(); _boundRect = new FloatRect(); _boundsNeedUpdate = true; ComputeBoundaries(); _visMesh = new VertexArray(PrimitiveType.TrianglesFan); _visMeshNeedsUpdate = true; }
void DebugDraw(RenderWindow win) { debugGraphic.FillColor = Color.Red; debugGraphic.Position = Position - ((Vector2)debugGraphic.Size / 2F); win.Draw(debugGraphic); foreach (Rune adjacentRune in AdjacentRunes) { //if (this.GetType() == adjacentRune.GetType()) { VertexArray line = new VertexArray(); line.Append(new Vertex(Position)); for (float t = 0F; t < 1F; t += 0.01F) { line.Append(new Vertex(Vector2.lerp(Position, adjacentRune.Position, t))); } line.Append(new Vertex(adjacentRune.Position)); win.Draw(line); } } }
protected SquareGridBase(Vector2i cellSize, Vector2i gridSize) { GridSize = gridSize; CellSize = cellSize; m_QuadArray = new VertexArray(PrimitiveType.Quads, (uint) (gridSize.X * gridSize.Y * 4)); m_LineArray = new VertexArray(PrimitiveType.Lines, (uint) (gridSize.X + gridSize.Y + 2) * 2); for (uint y = 0; y < gridSize.Y; y++) { for (uint x = 0; x < gridSize.X; x++) { var i = (uint) ((x + (y * gridSize.X)) * 4); var topLeft = new Vector2f(cellSize.X*x, cellSize.Y*y); var topRight = topLeft + new Vector2f(cellSize.X, 0); var bottomLeft = topLeft + new Vector2f(0, cellSize.Y); var bottomRight = topLeft + new Vector2f(cellSize.X, cellSize.Y); m_QuadArray[i] = new Vertex(topLeft, Color.Black); m_QuadArray[i + 1] = new Vertex(topRight, Color.Black); m_QuadArray[i + 2] = new Vertex(bottomRight, Color.Black); m_QuadArray[i + 3] = new Vertex(bottomLeft, Color.Black); } } for (uint x = 0; x <= gridSize.X; x++) { m_LineArray[x*2] = new Vertex(new Vector2f(x * cellSize.X, 0), Color.White); m_LineArray[(x*2) + 1] = new Vertex(new Vector2f(x * cellSize.X, cellSize.Y * gridSize.Y), Color.White); } var yOffset = (uint) ((gridSize.X + 1)*2); for (uint y = 0; y <= gridSize.Y; y++) { m_LineArray[yOffset + (y*2)] = new Vertex(new Vector2f(0, y * cellSize.Y), Color.White); m_LineArray[yOffset + (y*2) + 1] = new Vertex(new Vector2f(cellSize.X * gridSize.X, y * cellSize.Y), Color.White); } }
public override void Draw(RenderTarget target, RenderStates states) { var corners = game.WindowBounds.Corners().Concat(game.World.Objects.SelectMany(o => o.Bounds.Corners())); var edges = game.WindowBounds.Edges().Concat(game.World.Objects.SelectMany(o => o.Bounds.Edges())); //foreach (var edge in edges) // Debug.DrawLine(edge.start, edge.end); var hits = from c in corners let angle = Radians(c.Angle(Position)) let hit = Raycast(Position, c, edges) let left = Raycast(Position, angle - 0.0001f, 10000f, edges) let right = Raycast(Position, angle + 0.0001f, 10000f, edges) where hit.HasValue && left.HasValue && right.HasValue from h in new[] { new { Hit = hit, Angle = angle }, new { Hit = left, Angle = angle - 0.0001f }, new { Hit = right, Angle = angle + 0.0001f } } let a = NormalizeAngle(Position.Angle(h.Hit.Value.ClosestHit)) orderby h.Angle select h.Hit.Value.ClosestHit; //foreach (var hit in hits) //{ // Debug.DrawLine(Position, hit, Color.Red); // Debug.DrawCircle(hit, 5f, 8, Color.Red); //} var vertices = new VertexArray(PrimitiveType.Triangles); var center = new Vertex(Position, Color); foreach (var hit in hits.Pairs(Position)) vertices.Append(new Vertex(hit, Color)); target.Draw(vertices); }
public void DrawLine(RenderWindow win, Vector2 from, Vector2 to) { VertexArray line = new VertexArray(); for (float t = 0F; t < 1F; t += 0.01F) { line.Append(new Vertex(Vector2.lerp(from, to, t))); } line.Append(new Vertex(to)); win.Draw(line); }
internal void AppendVertices(VertexArray array) { if(!FlipX && !FlipY) { array.Append(CreateVertex(0, 0, 0, 0)); array.Append(CreateVertex(Width, 0, Width, 0)); array.Append(CreateVertex(Width, Height, Width, Height)); array.Append(CreateVertex(0, Height, 0, Height)); } if(FlipX && FlipY) { array.Append(CreateVertex(0, 0, Width, Height)); array.Append(CreateVertex(Width, 0, 0, Height)); array.Append(CreateVertex(Width, Height, 0, 0)); array.Append(CreateVertex(0, Height, Width, 0)); } if(FlipX & !FlipY) { array.Append(CreateVertex(0, 0, Width, 0)); array.Append(CreateVertex(Width, 0, 0, 0)); array.Append(CreateVertex(Width, Height, 0, Height)); array.Append(CreateVertex(0, Height, Width, Height)); } if (!FlipX & FlipY) { array.Append(CreateVertex(0, 0, 0, Height)); array.Append(CreateVertex(Width, 0, Width, Height)); array.Append(CreateVertex(Width, Height, Width, 0)); array.Append(CreateVertex(0, Height, 0, 0)); } }
private void Rebuild() { vertexArray = new VertexArray(PrimitiveType.Quads); var mapWidth = tiles.GetUpperBound(0) + 1; var mapHeight = tiles.GetUpperBound(1) + 1; var tileSize = GameOptions.TileSize; var tileMapWidth = (int)texture.Size.X / tileSize; var chunkSize = GameOptions.TileChunkSize; var startX = chunkX * chunkSize; var startY = chunkY * chunkSize; var endX = Math.Min(startX + chunkSize, mapWidth); var endY = Math.Min(startY + chunkSize, mapHeight); for (var y = startY; y < endY; y++) { for (var x = startX; x < endX; x++) { if (tiles[x, y].Index >= lastTile) continue; var last = vertexArray.VertexCount; vertexArray.Resize(vertexArray.VertexCount + 4); var itexX = (tiles[x, y].Index % tileMapWidth) * tileSize; var itexY = (tiles[x, y].Index / tileMapWidth) * tileSize; // HACK: SFML's weird rendering var texX = itexX + 0.01f; var texY = itexY - 0.01f; vertexArray[last + 0] = new Vertex(new Vector2f(x * tileSize, y * tileSize), new Vector2f(texX, texY)); vertexArray[last + 1] = new Vertex(new Vector2f((x * tileSize) + tileSize, y * tileSize), new Vector2f(texX + tileSize, texY)); vertexArray[last + 2] = new Vertex(new Vector2f((x * tileSize) + tileSize, (y * tileSize) + tileSize), new Vector2f(texX + tileSize, texY + tileSize)); vertexArray[last + 3] = new Vertex(new Vector2f(x * tileSize, (y * tileSize) + tileSize), new Vector2f(texX, texY + tileSize)); } } Dirty = false; }
void Append(VertexArray v, float x, float y, float tx, float ty) { v.Append(new Vertex(new Vector2f(x, y), new Vector2f(tx, ty))); }
protected override void UpdateDrawable() { var minWidth = sliceX1 + tWidth - sliceX2; panelScaleX = (float)Width / (float)minWidth; if (panelScaleX > 1) panelScaleX = 1; var minHeight = sliceY1 + tHeight - sliceY2; panelScaleY = (float)Height / (float)minHeight; if (panelScaleY > 1) panelScaleY = 1; var v = new VertexArray(PrimitiveType.Quads); int x0, x1, x2, x3, y0, y1, y2, y3; int u0, u1, u2, u3, v0, v1, v2, v3; x0 = 0; y0 = 0; x1 = sliceX1; y1 = sliceY1; x2 = Width - (tWidth - sliceX2); y2 = Height - (tHeight - sliceY2); x3 = Width; y3 = Height; u0 = TextureLeft; v0 = TextureTop; u1 = TextureLeft + sliceX1; v1 = TextureTop + sliceY1; u2 = TextureLeft + sliceX2; v2 = TextureTop + sliceY2; u3 = TextureLeft + tWidth; v3 = TextureTop + tHeight; if (panelScaleX < 1) { x1 = (int)Math.Round(x1 * panelScaleX); x2 = x1; } if (panelScaleY < 1) { y1 = (int)Math.Round(y1 * panelScaleY); y2 = y1; } int tileX = sliceX2 - sliceX1; int tileY = sliceY2 - sliceY1; if (PanelType == PanelType.Stretch) { //top DrawQuad(v, x1, y0, x2, y1, u1, v0, u2, v1); //left DrawQuad(v, x0, y1, x1, y2, u0, v1, u1, v2); //right DrawQuad(v, x2, y1, x3, y2, u2, v1, u3, v2); //bottom DrawQuad(v, x1, y2, x2, y3, u1, v2, u2, v3); //middle DrawQuad(v, x1, y1, x2, y2, u1, v1, u2, v2); } else { for (int xx = x1; xx < x2; xx += tileX) { for (int yy = y1; yy < y2; yy += tileY) { //middle DrawQuad(v, xx, yy, xx + tileX, yy + tileY, u1, v1, u2, v2); } } for (int yy = y1; yy < y2; yy += tileY) { //left DrawQuad(v, x0, yy, x1, yy + tileY, u0, v1, u1, v2); //right DrawQuad(v, x2, yy, x3, yy + tileY, u2, v1, u3, v2); } for (int xx = x1; xx < x2; xx += tileX) { //top DrawQuad(v, xx, y0, xx + tileX, y1, u1, v0, u2, v1); //bottom DrawQuad(v, xx, y2, xx + tileX, y3, u1, v2, u2, v3); } } //top left DrawQuad(v, x0, y0, x1, y1, u0, v0, u1, v1); //top right DrawQuad(v, x2, y0, x3, y1, u2, v0, u3, v1); //bottom left DrawQuad(v, x0, y2, x1, y3, u0, v2, u1, v3); //bottom right DrawQuad(v, x2, y2, x3, y3, u2, v2, u3, v3); SFMLVertices = v; }
void DrawQuad(VertexArray v, float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2) { float cx1 = x1, cx2 = x2, cy1 = y1, cy2 = y2; float cu1 = u1, cu2 = u2, cv1 = v1, cv2 = v2; if (usePanelClip) { cx1 = Util.Clamp(x1, ClippingRegion.Left, ClippingRegion.Right); cu1 = Util.ScaleClamp(cx1, x1, x2, u1, u2); cx2 = Util.Clamp(x2, ClippingRegion.Left, ClippingRegion.Right); cu2 = Util.ScaleClamp(cx2, x1, x2, u1, u2); cy1 = Util.Clamp(y1, ClippingRegion.Top, ClippingRegion.Bottom); cv1 = Util.ScaleClamp(cy1, y1, y2, v1, v2); cy2 = Util.Clamp(y2, ClippingRegion.Top, ClippingRegion.Bottom); cv2 = Util.ScaleClamp(cy2, y1, y2, v1, v2); } v.Append(cx1, cy1, Color, cu1, cv1); v.Append(cx2, cy1, Color, cu2, cv1); v.Append(cx2, cy2, Color, cu2, cv2); v.Append(cx1, cy2, Color, cu1, cv2); }
/// <summary> /// Render debug information in the console. /// </summary> public override void RenderDebug(SFML.Graphics.VertexArray vertexArray) { // TODO: render the grid lol }
//////////////////////////////////////////////////////////// /// <summary> /// Construct the vertex array from another vertex array /// </summary> /// <param name="copy">Transformable to copy</param> //////////////////////////////////////////////////////////// public VertexArray(VertexArray copy) : base(sfVertexArray_copy(copy.CPointer)) { }
public StormBlink() : base("storm + blink") { Random random = new Random(); // Create the points myPoints = new VertexArray(PrimitiveType.Points); for (int i = 0; i < 40000; ++i) { float x = (float)random.Next(0, 800); float y = (float)random.Next(0, 600); byte r = (byte)random.Next(0, 255); byte g = (byte)random.Next(0, 255); byte b = (byte)random.Next(0, 255); myPoints.Append(new Vertex(new Vector2f(x, y), new Color(r, g, b))); } // Load the shader myShader = new Shader("resources/storm.vert", "resources/blink.frag"); }
static Draw() { verts = new VertexArray(SFML.Graphics.PrimitiveType.Lines); }
internal void Draw(Texture texture, float x, float y, float originX, float originY, int width, int height, float scaleX, float scaleY, float angle, Color color = null, BlendMode blend = BlendMode.Alpha, Shader shader = null) { states = new RenderStates(Texture.SFMLTexture); states.BlendMode = (SFML.Graphics.BlendMode)Blend; if (Shader != null) { states.Shader = Shader.shader; } states.Transform.Translate(x - OriginX, y - OriginY); states.Transform.Rotate(-Angle, OriginX, OriginY); states.Transform.Scale(ScaleX, ScaleY, OriginX, OriginY); var v = new VertexArray(PrimitiveType.Quads); if (color == null) color = Color.White; v.Append(x, y, color, 0, 0); v.Append(x + width, y, color, width, 0); v.Append(x + width, y + height, color, width, height); v.Append(x, y + height, color, 0, height); Draw(v, states); }
internal void AppendVertices(VertexArray array) { array.Append(CreateVertex()); array.Append(CreateVertex(Width, 0, Width)); array.Append(CreateVertex(Width, Height, Width, Height)); array.Append(CreateVertex(0, Height, 0, Height)); }
void Append(VertexArray v, float x, float y) { v.Append(x, y, Color); }
// This right here my friend. public void SendWhiteboarDrawnSomething(VertexArray v, byte tool) { NetOutgoingMessage om = _client.CreateMessage(); om.WriteVariableInt32((int)ClientSendType.ClientSendWhiteboardDrawnSomething); om.Write(tool); om.Write(v.VertexCount + 3); for (int i = 0; i < v.VertexCount + 3; i++) { if (i > 2) { int testA = (int)v[(uint)i - 3].Position.X; int testB = (int)v[(uint)i - 3].Position.Y; Console.WriteLine("server: index: " + (i - 3) + " x: " + testA + " y: " + testB); om.WriteVariableInt32(testA); om.WriteVariableInt32(testB); om.Write(v[(uint)i - 3].Color.R); om.Write(v[(uint)i - 3].Color.G); om.Write(v[(uint)i - 3].Color.B); om.Write(v[(uint)i - 3].Color.A); } else { int testA = (int)v[(uint)i].Position.X; int testB = (int)v[(uint)i].Position.Y; Console.WriteLine("server: index: " + i + " x: " + testA + " y: " + testB); om.WriteVariableInt32(testA); om.WriteVariableInt32(testB); om.Write(v[(uint)i].Color.R); om.Write(v[(uint)i].Color.G); om.Write(v[(uint)i].Color.B); om.Write(v[(uint)i].Color.A); } } _client.SendMessage(om, NetDeliveryMethod.ReliableOrdered, 0); _client.FlushSendQueue(); }
/* * @param _funcType Style of the top line that generated * @param _res Size of mapunits for one linear segment * */ public PolygonActor(World _world, Vector2 _position, uint _seed, FunctionType _funcType, int _res = 5) : base(_world, _position) { int lineCount = (int)Constants.worldSizeX / _res; //make sure to have an even number if (lineCount % 2 != 0) lineCount++; Vec2[] verts = new Vec2[(int)lineCount + 1 + 4]; vertexBuffer = new VertexArray(PrimitiveType.LinesStrip); Vector2 posScreen = _position.toScreenCoord(); //repeatable random sequenze Rand rnd = new Rand(_seed); //start and end have even ground verts[0] = new Vec2(0, 6); verts[1] = new Vec2(_res, 6); verts[2] = new Vec2(_res + _res, 6); verts[lineCount - 2] = new Vec2(_res * (lineCount - 2), 6); verts[lineCount-1] = new Vec2(_res * (lineCount-1), 6); verts[lineCount] = new Vec2(_res * lineCount, 6); vertexBuffer.Append(new Vertex(((Vector2)verts[0] + _position).toScreenCoord())); //create the function if (_funcType == FunctionType.Simple) { for (int i = 2; i <= lineCount; ++i) { //Vector2 pos = new Vec2(i * 5, 10 + Rand.IntValue(10)); Vector2 pos = new Vec2(i * _res, System.Math.Max((verts[i - 1].Y + (int)rnd.next(6) - 3), 0)); verts[i] = pos; } } else if(_funcType == FunctionType.GradientNoise) { for (int i = 2; i < lineCount-3;) { int nextGrad = i + 4; if (nextGrad < lineCount - 2) { verts[nextGrad] = new Vec2(nextGrad * _res, rnd.next((int)maxHeight)); } else nextGrad = lineCount - 2; //interpolate between float relativeA = verts[i].Y / maxHeight; float relativeB = verts[nextGrad].Y / maxHeight; for (int c = i + 1; c < nextGrad; ++c) { verts[c] = new Vec2(c * _res, maxHeight * interpolateCos(relativeA, relativeB, (float)(c - i) / 4)); } i = nextGrad; } } Array.Resize<Body>(ref triangleBodys, lineCount); PolygonDef triangleDef = new PolygonDef(); triangleDef.Density = 0.0f; triangleDef.Friction = 1.0f; triangleDef.VertexCount = 3; BodyDef bodydef = new BodyDef(); bodydef.Position = _position; bodydef.Angle = 0.0f; //convert to triangles for (int i = 0; i < lineCount; ++i) { //always 3 points of the function form a triangle triangleDef.Vertices[0] = verts[i]; triangleDef.Vertices[1] = verts[i] - new Vec2(0.0f, 50.0f); triangleDef.Vertices[2] = verts[i + 1];//.Y < verts[i+1].Y ? verts[i] : verts[i + 1] triangleBodys[i] = _world.CreateBody(bodydef); triangleBodys[i].CreateShape(triangleDef); vertexBuffer.Append(new Vertex(((Vector2)verts[i+1] + _position).toScreenCoord())); } }
public Client(string address, int port) { vertex = new VertexArray(PrimitiveType.TrianglesStrip); Init(address, port); }
/// <summary> /// This method draw the received vertex, used by both the client and the server /// Call when whether the server draw something or the client draw something and /// had sent the information over /// </summary> /// <param name="v">V is the vertex array of the drawn line</param> /// <param name="tool">Tool is the byte that define which tool is being drawn, corresponse to ToolType enum</param> public void DrawReceivedVertex(VertexArray v, byte tool) { if (tool == (byte)ToolType.Pencil) forDraw.Draw(v); else forDraw.Draw(v, rState); }
public override void DrawSolidPolygon(Vector2[] vertices, int count, float red, float blue, float green) { var col = new Color((byte)red, (byte)green, (byte)blue); var va = new VertexArray(PrimitiveType.Quads, (uint)count); for (uint i = 0; i < count; i++) { va[i] = new Vertex(new Vector2f(vertices[i].X * 64, vertices[i].Y * 64), col); } rt.Draw(va); }