public void DrawLine(FPoint point1, FPoint point2, Color color, float thickness = 1f) { var distance = FPoint.Distance(point1, point2); var angle = FloatMath.Atan2(point2.Y - point1.Y, point2.X - point1.X); DrawLine(point1, distance, angle, color, thickness); }
//----------------------------------------------------------------------------------------------- public Waypoint(FPoint fp, Waypoint parent, bool done) { this.type = WaypointType.Normal; this.done = done; this.parent = parent; this.fp = fp.Clone(); if (parent == null) { G = 0; } else { G = parent.G + fp.Distance(parent.fp); } H = fp.Distance(fp_dst); F = G + H; }
void PushVertexWaypoint(FPoint fp, int fp_idx, Waypoint parent) //凭借fp_idx可以判断done标志 { //在Close表中,退出 if (close.IsContainsPos(fp)) { return; } //在Open表中否? Waypoint w = open.GetWaypointFromXY(fp); if (w != null) { //在Open表中,可优化否? float d = fp.Distance(parent.fp); if (w.G > parent.G + d) //可优化 { open.Delete(w); w.parent = parent; w.G = parent.G + d; w.F = w.G + w.H; open.Add(w); } } else { //不在Open表中 int y_idx = (int)(fp.y / 64); int x_idx = (int)(fp.x / 64); Grid grid = topo.grids[y_idx, x_idx]; bool done = false; foreach (int idx in dst_fpidx) //会不会慢?... { if (fp_idx == idx) { done = true; break; } } w = new VertexWaypoint(fp, parent, grid, done); open.Add(w); } }
private void DrawPolygonEdge(TextureRegion2D texture, FPoint point1, FPoint point2, Color color, float thickness) { #if DEBUG IncRenderSpriteCount(); #endif var length = FPoint.Distance(point1, point2); var angle = FloatMath.Atan2(point2.Y - point1.Y, point2.X - point1.X); var scale = new Vector2(length, thickness); internalBatch.Draw( texture: texture.Texture, position: point1.ToVec2D(), sourceRectangle: texture.Bounds, color: color, rotation: angle, scale: scale); }
//=============================================================================================== void PushEdgeWaypoint(FPoint fp, Border border, Waypoint parent) //凭借border可以判断done标志 { //在Close表中,退出 if (close.IsContainsPos(fp)) { return; } //在Open表中否? Waypoint w = open.GetWaypointFromXY(fp); if (w != null) { //在Open表中,可优化否? float d = fp.Distance(parent.fp); if (w.G > parent.G + d) //可优化 { open.Delete(w); w.parent = parent; w.G = parent.G + d; w.F = w.G + w.H; open.Add(w); } } else { //不在Open表中 int p1 = border.belong_poly; int p2 = border.neighbor_poly; Polygon po1 = (p1 == -1) ? null : polys[p1]; Polygon po2 = (p2 == -1) ? null : polys[p2]; bool done = (po1 == dst_poly || po2 == dst_poly) ? true : false; w = new EdgeWaypoint(fp, parent, border, done); open.Add(w); } }