private bool MakeOneVertexRow(int RowIndex, int HowMany, double Latitude) { try { VertexRows[RowIndex] = new VertexRow(); VertexRows[RowIndex].Row = new LatLongPosition[HowMany]; VertexRows[RowIndex].RowLast = HowMany; double LatRadians = NumbersEC.DegreesToRadians(Latitude); double CosLatRadians = Math.Cos(LatRadians); double SinLatRadians = Math.Sin(LatRadians); double LonStart = -180.0; // There is a beginning vertex at -180 longitude // and there is an ending vertex at 180 // longitude, which is the same place, but they // are associated with different texture // coordinates. One at the left end of the // texture and one at the right end. // So this is minus 1: double LonDelta = 360.0d / (double)(HowMany - 1); for (int Count = 0; Count < HowMany; Count++) { LatLongPosition Pos = new LatLongPosition(); Pos.Latitude = Latitude; // The sine and cosine of this longitude could // be saved in an array for the next row of // equal size. (Like 1024 vertexes or what // ever.) Pos.Longitude = LonStart + (LonDelta * Count); Pos.Index = LastVertexIndex; LastVertexIndex++; SetLatLonPositionXYZ(ref Pos, CosLatRadians, SinLatRadians); VertexRows[RowIndex].Row[Count] = Pos; AddSurfaceVertex(Pos); } return(true); } catch (Exception Except) { ShowStatus("Exception in PlanetSphere.MakeSphericalModel(): " + Except.Message); return(false); } }
private void MakeSphericalModel() { try { Surface = new MeshGeometry3D(); LastVertexIndex = 0; VertexRowsLast = 20 - 1; int VertexRowsMiddle = 9; VertexRows = new VertexRow[VertexRowsLast]; LatLongPosition PosNorthPole = new LatLongPosition(); PosNorthPole.Latitude = 90.0; PosNorthPole.Longitude = 0; PosNorthPole.Index = LastVertexIndex; LastVertexIndex++; double LatRadians = NumbersEC.DegreesToRadians(PosNorthPole.Latitude); double CosLatRadians = Math.Cos(LatRadians); double SinLatRadians = Math.Sin(LatRadians); SetLatLonPositionXYZ(ref PosNorthPole, CosLatRadians, SinLatRadians); LatLongPosition PosSouthPole = new LatLongPosition(); PosSouthPole.Latitude = -90.0; PosSouthPole.Longitude = 0; PosSouthPole.Index = LastVertexIndex; LastVertexIndex++; LatRadians = NumbersEC.DegreesToRadians(PosSouthPole.Latitude); CosLatRadians = Math.Cos(LatRadians); SinLatRadians = Math.Sin(LatRadians); SetLatLonPositionXYZ(ref PosSouthPole, CosLatRadians, SinLatRadians); VertexRows[0] = new VertexRow(); VertexRows[0].Row = new LatLongPosition[1]; VertexRows[0].RowLast = 1; VertexRows[0].Row[0] = PosNorthPole; AddSurfaceVertex(PosNorthPole); VertexRows[VertexRowsLast - 1] = new VertexRow(); VertexRows[VertexRowsLast - 1].Row = new LatLongPosition[1]; VertexRows[VertexRowsLast - 1].RowLast = 1; VertexRows[VertexRowsLast - 1].Row[0] = PosSouthPole; AddSurfaceVertex(PosSouthPole); double RowLatitude = 90; double RowLatDelta = 10; int MaximumVertexes = 64; int HowMany = 4; for (int Index = 1; Index <= VertexRowsMiddle; Index++) { RowLatitude -= RowLatDelta; MakeOneVertexRow(Index, HowMany, RowLatitude); if (HowMany < MaximumVertexes) { HowMany = HowMany * 2; } } RowLatitude = -90; HowMany = 4; for (int Index = VertexRowsLast - 2; Index > VertexRowsMiddle; Index--) { RowLatitude += RowLatDelta; MakeOneVertexRow(Index, HowMany, RowLatitude); if (HowMany < MaximumVertexes) { HowMany = HowMany * 2; } } MakePoleTriangles(); for (int Index = 0; Index < VertexRowsLast - 2; Index++) { if (VertexRows[Index].RowLast == VertexRows[Index + 1].RowLast) { MakeRowTriangles(Index, Index + 1); } else { if (VertexRows[Index].RowLast < VertexRows[Index + 1].RowLast) { MakeDoubleRowTriangles(Index, Index + 1); } else { MakeDoubleReverseRowTriangles(Index + 1, Index); } } } FreeVertexRows(); } catch (Exception Except) { ShowStatus("Exception in PlanetSphere.MakeSphericalModel(): " + Except.Message); } }