private static PolygonSave ConvertTmxObjectToFrbPolygonSave(this TiledMapSave tiledMapSave, string name, double x, double y, double w, double h, double rotation, mapObjectgroupObjectEllipse ellipse) { var pointsSb = new StringBuilder(); if (ellipse == null) { pointsSb.AppendFormat("{0},{1}", -w / 2, -h / 2); pointsSb.AppendFormat(" {0},{1}", w / 2, -h / 2); pointsSb.AppendFormat(" {0},{1}", w / 2, h / 2); pointsSb.AppendFormat(" {0},{1}", -w / 2, h / 2); } else { const double a = .5; const double b = .5; // x = a cos t // y = b cos t var first = true; string firstPoint = ""; for (var angle = 0; angle <= 360; angle += 18) { var radians = MathHelper.ToRadians(angle); // This code made the position of the poly be top left, not optimized! //var newx = a*Math.Cos(radians)*w+w/2; //var newy = b*Math.Sin(radians)*h+h/2; var newx = a * Math.Cos(radians) * w; var newy = b * Math.Sin(radians) * h; if (first) { firstPoint = string.Format("{0},{1}", newx, newy); } pointsSb.AppendFormat("{2}{0},{1}", newx, newy, first ? "" : " "); first = false; } pointsSb.AppendFormat(" {0}", firstPoint); } return(tiledMapSave.ConvertTmxObjectToFrbPolygonSave(name, x + w / 2.0f, y + h / 2.0f, rotation, pointsSb.ToString(), true)); }
private static PolygonSave ConvertTmxObjectToFrbPolygonSave(this TiledMapSave tiledMapSave, string name, double x, double y, double w, double h, double rotation, mapObjectgroupObjectEllipse ellipse) { var pointsSb = new StringBuilder(); if (ellipse == null) { pointsSb.Append("0,0"); pointsSb.AppendFormat(" {0},{1}", w, 0); pointsSb.AppendFormat(" {0},{1}", w, h); pointsSb.AppendFormat(" {0},{1}", 0, h); } else { const double a = .5; const double b = .5; // x = a cos t // y = b cos t var first = true; string firstPoint = ""; for (var angle = 0; angle <= 360; angle += 18) { var radians = MathHelper.ToRadians(angle); var newx = a*Math.Cos(radians)*w+w/2; var newy = b*Math.Sin(radians)*h+h/2; if (first) { firstPoint = string.Format("{0},{1}", newx, newy); } pointsSb.AppendFormat("{2}{0},{1}", newx, newy, first ? "" : " "); first = false; } pointsSb.AppendFormat(" {0}", firstPoint); } return tiledMapSave.ConvertTmxObjectToFrbPolygonSave(name, x, y, rotation, pointsSb.ToString(), true); }