private static void CreateCircle() { Drawable.Drawables.Remove(circleLine); float radius = Math.Max(MapDimensions.X, MapDimensions.Z); double theta = 2.0f * Math.PI * 0 / CIRCLE_SEGMENTS; Vector3[] polygons = new Vector3[CIRCLE_SEGMENTS]; for (int i = 0; i < CIRCLE_SEGMENTS; i++) { theta = 2.0f * Math.PI * i / CIRCLE_SEGMENTS; float x = radius * (float)Math.Cos(theta); float z = radius * (float)Math.Sin(theta); polygons[i] = new Vector3(x, 0, z); } circleLine = new LineLoop(polygons, COLOR_CIRCLE, 2); }
private static void CreateGrid(bool polar = false) { Drawable.Drawables = Drawable.Drawables.Except(gridLines).ToList(); gridLines.Clear(); if (!polar) { for (float x = -MapDimensions.X; x <= MapDimensions.X; x += MapDimensions.X / 20) { Vector3 start = new Vector3(x, 0, -MapDimensions.Z); Vector3 end = new Vector3(x, 0, MapDimensions.Z); Line line = new Line(start, end, COLOR_GRID); gridLines.Add(line); } for (float z = -MapDimensions.Z; z <= MapDimensions.Z; z += MapDimensions.Z / 20) { Vector3 start = new Vector3(-MapDimensions.X, 0, z); Vector3 end = new Vector3(MapDimensions.X, 0, z); Line line = new Line(start, end, COLOR_GRID); gridLines.Add(line); } } else { float radius = Math.Max(MapDimensions.X, MapDimensions.Z); //Lines double angleDelta = Math.PI / POLAR_LINES; double angle = 0; float width = 1; for (int i = 0; i < POLAR_LINES; i++) { float startX = (float)Math.Cos(angle) * radius; float startZ = (float)Math.Sin(angle) * radius; Vector3 start = new Vector3(startX, 0, startZ); float endX = (float)Math.Cos(angle + Math.PI) * radius; float endZ = (float)Math.Sin(angle + Math.PI) * radius; Vector3 end = new Vector3(endX, 0, endZ); if (i == 0 || i == POLAR_LINES / 2) { width = 1.6f; } else { width = 1; } Line line = new Line(start, end, COLOR_GRID, width); gridLines.Add(line); angle += angleDelta; } //Circles float circleRadius = 0; float circleRadiusDelta = radius / POLAR_CIRCLES; for (int n = 0; n < POLAR_CIRCLES; n++) { double theta = 0; Vector3[] polygons = new Vector3[POLAR_CIRCLE_SEGMENTS]; for (int i = 0; i < POLAR_CIRCLE_SEGMENTS; i++) { theta = 2.0f * Math.PI * i / POLAR_CIRCLE_SEGMENTS; float x = circleRadius * (float)Math.Cos(theta); float z = circleRadius * (float)Math.Sin(theta); polygons[i] = new Vector3(x, 0, z); } LineLoop line = new LineLoop(polygons, COLOR_GRID); gridLines.Add(line); circleRadius += circleRadiusDelta; } } }