float epsilon; // padding for ray casting /*Polygon(Vector2 p1, Vector2 p2, params Vector2[] vertices) * { * Polygons.Add(this); * * if (p1.X < p2.X) * { * MinX = p1.X; * MaxX = p2.X; * } * else * { * MinX = p2.X; * MaxX = p1.X; * } * * if (p1.Y < p2.Y) * { * MinY = p1.Y; * MaxY = p2.Y; * } * else * { * MinY = p2.Y; * MaxY = p1.Y; * } * * this.vertices.Add(p1); * this.vertices.Add(p2); * * foreach (Vector2 vertex in vertices) * { * this.vertices.Add(vertex); * * if (vertex.X < MinX) * MinX = vertex.X; * else if (vertex.X > MaxX) * MaxX = vertex.X; * * if (vertex.Y < MinY) * MinY = vertex.Y; * else if (vertex.Y > MaxY) * MaxY = vertex.Y; * } * * for (int i = 0; i < this.vertices.Count; i++) * { * if (i < this.vertices.Count - 1) * { * * sides.Add(new LineSegment(this.vertices[i], this.vertices[i + 1])); * } * else * { * sides.Add(new LineSegment(this.vertices[i], p1)); * } * } * * epsilon = (MaxX - MinX) / 100f; * * line = new PrimitiveLine(Game1.Graphics.GraphicsDevice, 1); * line.Colour = Color.White; * }*/ /*public Polygon(Vector2 p1, Vector2 p2, params Vector2[] vertices) * { * Polygons.Add(this); * * if (p1.X < p2.X) * { * MinX = p1.X; * MaxX = p2.X; * } * else * { * MinX = p2.X; * MaxX = p1.X; * } * * if (p1.Y < p2.Y) * { * MinY = p1.Y; * MaxY = p2.Y; * } * else * { * MinY = p2.Y; * MaxY = p1.Y; * } * * this.vertices.Add(p1); * this.vertices.Add(p2); * * foreach (Vector2 vertex in vertices) * { * this.vertices.Add(vertex); * * if (vertex.X < MinX) * MinX = vertex.X; * else if (vertex.X > MaxX) * MaxX = vertex.X; * * if (vertex.Y < MinY) * MinY = vertex.Y; * else if (vertex.Y > MaxY) * MaxY = vertex.Y; * } * * for (int i = 0; i < this.vertices.Count; i++) * { * if (i < this.vertices.Count - 1) * { * * sides.Add(new LineSegment(this.vertices[i], this.vertices[i + 1])); * } * else * { * sides.Add(new LineSegment(this.vertices[i], p1)); * } * } * * epsilon = (MaxX - MinX) / 100f; * * CenterPoint = new Vector2((MinX + MaxX) / 2, (MinY + MaxY) / 2); * * line = new PrimitiveLine(Game1.Graphics.GraphicsDevice, 1); * line.Colour = Color.White; * }*/ public Polygon(params Vector2[] vertices) { if (vertices.Length < 3) { throw new Exception("inside Polygon constructor: must have at least 3 vertices"); } Polygons.Add(this); MinX = MaxX = vertices[0].X; MinY = MaxY = vertices[0].Y; foreach (Vector2 vertex in vertices) { this.vertices.Add(vertex); if (vertex.X < MinX) { MinX = vertex.X; } else if (vertex.X > MaxX) { MaxX = vertex.X; } if (vertex.Y < MinY) { MinY = vertex.Y; } else if (vertex.Y > MaxY) { MaxY = vertex.Y; } } for (int i = 0; i < this.vertices.Count; i++) { if (i < this.vertices.Count - 1) { sides.Add(new LineSegment(this.vertices[i], this.vertices[i + 1])); } else { sides.Add(new LineSegment(this.vertices[i], this.vertices[0])); } } epsilon = (MaxX - MinX) / 100f; CenterPoint = new Vector2((MinX + MaxX) / 2, (MinY + MaxY) / 2); line = new PrimitiveLine(Game1.Graphics.GraphicsDevice, 1); line.Colour = Color.White; initializeOccupiedGridNodes(); }
protected override void Initialize() { // TODO: Add your initialization logic here ballTexture = Content.Load <Texture2D>("blackcircle"); redTexture = Content.Load <Texture2D>("red"); font1 = Content.Load <SpriteFont>("font1"); line = new PrimitiveLine(Graphics.GraphicsDevice, 1); line.Colour = Color.Black; Grid = new Grid(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, (int)(ballSize * 1.1f)); makeBalls(); //new Polygon(new Vector2(200, 200), new Vector2(700, 150), new Vector2(800, 500), new Vector2(400, 500), new Vector2(500, 300)); /*new Polygon(new Vector2(200, 200), * new Vector2(Graphics.GraphicsDevice.Viewport.Width - 200, 200), * new Vector2(Graphics.GraphicsDevice.Viewport.Width - 400, Graphics.GraphicsDevice.Viewport.Height - 200), * new Vector2(Graphics.GraphicsDevice.Viewport.Width / 2, Graphics.GraphicsDevice.Viewport.Height), * new Vector2(200, Graphics.GraphicsDevice.Viewport.Height - 200), * new Vector2(100, Graphics.GraphicsDevice.Viewport.Height / 2));*/ Vector2 p1 = new Vector2(200, 200), p2 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 200, 200), p3 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 400, Graphics.GraphicsDevice.Viewport.Height - 200), p4 = new Vector2(Graphics.GraphicsDevice.Viewport.Width / 2, Graphics.GraphicsDevice.Viewport.Height), p5 = new Vector2(200, Graphics.GraphicsDevice.Viewport.Height - 200), p6 = new Vector2(100, Graphics.GraphicsDevice.Viewport.Height / 2), p7 = new Vector2(Graphics.GraphicsDevice.Viewport.Width / 2, 300); List <Vector2> points = new List <Vector2>(); /*points.AddRange(Geometry.CreateCatmullCurve(p6, p1, p2, p3, true, 1f)); * points.AddRange(Geometry.CreateCatmullCurve(p1, p2, p3, p4, true, 1f)); * points.AddRange(Geometry.CreateCatmullCurve(p2, p3, p4, p5, true, 1f)); * points.AddRange(Geometry.CreateCatmullCurve(p3, p4, p5, p6, true, 1f)); * points.AddRange(Geometry.CreateCatmullCurve(p4, p5, p6, p1, true, 1f)); * points.AddRange(Geometry.CreateCatmullCurve(p5, p6, p1, p2, true, 1f));*/ /*List<Vector2> points = new List<Vector2>(Geometry.CreateCatmullCurve(p5, p6, p1, p2, true)); * points.Insert(0, p5); * points.Insert(0, p4); * points.Insert(0, p3);*/ //new Polygon(points.ToArray()); //new Polygon(Geometry.CreateBlob(1f, p1, p2, p3, p4, p5, p6)); //new CatmullRomPolygon(1f, p1, p7, p2, p3, p4, p5, p6); Vector2 point1 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 250, Graphics.GraphicsDevice.Viewport.Height - 100), point2 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 175, Graphics.GraphicsDevice.Viewport.Height - 250), point3 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 150, Graphics.GraphicsDevice.Viewport.Height - 200); //new Polygon(point1, point2, point3); //List<Vector2> points = new List<Vector2>(Geometry.CreateHalfCircle(point2, point3, true)); points = new List <Vector2>(Geometry.CreateCatmullCurve(point1, point2, point3, point1, 2f)); points.Insert(0, point2); points.Insert(0, point1); //points.Insert(0, point3); //new Polygon(points.ToArray()); //new CatmullRomPolygon(.5f, new Vector2(0, Graphics.GraphicsDevice.Viewport.Height - 400), new Vector2(0, Graphics.GraphicsDevice.Viewport.Height), new Vector2(220, Graphics.GraphicsDevice.Viewport.Height), new Vector2(220, Graphics.GraphicsDevice.Viewport.Height - 400)); int xx = Graphics.GraphicsDevice.Viewport.Width / 2, yy = Graphics.GraphicsDevice.Viewport.Height / 2; //new CatmullRomPolygon(1f, new Vector2(xx, yy), new Vector2(xx + 100, yy), new Vector2(xx + 100, yy + 100), new Vector2(xx, yy + 100)); yy = Graphics.GraphicsDevice.Viewport.Height / 4; //new CatmullRomPolygon(1f, new Vector2(xx - 50, yy - 50), new Vector2(xx + 25, yy + 50), new Vector2(xx + 50, yy), new Vector2(xx + 100, yy), new Vector2(xx + 125, yy + 50), new Vector2(xx + 200, yy - 50), new Vector2(xx + 100, yy - 100)); base.Initialize(); }
protected override void Initialize() { // TODO: Add your initialization logic here ballTexture = Content.Load<Texture2D>("blackcircle"); redTexture = Content.Load<Texture2D>("red"); font1 = Content.Load<SpriteFont>("font1"); line = new PrimitiveLine(Graphics.GraphicsDevice, 1); line.Colour = Color.Black; Grid = new Grid(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, (int)(ballSize * 1.1f)); makeBalls(); //new Polygon(new Vector2(200, 200), new Vector2(700, 150), new Vector2(800, 500), new Vector2(400, 500), new Vector2(500, 300)); /*new Polygon(new Vector2(200, 200), new Vector2(Graphics.GraphicsDevice.Viewport.Width - 200, 200), new Vector2(Graphics.GraphicsDevice.Viewport.Width - 400, Graphics.GraphicsDevice.Viewport.Height - 200), new Vector2(Graphics.GraphicsDevice.Viewport.Width / 2, Graphics.GraphicsDevice.Viewport.Height), new Vector2(200, Graphics.GraphicsDevice.Viewport.Height - 200), new Vector2(100, Graphics.GraphicsDevice.Viewport.Height / 2));*/ Vector2 p1 = new Vector2(200, 200), p2 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 200, 200), p3 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 400, Graphics.GraphicsDevice.Viewport.Height - 200), p4 = new Vector2(Graphics.GraphicsDevice.Viewport.Width / 2, Graphics.GraphicsDevice.Viewport.Height), p5 = new Vector2(200, Graphics.GraphicsDevice.Viewport.Height - 200), p6 = new Vector2(100, Graphics.GraphicsDevice.Viewport.Height / 2), p7 = new Vector2(Graphics.GraphicsDevice.Viewport.Width / 2, 300); List<Vector2> points = new List<Vector2>(); /*points.AddRange(Geometry.CreateCatmullCurve(p6, p1, p2, p3, true, 1f)); points.AddRange(Geometry.CreateCatmullCurve(p1, p2, p3, p4, true, 1f)); points.AddRange(Geometry.CreateCatmullCurve(p2, p3, p4, p5, true, 1f)); points.AddRange(Geometry.CreateCatmullCurve(p3, p4, p5, p6, true, 1f)); points.AddRange(Geometry.CreateCatmullCurve(p4, p5, p6, p1, true, 1f)); points.AddRange(Geometry.CreateCatmullCurve(p5, p6, p1, p2, true, 1f));*/ /*List<Vector2> points = new List<Vector2>(Geometry.CreateCatmullCurve(p5, p6, p1, p2, true)); points.Insert(0, p5); points.Insert(0, p4); points.Insert(0, p3);*/ //new Polygon(points.ToArray()); //new Polygon(Geometry.CreateBlob(1f, p1, p2, p3, p4, p5, p6)); //new CatmullRomPolygon(1f, p1, p7, p2, p3, p4, p5, p6); Vector2 point1 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 250, Graphics.GraphicsDevice.Viewport.Height - 100), point2 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 175, Graphics.GraphicsDevice.Viewport.Height - 250), point3 = new Vector2(Graphics.GraphicsDevice.Viewport.Width - 150, Graphics.GraphicsDevice.Viewport.Height - 200); //new Polygon(point1, point2, point3); //List<Vector2> points = new List<Vector2>(Geometry.CreateHalfCircle(point2, point3, true)); points = new List<Vector2>(Geometry.CreateCatmullCurve(point1, point2, point3, point1, 2f)); points.Insert(0, point2); points.Insert(0, point1); //points.Insert(0, point3); //new Polygon(points.ToArray()); //new CatmullRomPolygon(.5f, new Vector2(0, Graphics.GraphicsDevice.Viewport.Height - 400), new Vector2(0, Graphics.GraphicsDevice.Viewport.Height), new Vector2(220, Graphics.GraphicsDevice.Viewport.Height), new Vector2(220, Graphics.GraphicsDevice.Viewport.Height - 400)); int xx = Graphics.GraphicsDevice.Viewport.Width / 2, yy = Graphics.GraphicsDevice.Viewport.Height / 2; //new CatmullRomPolygon(1f, new Vector2(xx, yy), new Vector2(xx + 100, yy), new Vector2(xx + 100, yy + 100), new Vector2(xx, yy + 100)); yy = Graphics.GraphicsDevice.Viewport.Height / 4; //new CatmullRomPolygon(1f, new Vector2(xx - 50, yy - 50), new Vector2(xx + 25, yy + 50), new Vector2(xx + 50, yy), new Vector2(xx + 100, yy), new Vector2(xx + 125, yy + 50), new Vector2(xx + 200, yy - 50), new Vector2(xx + 100, yy - 100)); base.Initialize(); }
/*Polygon(Vector2 p1, Vector2 p2, params Vector2[] vertices) { Polygons.Add(this); if (p1.X < p2.X) { MinX = p1.X; MaxX = p2.X; } else { MinX = p2.X; MaxX = p1.X; } if (p1.Y < p2.Y) { MinY = p1.Y; MaxY = p2.Y; } else { MinY = p2.Y; MaxY = p1.Y; } this.vertices.Add(p1); this.vertices.Add(p2); foreach (Vector2 vertex in vertices) { this.vertices.Add(vertex); if (vertex.X < MinX) MinX = vertex.X; else if (vertex.X > MaxX) MaxX = vertex.X; if (vertex.Y < MinY) MinY = vertex.Y; else if (vertex.Y > MaxY) MaxY = vertex.Y; } for (int i = 0; i < this.vertices.Count; i++) { if (i < this.vertices.Count - 1) { sides.Add(new LineSegment(this.vertices[i], this.vertices[i + 1])); } else { sides.Add(new LineSegment(this.vertices[i], p1)); } } epsilon = (MaxX - MinX) / 100f; line = new PrimitiveLine(Game1.Graphics.GraphicsDevice, 1); line.Colour = Color.White; }*/ /*public Polygon(Vector2 p1, Vector2 p2, params Vector2[] vertices) { Polygons.Add(this); if (p1.X < p2.X) { MinX = p1.X; MaxX = p2.X; } else { MinX = p2.X; MaxX = p1.X; } if (p1.Y < p2.Y) { MinY = p1.Y; MaxY = p2.Y; } else { MinY = p2.Y; MaxY = p1.Y; } this.vertices.Add(p1); this.vertices.Add(p2); foreach (Vector2 vertex in vertices) { this.vertices.Add(vertex); if (vertex.X < MinX) MinX = vertex.X; else if (vertex.X > MaxX) MaxX = vertex.X; if (vertex.Y < MinY) MinY = vertex.Y; else if (vertex.Y > MaxY) MaxY = vertex.Y; } for (int i = 0; i < this.vertices.Count; i++) { if (i < this.vertices.Count - 1) { sides.Add(new LineSegment(this.vertices[i], this.vertices[i + 1])); } else { sides.Add(new LineSegment(this.vertices[i], p1)); } } epsilon = (MaxX - MinX) / 100f; CenterPoint = new Vector2((MinX + MaxX) / 2, (MinY + MaxY) / 2); line = new PrimitiveLine(Game1.Graphics.GraphicsDevice, 1); line.Colour = Color.White; }*/ public Polygon(params Vector2[] vertices) { if (vertices.Length < 3) throw new Exception("inside Polygon constructor: must have at least 3 vertices"); Polygons.Add(this); MinX = MaxX = vertices[0].X; MinY = MaxY = vertices[0].Y; foreach (Vector2 vertex in vertices) { this.vertices.Add(vertex); if (vertex.X < MinX) MinX = vertex.X; else if (vertex.X > MaxX) MaxX = vertex.X; if (vertex.Y < MinY) MinY = vertex.Y; else if (vertex.Y > MaxY) MaxY = vertex.Y; } for (int i = 0; i < this.vertices.Count; i++) { if (i < this.vertices.Count - 1) { sides.Add(new LineSegment(this.vertices[i], this.vertices[i + 1])); } else { sides.Add(new LineSegment(this.vertices[i], this.vertices[0])); } } epsilon = (MaxX - MinX) / 100f; CenterPoint = new Vector2((MinX + MaxX) / 2, (MinY + MaxY) / 2); line = new PrimitiveLine(Game1.Graphics.GraphicsDevice, 1); line.Colour = Color.White; initializeOccupiedGridNodes(); }