void Rebuild() { if (!IsDirty) { return; } IsDirty = false; TextureAtlas = new Texture((uint)TextureAtlasSize.X, (uint)TextureAtlasSize.Y); for (var index = 0; index < TilePropertyIndexes.Length; ++index) { var propertyIndex = TilePropertyIndexes[index]; var props = TileProperties.GetByIndex(propertyIndex); var fileName = Path.Combine("data", "tiles", props.Filename); if (File.Exists(fileName)) { SetTileTexture(new Image(fileName), propertyIndex); } } VertexArray.Clear(); for (var index = 0; index < TilePropertyIndexes.Length; ++index) { Vector2f TileUV = GetTileUV(TilePropertyIndexes[index]); var worldPosition = new Vector2f((index % Size.X) * TileSize.X, (index / Size.X) * TileSize.Y); VertexArray.Append(new Vertex() { Position = worldPosition, TexCoords = new Vector2f(TileUV.X, 0), Color = Color.White }); VertexArray.Append(new Vertex() { Position = worldPosition + new Vector2f(TileSize.X, 0), TexCoords = new Vector2f(TileUV.X + TileSize.X, TileUV.Y), Color = Color.White }); VertexArray.Append(new Vertex() { Position = worldPosition + new Vector2f(TileSize.X, TileSize.Y), TexCoords = new Vector2f(TileUV.X + TileSize.X, TileUV.Y + TileSize.Y), Color = Color.White }); VertexArray.Append(new Vertex() { Position = worldPosition + new Vector2f(0, TileSize.Y), TexCoords = new Vector2f(TileUV.X, TileUV.Y + TileSize.Y), Color = Color.White }); } }
private void BindTexture() { vertexArray.Clear(); // !# // ## vertexArray.Append(new Vertex( new Vector2f(mapPosition.X * WorldSize, mapPosition.Y * WorldSize), new Vector2f(ID % tilesPerTileSetLine * TextureSize, (ID / tilesPerTileSetLine) * TextureSize))); // #! // ## vertexArray.Append(new Vertex( new Vector2f((mapPosition.X + 1) * WorldSize, mapPosition.Y * WorldSize), new Vector2f((ID % tilesPerTileSetLine + 1) * TextureSize, (ID / tilesPerTileSetLine) * TextureSize))); // ## // #! vertexArray.Append(new Vertex( new Vector2f((mapPosition.X + 1) * WorldSize, (mapPosition.Y + 1) * WorldSize), new Vector2f((ID % tilesPerTileSetLine + 1) * TextureSize, ((ID / tilesPerTileSetLine) + 1) * TextureSize))); // ## // !# vertexArray.Append(new Vertex( new Vector2f(mapPosition.X * WorldSize, (mapPosition.Y + 1) * WorldSize), new Vector2f(ID % tilesPerTileSetLine * TextureSize, ((ID / tilesPerTileSetLine) + 1) * TextureSize))); }
/// <summary> /// Draw a line between the given coordinates /// </summary> /// <param name="x1">The first x-coordinate</param> /// <param name="y1">The first y-coordinate</param> /// <param name="x2">The second x-coordinate</param> /// <param name="y2">The second y-coordinate</param> public static void DrawLine(int x1, int y1, int x2, int y2) { if (_lineThickness == 0) { VertexArray vertexArray = new VertexArray(PrimitiveType.Lines); vertexArray.Append(new Vertex(new Vector2f(x1, y1), _lineColor)); vertexArray.Append(new Vertex(new Vector2f(x2, y2), _lineColor)); _drawables.Add(vertexArray); } else { // a line with thickness is actually a rectangle with a length determined // by pythagoras and a height determined by line thickness RectangleShape rect = new RectangleShape( size: new Vector2f( x: (float)Math.Sqrt(Math.Pow(Math.Abs(x2 - x1), 2) + Math.Pow(Math.Abs(y2 - y1), 2)), y: _lineThickness ) ); rect.FillColor = _lineColor; rect.Position = new Vector2f(x1 + _lineThickness / 2, y1 - _lineThickness / 2); // cartesian space calculation of vector angle rect.Rotation = (float)(-Math.Atan2(y1 - y2, x2 - x1) * 180 / Math.PI); _drawables.Add(rect); } Update(); }
VertexArray GenerateTrianglesStrip(List <Vector2f> points, Color color, float thickness, bool open) { var array = new VertexArray(PrimitiveType.TrianglesStrip); for (int i = 1; i < points.Count + 1 + (open ? 0 : 1); i++) { Vector2f v0 = points[(i - 1) % points.Count]; Vector2f v1 = points[i % points.Count]; Vector2f v2 = points[(i + 1) % points.Count]; Vector2f v01 = (v1 - v0).Normalized(); Vector2f v12 = (v2 - v1).Normalized(); Vector2f d = (v01 + v12).GetNormal(); float dot = d.Dot(v01.GetNormal()); d *= thickness / 2f / dot; //< TODO: Add flat miter joint in extreme cases // d *= thickness / 2f / (float)Math.Max(.8, dot); if (points.Count == i) { array.Append(new Vertex(v0 - d / 4, color)); array.Append(new Vertex(v0 + d / 4, color)); } else { array.Append(new Vertex(v0 + d, color)); array.Append(new Vertex(v0 - d, color)); } } return(array); }
public void Draw() { PlayerAnimations.SetTextureArea(this); Func <int, int> scale = (x) => x * Const.PlayerScalePercent / 100; int width = scale(Const.PlayerSpriteWidth), height = scale(Const.PlayerSpriteHeight); IntRect dst = Geometry.AdaptRect(new IntRect( left: Rect.Left + Rect.Width / 2 - width / 2, top: Rect.Top + Rect.Height / 2 - height / 2, width: width, height: height )); Screen.GameScene.Draw(Drawing.SpriteOf(Texture, dst, TextureArea)); if (Hooked) { VertexArray line = new VertexArray(PrimitiveType.Lines); line.Append(new Vertex( (Vector2f)Geometry.AdaptPoint(GetCOM()), new Color(red: 255, 0, 0) )); line.Append(new Vertex( (Vector2f)Geometry.AdaptPoint(HookPoint), new Color(red: 255, 0, 0) )); Screen.GameScene.Draw(line); } }
public void MakeRectangle(FloatRect rect, FloatRect uv) { _mesh.Clear(); Vertex v = new Vertex(); Color color = Color.White; v.Color = color; v.Position = new Vector2f(rect.Left, rect.Top); v.TexCoords = new Vector2f(uv.Left, uv.Top); _mesh.Append(v); v.Position.X += rect.Width; v.TexCoords.X += uv.Width; _mesh.Append(v); v.Position.Y += rect.Height; v.TexCoords.Y += uv.Height; _mesh.Append(v); v.Position.X = rect.Left; v.TexCoords.X = uv.Left; _mesh.Append(v); _mesh.PrimitiveType = PrimitiveType.Quads; }
public bool intersecting(Shape other, RenderWindow w) { Vector2f[] axisArray = getAxisToTest(other); foreach (Vector2f axis in axisArray) { double[] projectedThis = Points.Select(x => x.Position.DotProduct(axis)).ToArray(); double[] projectedOther = other.Points.Select(x => x.Position.DotProduct(axis)).ToArray(); double thisMin = projectedThis.Min(); double thisMax = projectedThis.Max(); double otherMin = projectedOther.Min(); double otherMax = projectedOther.Max(); VertexArray a = new VertexArray(PrimitiveType.LinesStrip); a.Append(new Vertex(axis.Multiply(-1000), Color.Red)); a.Append(new Vertex(new Vector2f(400, 300), Color.Red)); a.Append(new Vertex(axis.Multiply(1000), Color.Red)); w.Draw(a); VertexArray b = new VertexArray(PrimitiveType.Lines); b.Append(new Vertex(axis.Multiply((float)thisMin), Color.Blue)); b.Append(new Vertex(new Vector2f(0, 0))); w.Draw(b); if (otherMin > thisMax || thisMin > otherMax) { return(false); } } return(true); }
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); }
public void AddSprite(Sprite drawable, Transformable t) { var rect = drawable.GetGlobalBounds(); _texture = drawable.Texture; _batch.Append(new Vertex() { Position = t.Position, TexCoords = new Vector2f(), Color = Color.White }); _batch.Append(new Vertex() { Position = new Vector2f(t.Position.X + rect.Width, t.Position.Y), TexCoords = new Vector2f(25, 0), Color = Color.White }); _batch.Append(new Vertex() { Position = new Vector2f(t.Position.X + rect.Width, t.Position.Y + rect.Height), TexCoords = new Vector2f(25, 50), Color = Color.White }); _batch.Append(new Vertex() { Position = t.Position, TexCoords = new Vector2f(t.Position.X, t.Position.Y + rect.Height), Color = Color.White }); }
public bool load(Int32 x, Int32 y, string tileset, Vector2u tileSize, List <List <Int32> > tiles, Int32 baseMin, Int32 baseMax) { m_tileset = new Texture(tileset); _tileSize = tileSize; _baseMin = baseMin; m_vertices.PrimitiveType = PrimitiveType.Quads; for (Int32 i = 0; i < tiles.Count; ++i) { for (Int32 j = 0; j < tiles[0].Count; ++j) { if (tiles[i][j] >= baseMin && tiles[i][j] <= baseMax) { m_vertices.Append(new Vertex(new Vector2f(j * tileSize.X + x, i * tileSize.Y + y))); m_vertices.Append(new Vertex(new Vector2f((j + 1) * tileSize.X + x, i * tileSize.Y + y))); m_vertices.Append(new Vertex(new Vector2f((j + 1) * tileSize.X + x, (i + 1) * tileSize.Y + y))); m_vertices.Append(new Vertex(new Vector2f(j * tileSize.X + x, (i + 1) * tileSize.Y + y))); _tiles.Add(tiles[i][j]); } } } return(true); }
public static List <VertexArray> GenerateLineWithThickness(List <Vector2f> points, Color color, float thickness, bool[] lines) { List <VertexArray> result = new List <VertexArray>( ); VertexArray array = new VertexArray(PrimitiveType.TrianglesStrip); for (int i = 0; i < points.Count; i++) { Vector2f v0 = (i == 0 ? 2 * points[0] - points[1] : points[i - 1]); Vector2f v1 = points[i]; Vector2f v2 = (i == points.Count - 1 ? 2 * points[i] - points[i - 1] : points[i + 1]); Vector2f v01 = (v1 - v0).Normalized( ); Vector2f v12 = (v2 - v1).Normalized( ); Vector2f d = (v01 + v12).GetNormal( ); float dot = d.Dot(v01.GetNormal( )); d *= thickness / 2f / dot; //< TODO: Add flat miter joint in extreme cases if (lines[i % lines.Length]) { array.Append(new Vertex(v1 + d, color)); array.Append(new Vertex(v1 - d, color)); } else { if (array.VertexCount > 0) { result.Add(array); array = new VertexArray(PrimitiveType.TrianglesStrip); } } } if (array.VertexCount > 0) { result.Add(array); } return(result); }
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)); }
public void AddTileVertices(AABB tile_region, AABB pos_in_tileset) { vertices.Append(new Vertex(new Vector2f(tile_region.topLeft.X, tile_region.topLeft.Y), Color.White, new Vector2f(pos_in_tileset.topLeft.X, pos_in_tileset.topLeft.Y))); vertices.Append(new Vertex(new Vector2f(tile_region.getTopRight().X, tile_region.getTopRight().Y), Color.White, new Vector2f(pos_in_tileset.getTopRight().X, pos_in_tileset.getTopRight().Y))); vertices.Append(new Vertex(new Vector2f(tile_region.rightBottom.X, tile_region.rightBottom.Y), Color.White, new Vector2f(pos_in_tileset.rightBottom.X, pos_in_tileset.rightBottom.Y))); vertices.Append(new Vertex(new Vector2f(tile_region.getLeftBottom().X, tile_region.getLeftBottom().Y), Color.White, new Vector2f(pos_in_tileset.getLeftBottom().X, pos_in_tileset.getLeftBottom().Y))); }
public static void DebugRender(this Camera camera, RenderTarget target) { #if DEBUG CircleShape cameraPositionRect = new CircleShape(); cameraPositionRect.FillColor = Color.Magenta; cameraPositionRect.Origin = new Vector2f(5, 5); cameraPositionRect.Position = camera.WorldPosition; cameraPositionRect.Radius = 5; // new Vector2f(10, 10); CircleShape originPositionRect = new CircleShape(); originPositionRect.FillColor = Color.Cyan; originPositionRect.Origin = new Vector2f(5, 5); originPositionRect.Position = camera.WorldZeroPosition; originPositionRect.Radius = 5; //new Vector2f(10, 10); target.Draw(cameraPositionRect); target.Draw(originPositionRect); VertexArray verts = new VertexArray(); verts.PrimitiveType = PrimitiveType.LineStrip; verts.Append(new Vertex(camera.WorldPosition, Color.Magenta)); verts.Append(new Vertex(camera.WorldZeroPosition, Color.Cyan)); target.Draw(verts); #endif }
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> /// Draws a line with a thickness using a quad. /// </summary> /// <param name="x1">The X position of the first point.</param> /// <param name="y1">The Y position of the first point.</param> /// <param name="x2">The X position of the second point.</param> /// <param name="y2">The Y position of the second point.</param> /// <param name="color">The color of the line.</param> /// <param name="thickness">The thickness of the line.</param> static public void Line(float x1, float y1, float x2, float y2, Color color, float thickness) { VertexArray vertices = new VertexArray(PrimitiveType.Quads); var line = new Vector2(x2 - x1, y2 - y1); var normalUp = new Vector2(y1 - y2, x2 - x1); var normalDown = new Vector2(y2 - y1, x1 - x2); normalUp.Normalize(thickness * 0.5f); normalDown.Normalize(thickness * 0.5f); float vx, vy; vx = (float)(x1 + normalUp.X); vy = (float)(y1 + normalUp.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); vx = (float)(x1 + normalDown.X); vy = (float)(y1 + normalDown.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); vx = (float)(x2 + normalDown.X); vy = (float)(y2 + normalDown.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); vx = (float)(x2 + normalUp.X); vy = (float)(y2 + normalUp.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); Drawable(vertices, RenderStates.Default); }
public override void Display(RenderWindow window) { View old = new View(window.GetView()); if (Absolute) { window.SetView(window.DefaultView); } if (Icon != null) { Sprite shadow = new Sprite(Icon); shadow.Position += new Vector2f(2, 2); shadow.Color = new Color(0, 0, 0); window.Draw(shadow); window.Draw(Icon); } VertexArray circle = new VertexArray(PrimitiveType.TriangleFan); circle.Append(new Vertex(Position + Size / 2, Color)); for (int i = 0; i < 20; i++) { circle.Append(new Vertex(new Vector2f( -MathF.Sin(State * MathF.PI / 180 * 360 / 20 * i) * Size.X / 2 + Position.X + Size.X / 2, -MathF.Cos(State * MathF.PI / 180 * 360 / 20 * i) * Size.Y / 2 + Position.Y + Size.Y / 2), Color)); } window.Draw(circle); if (Absolute) { window.SetView(old); } }
public Edge(Pair pair, Vector2f startpos, Vector2f stoppos, uint length = 1) { this.pair = pair; line = new VertexArray(); line.Append(new SFML.Graphics.Vertex(startpos, new Color(255, 255, 255))); line.Append(new SFML.Graphics.Vertex(stoppos, new Color(255, 255, 255))); line.PrimitiveType = PrimitiveType.Lines; this.length = length; Font font = new Font("resources/fonts/Font1.ttf"); lengthchar = new Text(); lengthchar.Font = font; lengthchar.CharacterSize = 25; lengthchar.Color = new Color(0, 0, 0); lengthchar.DisplayedString = length + ""; lengthchar.Position = new Vector2f((startpos.X + stoppos.X) / 2, (startpos.Y + stoppos.Y) / 2); lengthchar.Origin = new Vector2f(lengthchar.GetGlobalBounds().Width / 2, lengthchar.GetGlobalBounds().Height / 2); }
/// <summary> /// Draws a line using an OpenGL line. /// </summary> /// <param name="x1">The X position of the first point.</param> /// <param name="y1">The Y position of the first point.</param> /// <param name="x2">The X position of the second point.</param> /// <param name="y2">The Y position of the second point.</param> /// <param name="color">The color of the line.</param> static public void Line(float x1, float y1, float x2, float y2, Color color) { VertexArray vertices = new VertexArray(PrimitiveType.Lines); vertices.Append(new Vertex(new Vector2f(x1, y1), color.SFMLColor)); vertices.Append(new Vertex(new Vector2f(x2, y2), color.SFMLColor)); Drawable(vertices, RenderStates.Default); }
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 void InsertQuad(float xPos, float yPos, Color color) { // 1 2 // |_| // 0 3 vertexArray.Append(new Vertex(new Vector2f(xPos, yPos), color)); vertexArray.Append(new Vertex(new Vector2f(xPos, yPos + QuadHeight), color)); vertexArray.Append(new Vertex(new Vector2f(xPos + QuadWidth, yPos + QuadHeight), color)); vertexArray.Append(new Vertex(new Vector2f(xPos + QuadWidth, yPos), color)); }
private void DisplayNoiseWave(Color color, float weight, int interval) { VertexArray line = new VertexArray(PrimitiveType.LineStrip); line = new VertexArray(PrimitiveType.Quads); Vector2f prevPos; Vector2f currPos; Vector2f nextPos; Vector2f vector; Vertex v1; Vertex v2; InitializeFactors(color, weight, interval, out prevPos, out currPos, out nextPos, out vector, out v1, out v2); for (int i = interval; i < noiseFactors.Size; i += interval) { line.Append(v2); line.Append(v1); Vector2f vector1 = Normalize(prevPos - currPos); Vector2f vector2 = Normalize(nextPos - currPos); vector = (vector1 + vector2) * 0.5f; if (vector.Y > 0) { vector *= -1; } vector = SetMagnitude(vector, weight); v1 = new Vertex(currPos, color); v2 = new Vertex(v1.Position + vector, color); line.Append(v1); line.Append(v2); prevPos = currPos; currPos = new Vector2f ( Map(i, 0, noiseFactors.Size, -interval * 2, winSizeX + interval * 2), Map(noise[(i + (int)offset1) % noiseFactors.Size], GetMin(noise), GetMax(noise), -winSizeY * 0.25f, winSizeY * 0.25f) + winSizeY * 0.5f ); nextPos = new Vector2f ( Map(i + (int)interval, 0, noiseFactors.Size, -interval * 2, winSizeX + interval * 2), Map(noise[((int)(i + interval + offset1)) % noiseFactors.Size], GetMin(noise), GetMax(noise), -winSizeY * 0.25f, winSizeY * 0.25f) + winSizeY * 0.5f ); } window.Draw(line); }
public void SetColor(SFML.Graphics.Color color) { linePoints.Clear(); linePoints.Append(new Vertex(Start) { Color = color }); linePoints.Append(new Vertex(End) { Color = color }); }
private static void UpdateFromGameState(UpdateRequest state) { Players.Clear(); Players.AddRange(state.Players); LightPlayer lightPlayer = Players[Player.ID]; if (lightPlayer.Deaths != Player.Deaths) { Player.Deaths = lightPlayer.Deaths; Sounds.PlayShort("pop"); } if (lightPlayer.Score != Player.Score) { Player.Score = lightPlayer.Score; Sounds.PlayShort("tic"); } Player.HasRespawned = lightPlayer.HasRespawned; if (lightPlayer.ReSpawn) { Respawn(); Player.HasRespawned = true; } if (state.Shots == null) { return; } for (int i = 0; i < state.Shots.Length; ++i) { LightShot shot = state.Shots[i]; if (ShotLog.Contains(shot.ID)) { continue; } ShotLog.Add(shot.ID); Sounds.PlayShort("shot"); Color color = new Color(255, 220, 200, 255); VertexArray line = new VertexArray(PrimitiveType.Lines); line.Append(new Vertex( Geometry.AdaptPoint(new Vector2f(shot.Origin.X, shot.Origin.Y)), color )); line.Append(new Vertex( Geometry.AdaptPoint(new Vector2f(shot.Dest.X, shot.Dest.Y)), color )); Screen.Echoes.Add(line); } }
private void LineInternal(RenderTarget target, float x1, float y1, float x2, float y2, uint color = 0) { VertexArray points = new VertexArray(PrimitiveType.LineStrip); var vertex = new Vertex(new Vector2f(x1, y1)); vertex.Color = new Color(color); points.Append(vertex); var vertex1 = new Vertex(new Vector2f(x2, y2)); vertex1.Color = new Color(color); points.Append(vertex1); target.Draw(points); }
private void PrintChar(VertexArray vertexArray, BfChar c, Vector2f posF, Color color) { var white = new Color(255, 255, 255, 255); var texCoord = new Vector2f(c.Left, c.Top); var vX = new Vector2f(c.Width, 0); var vY = new Vector2f(0, LineHeight); // TODO: 12 is a magic number indicating font height. var vXY = vX + vY; vertexArray.Append(new Vertex(posF, white, texCoord)); vertexArray.Append(new Vertex(posF + vX, white, texCoord + vX)); vertexArray.Append(new Vertex(posF + vXY, color, texCoord + vXY)); vertexArray.Append(new Vertex(posF + vY, color, texCoord + vY)); }
public static void DrawLine(RenderTarget destination, Vector2f pos_start, Vector2f pos_end, Color color, BlendMode blend_mode) { RenderStates states = new RenderStates(blend_mode); VertexArray vertices = new VertexArray(PrimitiveType.Lines); vertices.Append(new Vertex(pos_start, color)); vertices.Append(new Vertex(pos_end, color)); destination.Draw(vertices, states); }
/// <summary> /// Draws cannon /// </summary> /// <param name="window"></param> /// <param name="cannon"></param> public void DrawCanon(RenderWindow window, Cannon cannon) { VertexArray ver_arr = new VertexArray(PrimitiveType.Quads); Color color = new Color(255, 100, 100); for (int i = 0; i < cannon.shape.Length; i++) { ver_arr.Append(new Vertex(new Vector2f((float)cannon.shape[i].x, (float)cannon.shape[i].y), color)); } ver_arr.Append(new Vertex(new Vector2f((float)cannon.shape[0].x, (float)cannon.shape[0].y), color)); window.Draw(ver_arr); }
//private float thickness; //private Color color; public sfLine(Vector2f point1, Vector2f point2, Color color, float thickness) { Vector2f direction = point2 - point1; Vector2f unitDirection = direction / (float)Math.Sqrt(direction.X * direction.X + direction.Y * direction.Y); Vector2f unitPerpendicular = new Vector2f(-unitDirection.Y, unitDirection.X); Vector2f offset = (thickness / 2.0f) * unitPerpendicular; vertices = new VertexArray(PrimitiveType.Quads); vertices.Append(new Vertex(point1 + offset, color)); vertices.Append(new Vertex(point2 + offset, color)); vertices.Append(new Vertex(point2 - offset, color)); vertices.Append(new Vertex(point1 - offset, color)); }
private void AddTileVertices(Tile tile, Vector2f position) // Add 4 vertices to our tiles { _vertexArray.Append(new Vertex((new Vector2f(0.0f, 0.0f) + position) * _tileWorldDimension, new Vector2f(_tileTextureDimension * tile._X, _tileTextureDimension * tile._Y))); _vertexArray.Append(new Vertex((new Vector2f(1.0f, 0.0f) + position) * _tileWorldDimension, new Vector2f(_tileTextureDimension * tile._X + _tileTextureDimension, _tileTextureDimension * tile._Y))); _vertexArray.Append(new Vertex((new Vector2f(1.0f, 1.0f) + position) * _tileWorldDimension, new Vector2f(_tileTextureDimension * tile._X + _tileTextureDimension, _tileTextureDimension * tile._Y + _tileTextureDimension))); _vertexArray.Append(new Vertex((new Vector2f(0.0f, 1.0f) + position) * _tileWorldDimension, new Vector2f(_tileTextureDimension * tile._X, _tileTextureDimension * tile._Y + _tileTextureDimension))); }