public PlanetSector(string name, PlanetCoord bl, PlanetCoord tr, PlanetCoord th = null) { _Name = name; _BL = bl; _TR = tr; _TH = th; }
public void GeneratePlanetModel() { double quartIncrement = (_Circumference / 4) / 1000; // Number of increments in a quarter of the circumference double Diff = (_Radius / quartIncrement); // Count of quarters completed in the circle Console.WriteLine("Radius is: " + _Radius + " metres, Circumference is: " + _Circumference + " metres."); PlanetCoord[] bef = new PlanetCoord[((int)_Circumference / 1000) + 1]; PlanetCoord[] aft = new PlanetCoord[((int)_Circumference / 1000) + 1]; int xIter = 0; int yIter = 0; CircumferenceLoop(1, ref xIter, ref yIter, ref bef, ref aft, Diff, Diff, 0, -1, -1, 0, 0, _Radius); }
// SMELL: Copy-pasted code, fix up public void CircumferenceLoop(int calledCount, ref int xIter, ref int yIter, ref PlanetCoord[] b, ref PlanetCoord[] a, double xdiff = 0, double ydiff = 0, double zdiff = 0, double xpol = 0, double ypol = 0, double zpol = 0, double xorigin = 0, double yorigin = 0, double zorigin = 0) { PlanetCoord cOrigin = new PlanetCoord(xorigin, yorigin, zorigin); // Located at the "origin" of the circumference PlanetCoord iter = cOrigin; PlanetCoord sBottom = new PlanetCoord(0, 0, -_Radius); PlanetCoord sTop = new PlanetCoord(0, 0, _Radius); int aIter = 0; int incrementsTotal = (int)_Circumference / 1000; int incrementsCount = 1; int increments2Count = 1; int qCount = 1; // Count of quarters completed in the circle double iterZ; // Temp variable for Z-axis loop double xDiff = xdiff * xpol; double yDiff = ydiff * ypol; double zDiff = zdiff * zpol; // Need to do all this stuff for the first iteration of the XY loop if (calledCount == 1) { iter = new PlanetCoord(iter._PlanetX, iter._PlanetY, iter._PlanetZ); // TODO: Fix issue with index out of bounds //this._PlanetCoords[incrementsCount, increments2Count] = iter; double xDiff2 = iter._PlanetX / (incrementsTotal / 4); double yDiff2 = iter._PlanetY / (incrementsTotal / 4); double zDiff2 = xdiff; CircumferenceLoop(calledCount - 1, ref xIter, ref yIter, ref a, ref b, xDiff2, yDiff2, zDiff2, -1, -1, 1, iter._PlanetX, iter._PlanetY, iter._PlanetZ); yIter = 0; xIter++; b = a; a = new PlanetCoord[((int)_Circumference / 1000)]; Console.WriteLine("XY Circumference at x = " + iter._PlanetX + ", y = " + iter._PlanetY + ", z = " + iter._PlanetZ + ", " + incrementsCount + " / " + incrementsTotal + " increments complete!"); incrementsCount++; } else { iter = new PlanetCoord(iter._PlanetX, iter._PlanetY, iter._PlanetZ); // TODO: Fix issue with index out of bounds //this._PlanetCoords[incrementsCount, increments2Count] = iter; ///Console.WriteLine("Z Circumference for x = " + iter._PlanetX + ", y = " + iter._PlanetY + ", z = " + iter._PlanetZ + ", " + increments2Count + " / " + incrementsTotal + "increments complete!"); if (b[0] == default(PlanetCoord)) { a[aIter] = iter; } else { a[aIter] = iter; _PlanetSectors[xIter, yIter] = new PlanetSector("a", b[(int)_Circumference / 1000], a[aIter]); _PlanetSectors[xIter, yIter].ToString(); yIter++; } aIter++; increments2Count++; } for (int i = 0; i < incrementsTotal; i++) { // Checks if reached a new quarter of the circle and reverses the sign of either the xDiff or yDiff if (i == (incrementsTotal / 4) || i == (incrementsTotal / 2) || i == (3 * (incrementsTotal / 4))) { if (calledCount == 1) { if (i == (incrementsTotal / 4) || i == (3 * (incrementsTotal / 4))) { xDiff = xDiff * -1; } else if (i == (incrementsTotal / 2)) { yDiff = yDiff * -1; } } else { if (i == (incrementsTotal / 4) || i == (3 * (incrementsTotal / 4))) { //xDiff = xDiff * -1; //yDiff = yDiff * -1; zDiff = zDiff * -1; } else if (i == (incrementsTotal / 2)) { xDiff = xDiff * -1; yDiff = yDiff * -1; } } qCount++; } if (((iter._PlanetX + xDiff) >= (-20) && (iter._PlanetX + xDiff) <= (20)) && ((iter._PlanetY + yDiff) >= (-20) && (iter._PlanetY + yDiff) <= (20)) && (calledCount == 0)) { if ((iter._PlanetZ + zDiff) > 0) { iter = sTop; } else { iter = sBottom; } } else if (((iter._PlanetX + xDiff) >= (-20) && (iter._PlanetX + xDiff) <= (20)) && (calledCount == 1)) { iter = new PlanetCoord(0, iter._PlanetY + yDiff, iter._PlanetZ + zDiff); } else if (((iter._PlanetY + yDiff) >= (-20) && (iter._PlanetY + yDiff) <= (20)) && (calledCount == 1)) { iter = new PlanetCoord(iter._PlanetX + yDiff, 0, iter._PlanetZ + zDiff); } else { if ((iter._PlanetZ + zDiff) >= (-20) && (iter._PlanetZ + zDiff) <= (20)) { iterZ = 0; } else { iterZ = iter._PlanetZ + zDiff; } iter = new PlanetCoord(iter._PlanetX + xDiff, iter._PlanetY + yDiff, iterZ); } // Assignment to PlanetSector array // TODO: Figure out better naming scheme for planet sectors if (calledCount == 0) { a[aIter] = iter; if (b[((int)_Circumference / 1000)] != default(PlanetCoord)) { if (iter._PlanetZ == _Radius || iter._PlanetZ == -_Radius) { // TODO: This requires separate cases for the top and bottom of the sphere. Also there should be two sectors at the top/bottom, one on either side _PlanetSectors[xIter, yIter] = new PlanetSector("a", b[aIter - 1], a[aIter], a[aIter - 1]); _PlanetSectors[xIter, yIter].ToString(); yIter++; } else { _PlanetSectors[xIter, yIter] = new PlanetSector("a", b[aIter - 1], a[aIter]); _PlanetSectors[xIter, yIter].ToString(); yIter++; } } aIter++; } if ((iter._PlanetX > (cOrigin._PlanetX - 10)) && (iter._PlanetY == cOrigin._PlanetY) && (calledCount == 1)) { break; } else if ((iter._PlanetZ > (cOrigin._PlanetZ - 10)) && (iter._PlanetX == cOrigin._PlanetX) && (iter._PlanetY == cOrigin._PlanetY) && (calledCount == 0)) { break; } else { // TODO: Fix issue with index out of bounds <-- SCRAP THIS: Instead assign bottom-left, top-right coordinate pairs to a "sector array", like sector of land or something. // ... the array should go from the bottom of the circle to the top, mapping around the circles, USE 2D ARRAYS SINCE NUMBER OF SECTORS PER-LEVEL MIGHT DIFFER AS YOU GO UP THE SPHERE i.e. [x_0 -> x_max], [lowest_sector -> highest_sector] //this._PlanetCoords[incrementsCount, increments2Count] = iter; if (calledCount == 1) { double xDiff2 = iter._PlanetX / (incrementsTotal / 4); double yDiff2 = iter._PlanetY / (incrementsTotal / 4); double zDiff2 = xdiff; CircumferenceLoop(calledCount - 1, ref xIter, ref yIter, ref b, ref a, xDiff2, yDiff2, zDiff2, -1, -1, 1, iter._PlanetX, iter._PlanetY, iter._PlanetZ); b = a; } } if (calledCount == 1) { Console.WriteLine("XY Circumference at x = " + iter._PlanetX + ", y = " + iter._PlanetY + ", z = " + iter._PlanetZ + ", " + incrementsCount + " / " + incrementsTotal + " increments complete!"); if ((incrementsCount == incrementsTotal / 4) || (incrementsCount == incrementsTotal / 2) || (incrementsCount == (3 * (incrementsTotal / 4))) || (incrementsCount == incrementsTotal)) { Console.WriteLine((incrementsCount / (incrementsTotal / 4)) + " XY-quarter(s) complete"); } incrementsCount++; } else { //Console.WriteLine("Z Circumference for x = " + iter._PlanetX + ", y = " + iter._PlanetY + ", z = " + iter._PlanetZ + ", " + increments2Count + " / " + incrementsTotal + "increments complete!"); if ((increments2Count == incrementsTotal / 4) || (increments2Count == incrementsTotal / 2) || (increments2Count == (3 * (incrementsTotal / 4))) || (increments2Count == incrementsTotal)) { //Console.WriteLine((increments2Count / (incrementsTotal / 4)) + " Z-quarter(s) complete"); increments2Count++; } } } }