public Arrow(ArrowInfo info) { _triangleSize = info.TriangleSize; _thickness = info.Thickness; _head = new ConvexShape(3) { Origin = new Vector2f(.0f, .0f), FillColor = info.Color, OutlineColor = info.LineColor, OutlineThickness = info.LineThickness }; _head.SetPoint(0, new Vector2f(.0f, .0f)); _head.SetPoint(1, new Vector2f(-_triangleSize.X, _triangleSize.Y / 2)); _head.SetPoint(2, new Vector2f(-_triangleSize.X, -_triangleSize.Y / 2)); _rect = new RectangleShape(new Vector2f(1.0f, info.Thickness)) { FillColor = info.Color, OutlineColor = info.LineColor, OutlineThickness = info.LineThickness }; Delta = new Vector2f(1.0f, 1.0f); }
void RenderMiniMap(IntRect size, List <GameObject> objects, Player player) { CircleShape circle = new CircleShape(); circle.Radius = 2.0f; circle.Origin = new Vector2f(circle.GetLocalBounds().Left + circle.GetLocalBounds().Width / 2, circle.GetLocalBounds().Top + circle.GetLocalBounds().Height / 2); circle.OutlineColor = new Color(0, 0, 0); circle.OutlineThickness = 1; RectangleShape rect = new RectangleShape(new Vector2f(size.Width + circle.Radius, size.Height + circle.Radius)); rect.Position = new Vector2f(size.Left - circle.Radius, size.Top); rect.FillColor = new Color(200, 200, 200, 230); rect.OutlineThickness = 1; rect.OutlineColor = new Color(0, 0, 0); rendertexture.Draw(rect); int MINIMAPRANGE = player.GetMiniMapRange(); for (int n = 0; n < objects.Count; n++) { if (Math.Abs(player.GetPosition().X - objects[n].GetPosition().X) < MINIMAPRANGE && Math.Abs(player.GetPosition().Y - objects[n].GetPosition().Y) < MINIMAPRANGE && objects[n].GetVisible()) { Color fillcol; if (objects[n].GetFixed()) { fillcol = new Color(0, 200, 0); } else { fillcol = new Color(0, 0, 200); } float objx = (objects[n].GetPosition().X - player.GetPosition().X) * size.Width / (MINIMAPRANGE * 2) + size.Width / 2 + size.Left; float objy = (objects[n].GetPosition().Y - player.GetPosition().Y) * size.Height / (MINIMAPRANGE * 2) + size.Height / 2 + size.Top; circle.FillColor = fillcol; circle.Position = new Vector2f(objx, objy); rendertexture.Draw(circle); } } /* * circle.Radius = 5.0f; * circle.Origin = new Vector2f(circle.GetLocalBounds().Left + circle.GetLocalBounds().Width/2, circle.GetLocalBounds().Top + circle.GetLocalBounds().Height/2); * circle.FillColor = new Color(200, 0, 0); * circle.Position = new Vector2f(size.Left + size.Width/2, size.Top + size.Height/2); * circle.SetPointCount(3); * circle.Rotation = (float)(player.GetAngle()*180.0/Math.PI) + 90; * rendertexture.Draw(circle);*/ ConvexShape playershape = new ConvexShape(3); playershape.SetPoint(0, new Vector2f((float)(6 * Math.Cos(player.GetAngle())), (float)(6 * Math.Sin(player.GetAngle())))); playershape.SetPoint(1, new Vector2f((float)(4 * Math.Cos(player.GetAngle() + Math.PI * 120 / 180)), (float)(4 * Math.Sin(player.GetAngle() + Math.PI * 120 / 180)))); playershape.SetPoint(2, new Vector2f((float)(4 * Math.Cos(player.GetAngle() + Math.PI * 240 / 180)), (float)(4 * Math.Sin(player.GetAngle() + Math.PI * 240 / 180)))); playershape.FillColor = new Color(200, 0, 0); playershape.Position = new Vector2f(size.Left + size.Width / 2, size.Top + size.Height / 2); rendertexture.Draw(playershape); }
public BoxRenderer(RenderTarget renderTarget) { _renderTarget = renderTarget; _shape = new ConvexShape(4); _shape.SetPoint(0, new Vector2f(-.5f, -.5f)); _shape.SetPoint(1, new Vector2f(.5f, -.5f)); _shape.SetPoint(2, new Vector2f(.5f, .5f)); _shape.SetPoint(3, new Vector2f(-.5f, .5f)); }
private ShapeDecorator GetTriangle(Vector2f point1, Vector2f point2, Vector2f point3) { ConvexShape triangle = new ConvexShape(); triangle.SetPointCount(3); triangle.SetPoint(0, point1); triangle.SetPoint(1, point2); triangle.SetPoint(2, point3); return(new TriangleDecorator(triangle)); }
private void InitRightButton() { int rightPosX = POS_X + 32; int rightPosY = POS_Y; rightButton = new ConvexShape(3); rightButton.FillColor = GetColor(); rightButton.Position = new Vector2f(rightPosX, rightPosY); rightButton.SetPoint(0, new Vector2f(rightPosX + 16, rightPosY)); rightButton.SetPoint(1, new Vector2f(rightPosX - 16, rightPosY - 16)); rightButton.SetPoint(2, new Vector2f(rightPosX - 16, rightPosY + 16)); }
private void InitLeftButton() { int leftPosX = POS_X - 32; int leftPosY = POS_Y; leftButton = new ConvexShape(3); leftButton.FillColor = GetColor(); leftButton.Position = new Vector2f(leftPosX, leftPosY); leftButton.SetPoint(0, new Vector2f(leftPosX - 16, leftPosY)); leftButton.SetPoint(1, new Vector2f(leftPosX + 16, leftPosY - 16)); leftButton.SetPoint(2, new Vector2f(leftPosX + 16, leftPosY + 16)); }
public int DrawTriangle(Vector2f p1, Vector2f p2, Vector2f p3) { ConvexShape triangle = new ConvexShape(3); triangle.SetPoint(0, GetScreenPosition(p1)); triangle.SetPoint(1, GetScreenPosition(p2)); triangle.SetPoint(2, GetScreenPosition(p3)); var id = GetNextId(); graphElements.Add(id, triangle); return(id); }
public Tile(int id) { shape = new ConvexShape(4) { OutlineColor = Color.Black, OutlineThickness = 2, Texture = new Texture(Sources.TileTextures[id]) //FillColor = getTileColor(id) }; shape.SetPoint(0, MathModule.ViewTransform(0, 0)); shape.SetPoint(1, MathModule.ViewTransform(0, 1)); shape.SetPoint(2, MathModule.ViewTransform(1, 1)); shape.SetPoint(3, MathModule.ViewTransform(1, 0)); }
public void DrawWires() { foreach (InPort port in inPorts) { if (port.connexion != null) { wireDrawer.SetPoint(0, port.GetGlobalPos()); wireDrawer.SetPoint(1, port.GetGlobalPos()); wireDrawer.SetPoint(2, port.connexion.GetGlobalPos()); wireDrawer.SetPoint(3, port.connexion.GetGlobalPos()); Program.window.Draw(wireDrawer); } } }
public void CheckDescriptionOfTriangle() { ConvexShape triangle = new ConvexShape(); triangle.SetPointCount(3); triangle.SetPoint(0, new Vector2f(40, 60)); triangle.SetPoint(1, new Vector2f(100, 100)); triangle.SetPoint(2, new Vector2f(200, 350)); ShapeDecorator circleDecorator = new TriangleDecorator(triangle); string expected = "Triangle: P=672,58; S=5500"; string actual = circleDecorator.GetDescription(); Assert.AreEqual(expected, actual); }
private static ConvexShape GetPolygon(Vector2i self, Color defaultColor) { var polygon = new ConvexShape(4) { Position = GetMapPoint(self.X, self.Y), FillColor = defaultColor, OutlineColor = Color.Black, OutlineThickness = 1 }; polygon.SetPoint(0, new Vector2f(0, 0)); polygon.SetPoint(1, GetMapPoint(self.X + 1, self.Y) - polygon.Position); polygon.SetPoint(2, GetMapPoint(self.X + 1, self.Y + 1) - polygon.Position); polygon.SetPoint(3, GetMapPoint(self.X, self.Y + 1) - polygon.Position); return(polygon); }
public static void DrawTriangle(float x1, float y1, float x2, float y2, float x3, float y3) { var shape = new ConvexShape(3) { //Position = new Vector2f(x1, x2), FillColor = FillColors.Peek(), OutlineThickness = StrokeWeights.Peek(), OutlineColor = StrokeColors.Peek(), }; shape.SetPoint(0, new Vector2f(x1, y1)); shape.SetPoint(1, new Vector2f(x2, y2)); shape.SetPoint(2, new Vector2f(x3, y3)); renderWindow.Draw(shape); }
public void DrawBorder(RenderWindow window, SFML.Graphics.Color fillColor, SFML.Graphics.Color outLineColor, int outLineSize = 1) { ConvexShape polygon = new ConvexShape(); polygon.SetPointCount(4); polygon.SetPoint(0, new Vector2f(this.Points[0].X, this.Points[0].Y)); polygon.SetPoint(1, new Vector2f(this.Points[1].X, this.Points[1].Y)); polygon.SetPoint(2, new Vector2f(this.Points[2].X, this.Points[2].Y)); polygon.SetPoint(3, new Vector2f(this.Points[3].X, this.Points[3].Y)); polygon.FillColor = SFML.Graphics.Color.Transparent; polygon.OutlineColor = outLineColor; polygon.FillColor = fillColor; polygon.OutlineThickness = outLineSize; window.Draw(polygon); }
private static void Append(ref ConvexShape s, Vector2i point) { var count = s.GetPointCount(); s.SetPointCount(count + 1); s.SetPoint(count, (Vector2f)point); }
public void EndFill() { if (!_isFillStart) { throw new LogicErrorException("Filling has already end"); } // RENDER var shape = new ConvexShape((uint)_points.Count); for (var i = 0; i < _points.Count; ++i) { shape.SetPoint((uint)i, _points[i]); } shape.FillColor = _fillColor; shape.OutlineColor = _lineColor; shape.OutlineThickness = _lineThickness; _renderer.Draw(shape); // RENDER _fillColor = Color.Transparent; _isFillStart = false; }
public void CheckAreaOfTriangle() { ConvexShape triangle = new ConvexShape(); triangle.SetPointCount(3); triangle.SetPoint(0, new Vector2f(40, 60)); triangle.SetPoint(1, new Vector2f(100, 100)); triangle.SetPoint(2, new Vector2f(200, 350)); ShapeDecorator circleDecorator = new TriangleDecorator(triangle); string expected = "5500"; string actual = ""; actual = actual + circleDecorator.GetArea(); Assert.AreEqual(expected, actual); }
public void SetReticlePosition(float y) { Reticle.Y = y; Vector2f LineLeftP = Utils.GetPointInDirection(LineLeft.Position, (float)Utils.GetAngle(LineLeft.Position, new Vector2f(Circle.Radius, Reticle.Y)), Game.Size.X * 3); Vector2f LineRightP = Utils.GetPointInDirection(LineRight.Position, (float)Utils.GetAngle(LineRight.Position, new Vector2f(-Circle.Radius, Reticle.Y)), Game.Size.X * 3); LineLeft.Size = new Vector2f(Utils.Distance(LineLeft.Position, LineLeftP), LineLeft.Size.Y); LineLeft.Rotation = (float)Utils.GetAngle(LineLeft.Position, LineLeftP); LineRight.Size = new Vector2f(Utils.Distance(LineRight.Position, LineRightP), LineRight.Size.Y); LineRight.Rotation = (float)Utils.GetAngle(LineRight.Position, LineRightP); Fill.SetPoint(0, LineLeft.Position); Fill.SetPoint(1, LineLeftP); Fill.SetPoint(2, LineRightP); Fill.SetPoint(3, LineRight.Position); }
public void DrawCellMapChangeTopMove(RenderWindow window, bool top) { if (top) { if (BorderTopChangeTrue == null) { ConvexShape polygon = new ConvexShape(); polygon.SetPointCount(4); polygon.SetPoint(0, new Vector2f(this.Points[0].X, this.Points[0].Y)); polygon.SetPoint(1, new Vector2f(this.Points[1].X, this.Points[1].Y)); polygon.SetPoint(2, new Vector2f(this.Points[2].X, this.Points[2].Y)); polygon.SetPoint(3, new Vector2f(this.Points[3].X, this.Points[3].Y)); polygon.FillColor = SFML.Graphics.Color.Transparent; polygon.OutlineColor = SFML.Graphics.Color.White; polygon.FillColor = new SFML.Graphics.Color(17, 76, 7, 80); polygon.OutlineThickness = 1; BorderTopChangeTrue = polygon; } window.Draw(BorderTopChangeTrue); } else { if (BorderTopChangeFalse == null) { ConvexShape polygon = new ConvexShape(); polygon.SetPointCount(4); polygon.SetPoint(0, new Vector2f(this.Points[0].X, this.Points[0].Y)); polygon.SetPoint(1, new Vector2f(this.Points[1].X, this.Points[1].Y)); polygon.SetPoint(2, new Vector2f(this.Points[2].X, this.Points[2].Y)); polygon.SetPoint(3, new Vector2f(this.Points[3].X, this.Points[3].Y)); polygon.FillColor = SFML.Graphics.Color.Transparent; polygon.OutlineColor = SFML.Graphics.Color.White; polygon.FillColor = new SFML.Graphics.Color(255, 0, 15, 80); polygon.OutlineThickness = 1; BorderTopChangeFalse = polygon; } window.Draw(BorderTopChangeFalse); } }
public void DrawColorCell(RenderWindow window, SFML.Graphics.Color fillColor, SFML.Graphics.Color outlineColor, int outlineThickness = 1) { if (m_PolygonneCell == null) { ConvexShape polygon = new ConvexShape(); polygon.SetPointCount(4); polygon.SetPoint(0, new Vector2f(this.Points[0].X, this.Points[0].Y)); polygon.SetPoint(1, new Vector2f(this.Points[1].X, this.Points[1].Y)); polygon.SetPoint(2, new Vector2f(this.Points[2].X, this.Points[2].Y)); polygon.SetPoint(3, new Vector2f(this.Points[3].X, this.Points[3].Y)); polygon.OutlineThickness = outlineThickness; m_PolygonneCell = polygon; } m_PolygonneCell.OutlineColor = outlineColor; m_PolygonneCell.FillColor = fillColor; m_PolygonneCell.OutlineThickness = outlineThickness; window.Draw(m_PolygonneCell); }
public static ConvexShape GetLine(Vector2f startingPoint, Vector2f endingPoint, int thickness, Color color) { // Get the vectors required to calculate the vertices of our rectanle (line) var lineDirection = (endingPoint - startingPoint); var perpLeft = lineDirection.PerendicularCounterClockwise().Normalize(); var perpRight = lineDirection.PerendicularClockwise().Normalize(); var shape = new ConvexShape(4) { FillColor = color }; // Define points clockwise shape.SetPoint(0, startingPoint + (thickness * perpLeft)); shape.SetPoint(1, endingPoint + (thickness * perpLeft)); shape.SetPoint(2, endingPoint + (thickness * perpRight)); shape.SetPoint(3, startingPoint + (thickness * perpRight)); return(shape); }
public ConvexShape GetRectangleBoundary() { Vector2f leftSide = this.Position + _direction * Radius; Vector2f pointUpLeft = leftSide + new Vector2f(-_direction.Y, _direction.X) * Radius; Vector2f pointDownLeft = leftSide + new Vector2f(_direction.Y, -_direction.X) * Radius; Vector2f rightSide = _oldPosition - _direction * Radius; Vector2f pointUpRight = rightSide - new Vector2f(-_direction.Y, _direction.X) * Radius; Vector2f pointDownRight = rightSide - new Vector2f(_direction.Y, -_direction.X) * Radius; ConvexShape shape = new ConvexShape(); shape.SetPointCount((uint)4); shape.SetPoint(0, pointUpLeft); shape.SetPoint(2, pointUpRight); shape.SetPoint(1, pointDownRight); shape.SetPoint(3, pointDownLeft); return(shape); }
public void SetPoints(Vector2[] points) { shape.SetPointCount((uint)points.Length); origin = Vector2.Zero; for (uint i = 0; i < points.Length; i++) { Vector2 vector = points[i]; shape.SetPoint(i, vector.ToVector2f()); origin += vector; } origin /= points.Length; }
private static Province CreateProvince(string name, List <Vector2f> points) { var shape = new ConvexShape((uint)points.Count) { FillColor = GameRandom.GetRandomColor() }; for (var i = 0; i < points.Count; i++) { shape.SetPoint((uint)i, points[i]); } return(new Province(name, shape)); }
public override void DrawSolidPolygon(Vector2[] vertices, int count, float red, float blue, float green) { var shape = new ConvexShape { FillColor = RGBtoColor(red, blue, green), }; for (int i = 0; i < count; i++) { shape.SetPoint((uint)i, vertices[i].ToVector2f().InvertY()); } m_renderTarget.Draw(shape); }
private void CreateShape(Vector2f[] poses) { if (poses.Length < 3) { return; } shape = new ConvexShape((uint)poses.Length); for (uint i = 0; i < poses.Length; i++) { shape.SetPoint(i, poses[i]); } shape.FillColor = Color.Black; shape.Position = position; }
public PolygonRender(DrawableActor actor, Polygon polygon) : base(actor) { this.polygon = new Polygon(polygon); convexShape = new ConvexShape(); var verts = this.polygon.GetVertices(); convexShape.SetPointCount((uint)verts.Length); for (int i = 0; i < verts.Length; i++) { convexShape.SetPoint((uint)i, verts[i].ToVector2f()); } convexShape.Origin = this.polygon.Center.ToVector2f(); convexShape.OutlineThickness = 2; convexShape.OutlineColor = Color.White; convexShape.FillColor = Color.Transparent; drawableActor = actor; SetActive(true); }
private void ImgChararctersConstruction() { if (_characterPlayer1 != string.Empty) { _imgPlayer1.SetPointCount(9); _imgPlayer1.SetPoint(0, new Vector2f(125f, 15f)); _imgPlayer1.SetPoint(1, new Vector2f(575f, 15f)); _imgPlayer1.SetPoint(2, new Vector2f(370f, 760f)); _imgPlayer1.SetPoint(3, new Vector2f(345f, 760f)); _imgPlayer1.SetPoint(4, new Vector2f(325f, 800f)); _imgPlayer1.SetPoint(5, new Vector2f(329f, 760f)); _imgPlayer1.SetPoint(6, new Vector2f(267f, 760f)); _imgPlayer1.SetPoint(7, new Vector2f(298f, 898f)); _imgPlayer1.SetPoint(8, new Vector2f(-155f, 898f)); _imgPlayer1.Position = new Vector2f(900f, 0f); _imgPlayer1.Texture = _img.Character[_characterPlayer1]; _imgPlayer1.TextureRect = new IntRect(0, 0, Convert.ToInt32(_img.Character[_characterPlayer1].Size.X), Convert.ToInt32(_img.Character[_characterPlayer1].Size.Y)); } if (_characterPlayer2 != string.Empty) { _imgPlayer2.SetPointCount(7); _imgPlayer2.SetPoint(0, new Vector2f(130f, 15f)); _imgPlayer2.SetPoint(1, new Vector2f(490f, 15f)); _imgPlayer2.SetPoint(2, new Vector2f(490f, 330f)); _imgPlayer2.SetPoint(3, new Vector2f(345f, 898f)); _imgPlayer2.SetPoint(4, new Vector2f(-50f, 898f)); _imgPlayer2.SetPoint(5, new Vector2f(-50f, 758f)); _imgPlayer2.SetPoint(6, new Vector2f(-95f, 758f)); _imgPlayer2.Position = new Vector2f(1428f, 0f); _imgPlayer2.Texture = _img.Character[_characterPlayer2]; _imgPlayer2.TextureRect = new IntRect(0, 0, Convert.ToInt32(_img.Character[_characterPlayer2].Size.X), Convert.ToInt32(_img.Character[_characterPlayer2].Size.Y)); } }
public static List <ConvexShape> LoadObjects(string title) { List <ConvexShape> returnList = new List <ConvexShape>(); FileStream fs = null; StreamReader streamRead = null; try { string[] file = File.ReadAllLines("Saves\\" + title + ".txt"); foreach (string line in file) { string[] lineSplit = line.Split(':'); int[] lineInt = new int[lineSplit.Length]; for (int i = 0; i < lineSplit.Length; i++) { lineInt[i] = Convert.ToInt32(lineSplit[i]); } ConvexShape shape = new ConvexShape((uint)lineInt[2]); shape.Position = new Vector2f(lineInt[0], lineInt[1]); for (int i = 3; i < lineInt[2] + 3; i++) { shape.SetPoint((uint)i - 3, new Vector2f(lineInt[i + i - 3], lineInt[i + i - 2])); } int colorI = lineInt[2] * 2 + 3; shape.FillColor = new Color((byte)lineInt[colorI], (byte)lineInt[colorI + 1], (byte)lineInt[colorI + 2]); returnList.Add(shape); } } finally { if (streamRead != null) { streamRead.Close(); } if (fs != null) { fs.Close(); } } return(returnList); }
void RenderFigure() { int size = figure.polygons.Keys.Count; if (figure.Dimension() > 2) { var zBuffer = new SortedList <double, int>(new DuplicateKeyComparer <double>()); for (int c = 0; c < size; ++c) { var polygon = figure.polygons[c]; Vector <double> normal = polygon.Aggregate((s, v) => s + v).Normalize(1); zBuffer.Add(normal[2], c); } for (int c = 0; c < size; ++c) { int id = zBuffer.Values[c]; var polygon = figure.polygons[id]; Color color = originalShape.FillColor; double zp = (zBuffer.Keys[c] + 1) * 0.5; color.R = (byte)(color.R * zp); color.G = (byte)(color.G * zp); color.B = (byte)(color.B * zp); color.A = (byte)(color.A * zp); ConvexShape shape = new ConvexShape { Position = originalShape.Position, FillColor = color }; shape.SetPointCount((uint)polygon.Count); for (int i = 0; i < polygon.Count; ++i) { shape.SetPoint((uint)i, new Vector2f((float)polygon[i][0], -(float)polygon[i][1])); } window.Draw(shape); } } }
public KeyControl(float size) { array = new ConvexShape(8); array.SetPoint(0, new Vector2f(0, -size)); array.SetPoint(1, new Vector2f(.3f * size, -.3f * size)); array.SetPoint(2, new Vector2f(size, 0)); array.SetPoint(3, new Vector2f(.3f * size, .3f * size)); array.SetPoint(4, new Vector2f(0, size)); array.SetPoint(5, new Vector2f(-.3f * size, .3f * size)); array.SetPoint(6, new Vector2f(-size, 0)); array.SetPoint(7, new Vector2f(-.3f * size, -.3f * size)); array.OutlineColor = Color.Black; array.OutlineThickness = -1f; var tmp = new CustomHitbox(); for (uint i = 0; i < 8; i++) { tmp.CustomShape.Add(array.GetPoint(i)); } HitBox = tmp; }