public static void InitStarVertexBuffer(RenderContext renderContext) { if (!starsDownloading) { GetStarFile("http://www.worldwidetelescope.org/wwtweb/catalog.aspx?Q=hipparcos"); starsDownloading = true; } if (starSprites == null && starCount > 0) { double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI; int count = stars.Count; starCount = count; starSprites = new PointList(renderContext); starSprites.DepthBuffered = false; foreach (Star star in stars) { Vector3d pos = Coordinates.RADecTo3dAu(star.RA, star.Dec, star.Distance); pos.RotateX(ecliptic); star.Position = pos; double radDec = (1200000) / Math.Pow(1.6, star.AbsoluteMagnitude); starSprites.AddPoint(pos, star.Col, new Dates(0, 1), (float)radDec * 100); } } }
private static void MakePrecessionChart() { double obliquity = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow); Matrix3d mat = Matrix3d.RotationX((obliquity / 360.0 * (Math.PI * 2))); Color col = Colors.White; if (precLineList == null) { precLineList = new SimpleLineList(); precLineList.DepthBuffered = false; for (double l = 0; l < 360; l++) { double b = 90 - obliquity; precLineList.AddLine(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, b, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu((l + 1) / 15, b, 1), mat)); } for (double l = -12000; l < 13000; l += 2000) { double b = 90 - obliquity; double p = -((l - 2000) / 25772 * 24) - 6; precLineList.AddLine(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(p, b - .5, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(p, b + .5, 1), mat)); } } if (PrecTextBatch == null) { PrecTextBatch = new Text3dBatch(50); int index = 0; for (double l = -12000; l < 13000; l += 2000) { double b = 90 - obliquity + 3; double p = -((l - 2000) / 25772 * 24) - 6; string text = l.ToString(); if (l == 0) { b = 90 - obliquity + 2; text = "1 CE"; } else if (l < 0) { text = " " + (Math.Abs(l).ToString()) + " BCE"; } else { text = (Math.Abs(l).ToString()) + " CE"; } if (text.Length == 9) { text = " " + text; } PrecTextBatch.Add(new Text3d(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(p, b, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(p + .01, b, 1), mat), text, 75, .00015)); } } return; }
private static void MakeEclipticGridText() { Color drawColor = Colors.White; double obliquity = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow); Matrix3d mat = Matrix3d.RotationX((float)(-obliquity / 360.0 * (Math.PI * 2))); if (EclipticTextBatch == null) { EclipticTextBatch = new Text3dBatch(30); for (double l = 0; l < 360; l += 10) { string text = " " + l.ToString(); if (l < 10) { text = " " + l.ToString(); } else if (l < 100) { text = " " + l.ToString(); } EclipticTextBatch.Add(new Text3d(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, .4, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, .5, 1), mat), text, 75, .00018)); } for (double l = 0; l < 360; l += 90) { for (double b = -80; b <= 80; b += 10) { if (b == 0) { continue; } string text = b.ToString(); if (b > 0) { text = " +" + b.ToString(); EclipticTextBatch.Add(new Text3d(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, b - .4, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, b - .3, 1), mat), text, 75, .00018)); } else { text = " - " + text.Substr(1); EclipticTextBatch.Add(new Text3d(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, b + .4, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, b + .5, 1), mat), text, 75, .00018)); } } } } return; }
private static void CreateCosmosVertexBuffer(RenderContext renderContext) { GL device = Tile.PrepDevice; int bucketCount = 256; if (cosmosSprites != null) { for (int ij = 0; ij < bucketCount; ij++) { if (cosmosSprites[ij] != null) { cosmosSprites[ij] = null; } } } cosmosSprites = null; double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI; cosmosSprites = new PointList[bucketCount]; int[] indexList = new int[bucketCount]; for (int i = 0; i < bucketCount; i++) { int count = galaxyVertexCounts[i]; cosmosSprites[i] = new PointList(renderContext); cosmosSprites[i].DepthBuffered = false; indexList[i] = 0; } foreach (Galaxy galaxy in cosmos) { int bucket = galaxy.eTypeBucket; int index = indexList[bucket]; Vector3d pos = Coordinates.RADecTo3dAu(galaxy.RA, galaxy.Dec, (galaxy.Distance * UiTools.AuPerParsec * 1000000.0) / .73); pos.RotateX(ecliptic); galaxy.Position = pos; cosmosSprites[bucket].AddPoint(pos, Colors.White, new Dates(0, 1), (float)(1000000000f * galaxy.Size * 100)); indexList[bucket]++; } cosmosReady = true; }
private static void MakeEclipticText() { int year = SpaceTimeController.Now.GetUTCFullYear(); if (EclipOvTextBatch == null) { EclipOvTextBatch = new Text3dBatch(80); EclipticTextYear = year; double obliquity = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow); Matrix3d mat = Matrix3d.RotationX((-obliquity / 360.0 * (Math.PI * 2))); double daysPerYear = 365.25; if (DT.IsLeap(year, true)) { monthDays[1] = 29; daysPerYear = 366; } else { monthDays[1] = 28; daysPerYear = 365; } int count = 2 * (int)daysPerYear; EclipticCount = (int)daysPerYear; double jYear = SpaceTimeController.UtcToJulian(new Date(year, 0, 1, 12, 0, 0)); int index = 0; double d = 0; for (int m = 0; m < 12; m++) { int daysThisMonth = (int)monthDays[m]; for (int i = 0; i < daysThisMonth; i++) { AstroRaDec sunRaDec = Planets.GetPlanetLocationJD("Sun", jYear); COR sunEcliptic = CT.Eq2Ec(sunRaDec.RA, sunRaDec.Dec, obliquity); d = sunEcliptic.X; double dd = d;// +180; if (i == Math.Floor(daysThisMonth / 2.0)) { Vector3d center = Vector3d.TransformCoordinate(Vector3d.Create((Math.Cos((dd * Math.PI * 2.0) / 360)), .025f, (Math.Sin((dd * Math.PI * 2.0) / 360))), mat); Vector3d up = Vector3d.TransformCoordinate(Vector3d.Create((Math.Cos((dd * Math.PI * 2.0) / 360)), .045f, (Math.Sin((dd * Math.PI * 2.0) / 360))), mat); up.Subtract(center); up.Normalize(); EclipOvTextBatch.Add(new Text3d(center, up, monthNames[m], 80, .000159375)); } index++; index++; jYear += 1; } d += monthDays[m]; } } }
public static bool DrawEcliptic(RenderContext renderContext, float opacity, Color drawColor) { Color col = drawColor; int year = SpaceTimeController.Now.GetUTCFullYear(); if (eclipticOverviewLineList == null || year != EclipticYear) { if (eclipticOverviewLineList != null) { eclipticOverviewLineList.Clear(); eclipticOverviewLineList = null; } EclipticYear = year; double obliquity = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow); Matrix3d mat = Matrix3d.RotationX((-obliquity / 360.0 * (Math.PI * 2))); double daysPerYear = 365.25; if (DT.IsLeap(year, true)) { monthDays[1] = 29; daysPerYear = 366; } else { monthDays[1] = 28; daysPerYear = 365; } int count = 2 * (int)daysPerYear; EclipticCount = (int)daysPerYear; double jYear = SpaceTimeController.UtcToJulian(new Date(year, 0, 1, 12, 0, 0)); int index = 0; double d = 0; eclipticOverviewLineList = new SimpleLineList(); eclipticOverviewLineList.DepthBuffered = false; for (int m = 0; m < 12; m++) { int daysThisMonth = (int)monthDays[m]; for (int i = 0; i < daysThisMonth; i++) { AstroRaDec sunRaDec = Planets.GetPlanetLocationJD("Sun", jYear); COR sunEcliptic = CT.Eq2Ec(sunRaDec.RA, sunRaDec.Dec, obliquity); d = sunEcliptic.X; double width = .005f; if (i == 0) { width = .01f; } double dd = d;// +180; eclipticOverviewLineList.AddLine( Vector3d.TransformCoordinate(Vector3d.Create((Math.Cos((dd * Math.PI * 2.0) / 360)), width, (Math.Sin((dd * Math.PI * 2.0) / 360))), mat), Vector3d.TransformCoordinate(Vector3d.Create((Math.Cos((dd * Math.PI * 2.0) / 360)), -width, (Math.Sin((dd * Math.PI * 2.0) / 360))), mat) ); index++; jYear += 1; } d += monthDays[m]; } } eclipticOverviewLineList.DrawLines(renderContext, opacity, drawColor); return(true); }
private static void CreateGalaxyImage(RenderContext renderContext) { if (milkyWayImage == null) { milkyWayImage = Planets.LoadPlanetTexture("http://cdn.worldwidetelescope.org/webclient/images/milkywaybar.jpg"); } int subdivs = 50; double lat, lng; int index = 0; double latMin = 64; double latMax = -64; double lngMin = -64; double lngMax = 64; //// Create a vertex buffer galaxyImageVertexBuffer = new PositionTextureVertexBuffer((subdivs + 1) * (subdivs + 1)); PositionTexture[] verts = (PositionTexture[])galaxyImageVertexBuffer.Lock(); int x1, y1; double latDegrees = latMax - latMin; double lngDegrees = lngMax - lngMin; double scaleFactor = 60800000.0; double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI; Vector3d point; double textureStepX = 1.0f / subdivs; double textureStepY = 1.0f / subdivs; for (y1 = 0; y1 <= subdivs; y1++) { if (y1 != subdivs) { lat = latMax - (textureStepY * latDegrees * (double)y1); } else { lat = latMin; } for (x1 = 0; x1 <= subdivs; x1++) { if (x1 != subdivs) { lng = lngMin + (textureStepX * lngDegrees * (double)x1); } else { lng = lngMax; } index = y1 * (subdivs + 1) + x1; point = Vector3d.Create(lng * scaleFactor, 0, (lat - 28) * scaleFactor); point.RotateY(213.0 / 180 * Math.PI); point.RotateZ((-62.87175) / 180 * Math.PI); point.RotateY((-192.8595083) / 180 * Math.PI); point.RotateX(ecliptic); verts[index] = PositionTexture.CreatePosRaw(point, (float)(1f - x1 * textureStepX), (float)(/*1f - */ (y1 * textureStepY))); //verts[index].Position = point; //verts[index].Tu = (float)(1f - x1 * textureStepX); //verts[index].Tv = (float)(/*1f - */(y1 * textureStepY)); } } galaxyImageVertexBuffer.Unlock(); galaxyImageTriangleCount = (subdivs) * (subdivs) * 2; Uint16Array ui16array = new Uint16Array(subdivs * subdivs * 6); UInt16[] indexArray = (UInt16[])(object)ui16array; for (y1 = 0; y1 < subdivs; y1++) { for (x1 = 0; x1 < subdivs; x1++) { index = (y1 * subdivs * 6) + 6 * x1; // First triangle in quad indexArray[index] = (ushort)(y1 * (subdivs + 1) + x1); indexArray[index + 2] = (ushort)((y1 + 1) * (subdivs + 1) + x1); indexArray[index + 1] = (ushort)(y1 * (subdivs + 1) + (x1 + 1)); // Second triangle in quad indexArray[index + 3] = (ushort)(y1 * (subdivs + 1) + (x1 + 1)); indexArray[index + 5] = (ushort)((y1 + 1) * (subdivs + 1) + x1); indexArray[index + 4] = (ushort)((y1 + 1) * (subdivs + 1) + (x1 + 1)); } } galaxyImageIndexBuffer = Tile.PrepDevice.createBuffer(); Tile.PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, galaxyImageIndexBuffer); Tile.PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW); }
public static bool DrawEclipticGrid(RenderContext renderContext, float opacity, Color drawColor) { if (eclipticLineList == null) { eclipticLineList = new SimpleLineList(); eclipticLineList.DepthBuffered = false; double obliquity = Coordinates.MeanObliquityOfEcliptic(2451545); Matrix3d mat = Matrix3d.RotationX((-obliquity / 360.0 * (Math.PI * 2))); for (double l = 0; l < 360; l += 10) { for (double b = -80; b < 80; b += 2) { eclipticLineList.AddLine(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, b, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, b + 2, 1), mat)); } } for (double b = -80; b <= 80; b += 10) { for (double l = 0; l < 360; l += 5) { eclipticLineList.AddLine(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, b, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu((l + 5) / 15, b, 1), mat)); } } int counter = 0; for (double l = 0; l < 360; l += 1) { double b = 0.25; switch (counter % 10) { case 0: counter++; continue; case 5: b = .5; break; } counter++; eclipticLineList.AddLine(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, b, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu(l / 15, -b, 1), mat)); } counter = 0; for (double l = 0; l < 360; l += 90) { counter = 0; for (double b = -80; b <= 80; b += 1) { double width = 0.5 / 2; switch (counter % 10) { case 0: counter++; continue; case 5: width = .5; break; } counter++; eclipticLineList.AddLine(Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu((l + width) / 15, b, 1), mat), Vector3d.TransformCoordinate(Coordinates.RADecTo3dAu((l - width) / 15, b, 1), mat)); } } } eclipticLineList.DrawLines(renderContext, opacity, drawColor); return(true); }
protected override bool PrepVertexBuffer(RenderContext renderContext, float opacity) { table.Lock(); if (lineList != null) { lineList.Clear(); } if (lineList2d != null) { lineList2d.Clear(); } if (triangleList != null) { triangleList.Clear(); } if (pointList != null) { pointList.Clear(); } if (triangleList2d != null) { triangleList2d.Clear(); } if (lineList == null) { lineList = new LineList(); } if (pointList == null) { pointList = new PointList(renderContext); } lineList.TimeSeries = this.timeSeries; if (lineList2d == null) { lineList2d = new LineList(); lineList2d.DepthBuffered = false; } lineList.TimeSeries = this.timeSeries; if (triangleList == null) { triangleList = new TriangleList(); } if (triangleList2d == null) { triangleList2d = new TriangleList(); triangleList2d.DepthBuffered = false; } positions.Clear(); UInt32 currentIndex = 0; // device.RenderState.FillMode = FillMode.WireFrame; Color colorLocal = Color; // colorLocal.A = (byte)(Color.A * Opacity); // for space 3d double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI; Dictionary <string, bool> selectDomain = new Dictionary <string, bool>(); double mr = 0; // double mr = LayerManager.AllMaps[ReferenceFrame].Frame.MeanRadius; if (mr != 0) { meanRadius = mr; } Vector3d position = new Vector3d(); float pointSize = .0002f; Color pointColor = Colors.White; float pointStartTime = 0; float pointEndTime = 0; foreach (string[] row in table.Rows) { try { bool selected = false; if (geometryColumn > -1 || (this.CoordinatesType == CoordinatesTypes.Spherical && (lngColumn > -1 && latColumn > -1)) || ((this.CoordinatesType == CoordinatesTypes.Rectangular) && (XAxisColumn > -1 && YAxisColumn > -1))) { double Xcoord = 0; double Ycoord = 0; double Zcoord = 0; double alt = 1; double altitude = 0; double distParces = 0; double factor = GetScaleFactor(AltUnit, 1); if (altColumn == -1 || AltType == AltTypes.SeaLevel || bufferIsFlat) { alt = 1; if (astronomical & !bufferIsFlat) { alt = UiTools.AuPerLightYear * 100; } } else { if (AltType == AltTypes.Depth) { factor = -factor; } alt = 0; try { alt = double.Parse(row[altColumn]); } catch { } if (astronomical) { factor = factor / (1000 * UiTools.KilometersPerAu); distParces = (alt * factor) / UiTools.AuPerParsec; altitude = (factor * alt); alt = (factor * alt); } else if (AltType == AltTypes.Distance) { altitude = (factor * alt); alt = (factor * alt / meanRadius); } else { altitude = (factor * alt); alt = 1 + (factor * alt / meanRadius); } } //todo remove hack when alt is fixed //alt = 1; if (CoordinatesType == CoordinatesTypes.Spherical && lngColumn > -1 && latColumn > -1) { //Xcoord = Coordinates.Parse(row[lngColumn]); //Ycoord = Coordinates.Parse(row[latColumn]); Xcoord = double.Parse(row[lngColumn]); Ycoord = double.Parse(row[latColumn]); if (astronomical) { if (RaUnits == RAUnits.Hours) { Xcoord *= 015; } if (bufferIsFlat) { // Xcoord += 180; } } double offset = 0; //todo EGM96Geoid.Height(Ycoord, Xcoord); // if (altitude != 0) { //altitude += offset; //alt += offset / meanRadius; } Vector3d pos = Coordinates.GeoTo3dDoubleRad(Ycoord, Xcoord, alt); if (astronomical && !bufferIsFlat) { pos.RotateX(ecliptic); } position = pos; positions.Add(position); } else if (this.CoordinatesType == CoordinatesTypes.Rectangular) { double xyzScale = GetScaleFactor(CartesianScale, CartesianCustomScale) / meanRadius; if (ZAxisColumn > -1) { Zcoord = double.Parse(row[ZAxisColumn]); } Xcoord = double.Parse(row[XAxisColumn]); Ycoord = double.Parse(row[YAxisColumn]); if (XAxisReverse) { Xcoord = -Xcoord; } if (YAxisReverse) { Ycoord = -Ycoord; } if (ZAxisReverse) { Zcoord = -Zcoord; } position = Vector3d.Create((Xcoord * xyzScale), (Zcoord * xyzScale), (Ycoord * xyzScale)); positions.Add(position); } // SqlGeometry pntGeo = SqlGeometry.Point(Xcoord,Ycoord, 4326); //// SqlGeometry pntGeo = SqlGeometry.Point(new SqlChars(String.Format("Point ({0} {1})", Xcoord,Ycoord).ToCharArray()), 4326); // if (!geo.STContains(pntGeo)) // { // continue; // } switch (ColorMap) { case ColorMaps.Same_For_All: pointColor = colorLocal; break; case ColorMaps.Per_Column_Literal: if (ColorMapColumn > -1) { pointColor = ParseColor(row[ColorMapColumn], colorLocal); } else { pointColor = colorLocal; } break; //case ColorMaps.Group_by_Range: // break; //case ColorMaps.Gradients_by_Range: // break; //case ColorMaps.Group_by_Values: // pointColor = ColorDomainValues[row[ColorMapColumn]].MarkerIndex; // break; default: break; } if (sizeColumn > -1) { switch (pointScaleType) { case PointScaleTypes.Linear: pointSize = Single.Parse(row[sizeColumn]); break; case PointScaleTypes.Log: pointSize = (float)Math.Log(Single.Parse(row[sizeColumn])); break; case PointScaleTypes.Power: { double size = 0; try { pointSize = (float)double.Parse(row[altColumn]); } catch { pointSize = 0; } } break; case PointScaleTypes.StellarMagnitude: { double size = 0; try { size = double.Parse(row[sizeColumn]); if (!bufferIsFlat) { size = size - 5 * ((Util.LogN(distParces, 10) - 1)); pointSize = (float)(120000000 / Math.Pow(1.6, size)); } else { pointSize = (float)(40 / Math.Pow(1.6, size)); } } catch { pointSize = 0; } } break; case PointScaleTypes.Constant: pointSize = 1; break; default: break; } } else { pointSize = (float)1; } if (PlotType == PlotTypes.Point) { pointSize = (float)1; } if (astronomical & !bufferIsFlat) { // lastItem.PointSize *= 1000000000000000000000000000f; } if (startDateColumn > -1) { Date dateTime = new Date(row[startDateColumn]); pointStartTime = (float)(SpaceTimeController.UtcToJulian(dateTime) - SpaceTimeController.UtcToJulian(baseDate)); if (endDateColumn > -1) { dateTime = new Date(row[endDateColumn]); //dateTime = DateTime.Parse(row[endDateColumn]); pointEndTime = (float)(SpaceTimeController.UtcToJulian(dateTime) - SpaceTimeController.UtcToJulian(baseDate)); } else { pointEndTime = pointStartTime; } } pointList.AddPoint(position, pointColor, new Dates(pointStartTime, pointEndTime), pointSize); if (geometryColumn > -1) { ParseGeometry(row[geometryColumn], pointColor, pointColor, altitude, new Dates(pointStartTime, pointEndTime)); } //if (barChartBitmask != 0) //{ // MakeBarChart(device, row, Ycoord, Xcoord, pointSize, factor, Color.FromArgb(lastItem.Color), selected, new Dates(pointStartTime, pointEndTime)); //} currentIndex++; } } catch { } lines = false; } table.Unlock(); dataDirty = false; dirty = false; return(false); }