private void RunQuery() { if (cornersLast != null && !String.IsNullOrEmpty(constellation)) { contextResults.Clear(); paginator1.CurrentPage = 1; paginator1.TotalPages = 1; //Place[] results = ContextSearch.FindConteallationObjects(Constellations.Abbreviation(constellation), cornersLast, (Classification)FilterCombo.Tag); Vector3d cornerUl = Coordinates.RADecTo3d(cornersLast[0].RA, cornersLast[0].Dec, 1); Vector3d cornerLR = Coordinates.RADecTo3d(cornersLast[2].RA, cornersLast[2].Dec, 1); Vector3d dist = Vector3d.Subtract(cornerLR, cornerUl); IPlace[] results = ContextSearch.FindConteallationObjectsInCone("SolarSystem", Earth3d.MainWindow.RA, Earth3d.MainWindow.Dec, (float)dist.Length() / 2.0f, (Classification)FilterCombo.Tag); if (results != null) { contextResults.AddRange(results); } results = ContextSearch.FindConteallationObjectsInCone("Community", Earth3d.MainWindow.RA, Earth3d.MainWindow.Dec, (float)dist.Length() / 2.0f, (Classification)FilterCombo.Tag); if (results != null) { contextResults.AddRange(results); } results = ContextSearch.FindConteallationObjectsInCone(Constellations.Abbreviation(constellation), Earth3d.MainWindow.RA, Earth3d.MainWindow.Dec, (float)dist.Length() / 2.0f, (Classification)FilterCombo.Tag); if (results != null) { contextResults.AddRange(results); } contextResults.Invalidate(); //paginator1.CurrentPage = 0; //paginator1.TotalPages = contextResults.PageCount; } }
public static IPlace[] FindConteallationObjectsInCone(string constellationID, double ra, double dec, float distance, Classification type) { Vector3d center = Coordinates.RADecTo3d(ra, dec, 1); if (!constellationObjects.ContainsKey(constellationID)) { return(null); } if (distance > 0) { List <IPlace> results = new List <IPlace>(); foreach (IPlace place in constellationObjects[constellationID]) { Vector3d distanceVector; //TODO Need Serious fixing of RA dec range validation... if ((type & place.Classification) != 0) { distanceVector = Vector3d.Subtract(center, place.Location3d); if (distanceVector.Length() < distance) { if (place.IsTour) { results.Insert(0, place); } else { results.Add(place); } } } } return(results.ToArray()); } else { List <IPlace> results = new List <IPlace>(); foreach (IPlace place in constellationObjects[constellationID]) { if ((type & place.Classification) != 0) { if (place.IsTour) { results.Insert(0, place); } else { results.Add(place); } } } return(results.ToArray()); } }
private void AddLines(bool sky, KmlLineList geo, float lineWidth, Color polyColor, Color lineColor, bool extrude) { //todo can we save this work for later? List <Vector3d> vertexList = new List <Vector3d>(); List <Vector3d> vertexListGround = new List <Vector3d>(); //todo list // We need to Wrap Around for complete polygone // we aldo need to do intereor //todo space? using RA/DEC for (int i = 0; i < (geo.PointList.Count); i++) { vertexList.Add(Coordinates.GeoTo3dDouble(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / geo.MeanRadius))); vertexListGround.Add(Coordinates.GeoTo3dDouble(geo.PointList[i].Lat, geo.PointList[i].Lng, 1)); } for (int i = 0; i < (geo.PointList.Count - 1); i++) { if (sky) { lines.AddLine(Coordinates.RADecTo3d(-(180.0 - geo.PointList[i].Lng) / 15 + 12, geo.PointList[i].Lat, 1), Coordinates.RADecTo3d(-(180.0 - geo.PointList[i + 1].Lng) / 15 + 12, geo.PointList[i + 1].Lat, 1), lineColor, new Dates()); } else { if (extrude) { triangles.AddQuad(vertexList[i], vertexList[i + 1], vertexListGround[i], vertexListGround[i + 1], polyColor, new Dates()); } if (lineWidth > 0) { lines.AddLine (vertexList[i], vertexList[i + 1], lineColor, new Dates()); if (extrude) { lines.AddLine(vertexListGround[i], vertexListGround[i + 1], lineColor, new Dates()); lines.AddLine(vertexList[i], vertexListGround[i], lineColor, new Dates()); lines.AddLine(vertexList[i + 1], vertexListGround[i + 1], lineColor, new Dates()); } } } } List <int> indexes = Glu.TesselateSimplePoly(vertexList); for (int i = 0; i < indexes.Count; i += 3) { triangles.AddTriangle(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], polyColor, new Dates()); } }
public SkyLabel(RenderContext11 renderContext, double ra, double dec, string text, LabelSytle style, double distance) { RA = ra; Dec = dec; Text = text; Style = style; Distance = distance; if (texture == null) { texture = Texture11.FromBitmap(Properties.Resources.circle, 0); } Vector3d up = new Vector3d(); Vector3d textPos = new Vector3d(); if (Earth3d.MainWindow.SolarSystemMode) { pos = Coordinates.RADecTo3d(ra, -dec, distance); up = Coordinates.RADecTo3d(ra, -dec + 90, distance); pos.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI); pos.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth)); up.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI); up.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth)); } else { pos = Coordinates.RADecTo3d(ra + 12, dec, distance); textPos = Coordinates.RADecTo3d(ra + 12, dec + 2, distance); up = Coordinates.RADecTo3d(ra + 12, dec + 92, distance); } center = new Vector3(9, 9, 0); textBatch = new Text3dBatch(24); if (style == LabelSytle.Telrad) { // Telrad-style labels are always screen-aligned Text3d t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01); t3.alignment = Text3d.Alignment.Left; textBatch.Add(t3); } else { up.Normalize(); textPos.Normalize(); textBatch.Add(new Text3d(textPos, up, text, 20, .0005)); } }
public static void InitializeConstellationNames() { NamesBatch = new Text3dBatch(80); foreach (IPlace centroid in ConstellationNamePositions.Values) { Vector3d center = Coordinates.RADecTo3d(centroid.RA + 12, centroid.Dec, 1); Vector3d up = new Vector3d(0, 1, 0); string name = centroid.Name; name = FullNames[centroid.Constellation]; if (centroid.Name == "Triangulum Australe") { name = name.Replace(" ", "\n "); } NamesBatch.Add(new Text3d(center, up, name, 80, .000125)); } }
public Vector2d GetImagePixel(Coordinates sky) { Vector2d result = new Vector2d(); //Vector3 tangent = GeoTo3dWithAltitude(sky.Lat, sky.Lng); Vector3d tangent = Coordinates.RADecTo3d(sky.RA + 12, sky.Dec, 1); Matrix3d mat = dataset.Matrix; mat.Invert(); tangent = Vector3d.TransformCoordinate(tangent, mat); Coordinates imagePoint = Coordinates.CartesianToSpherical(tangent); result.X = (float)((imagePoint.Lng / ScaleX) + PixelCenterX); result.Y = (float)((imagePoint.Lat / -ScaleY) + PixelCenterY); return(result); }
public IPlace HoverCheck(Vector3 searchPoint, IPlace defaultPlace, float distance) { searchPoint = -searchPoint; Vector3 dist; if (defaultPlace != null) { Vector3 testPoint = Coordinates.RADecTo3d(defaultPlace.RA, -defaultPlace.Dec, -1.0).Vector311; dist = searchPoint - testPoint; distance = dist.Length(); } int closestItem = -1; int index = 0; foreach (Vector3 point in positions) { dist = searchPoint - point; if (dist.Length() < distance) { distance = dist.Length(); closestItem = index; } index++; } lastHoverIndex = closestItem; if (closestItem == -1) { return(defaultPlace); } Coordinates pnt = Coordinates.CartesianToSpherical(positions[closestItem]); string name = this.names[closestItem]; if (String.IsNullOrEmpty(name)) { name = string.Format("RA={0}, Dec={1}", Coordinates.FormatHMS(pnt.RA), Coordinates.FormatDMS(pnt.Dec)); } TourPlace place = new TourPlace(name, pnt.Dec, pnt.RA, Classification.Unidentified, "", ImageSetType.Sky, -1); return(place); }
public override bool Draw3D(RenderContext11 renderContext, float opacity, Tile parent) { InViewFrustum = true; RenderedGeneration = CurrentRenderGeneration; if (!ReadyToRender) { TileCache.AddTileToQueue(this); return(false); } InViewFrustum = true; if (starVertexBuffer == null) { starProfile = Texture11.FromBitmap(Properties.Resources.StarProfile); int count = stars.Count; int index = 0; starCount = count; starVertexBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice); PositionColorSize[] points = (PositionColorSize[])starVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs) foreach (Star star in stars) { Vector3d pos = Coordinates.RADecTo3d(star.RA + 12, star.Dec, 1f); points[index].Position = pos.Vector3; points[index].Color = star.Col; double radDec = (.5) / Math.Pow(1.6, star.Magnitude); points[index].size = (float)radDec; index++; } starVertexBuffer.Unlock(); } renderContext.SetVertexBuffer(starVertexBuffer); renderContext.BlendMode = BlendMode.Additive; renderContext.DepthStencilMode = DepthStencilMode.Off; renderContext.setRasterizerState(TriangleCullMode.Off); SharpDX.Matrix mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; mvp.Transpose(); PointSpriteShader11.WVPMatrix = mvp; PointSpriteShader11.Color = SharpDX.Color.White; float adjustedScale = (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360)); PointSpriteShader11.ViewportScale = new SharpDX.Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale); PointSpriteShader11.PointScaleFactors = new SharpDX.Vector3(0.0f, 0.0f, 10000.0f); PointSpriteShader11.Use(renderContext.Device.ImmediateContext); renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, starProfile.ResourceView); renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList; renderContext.devContext.Draw(starCount, 0); renderContext.Device.ImmediateContext.GeometryShader.Set(null); // Reset blend mode so we don't mess up subsequent sky layer rendering renderContext.BlendMode = BlendMode.Alpha; return(true); }
public override IPlace FindClosest(Coordinates target, float distance, IPlace defaultPlace, bool astronomical) { Vector3d searchPoint = Coordinates.GeoTo3dDouble(target.Lat, target.Lng); //searchPoint = -searchPoint; Vector3d dist; if (defaultPlace != null) { Vector3d testPoint = Coordinates.RADecTo3d(defaultPlace.RA, -defaultPlace.Dec, -1.0); dist = searchPoint - testPoint; distance = (float)dist.Length(); } int closestItem = -1; int index = 0; foreach (Vector3 point in positions) { dist = searchPoint - new Vector3d(point); if (dist.Length() < distance) { distance = (float)dist.Length(); closestItem = index; } index++; } if (closestItem == -1) { return(defaultPlace); } Coordinates pnt = Coordinates.CartesianToSpherical2(positions[closestItem]); string name = table.Rows[closestItem].ColumnData[this.nameColumn].ToString(); if (nameColumn == startDateColumn || nameColumn == endDateColumn) { name = SpreadSheetLayer.ParseDate(name).ToString("u"); } if (String.IsNullOrEmpty(name)) { name = string.Format("RA={0}, Dec={1}", Coordinates.FormatHMS(pnt.RA), Coordinates.FormatDMS(pnt.Dec)); } TourPlace place = new TourPlace(name, pnt.Lat, pnt.RA, Classification.Unidentified, "", ImageSetType.Sky, -1); Dictionary <String, String> rowData = new Dictionary <string, string>(); for (int i = 0; i < table.Columns.Count; i++) { string colValue = table.Rows[closestItem][i].ToString(); if (i == startDateColumn || i == endDateColumn) { colValue = SpreadSheetLayer.ParseDate(colValue).ToString("u"); } if (!rowData.ContainsKey(table.Column[i].Name) && !string.IsNullOrEmpty(table.Column[i].Name)) { rowData.Add(table.Column[i].Name, colValue); } else { rowData.Add("Column" + i.ToString(), colValue); } } place.Tag = rowData; if (Viewer != null) { Viewer.LabelClicked(closestItem); } return(place); }
private void AddFeatureToDisplay(KmlFeature feature, bool sky) { KmlDocument doc = feature as KmlDocument; if (doc != null) { sky = doc.sky; } if (!(feature is KmlNetworkLink)) { if (feature.visibility == false) { return; } else if (feature is KmlPlacemark) { KmlPlacemark placemark = (KmlPlacemark)feature; KmlStyle style = placemark.Style.GetStyle(placemark.Selected); Color lineColor = Color.White; if (style != null) { lineColor = style.LineStyle.Color; } if (placemark.geometry is KmlPoint) { placemark.Point = (KmlPoint)placemark.geometry; AddPlacemark(placemark); } else if (placemark.geometry is KmlMultiGeometry) { KmlMultiGeometry geo = (KmlMultiGeometry)placemark.geometry; AddMultiGeometry(sky, placemark, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo); } else if (placemark.geometry is KmlPolygon) { KmlPolygon geo = (KmlPolygon)placemark.geometry; if (geo.OuterBoundary != null) { AddLines(sky, geo.OuterBoundary as KmlLineList, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo.extrude); // to do 3d work and subtract inner rings } } else if (placemark.geometry is KmlLineString) { KmlLineString geo = (KmlLineString)placemark.geometry; List <Vector3d> vertexList = new List <Vector3d>(); for (int i = 0; i < (geo.PointList.Count); i++) { vertexList.Add(Coordinates.GeoTo3dDouble(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / geo.MeanRadius))); } for (int i = 0; i < (geo.PointList.Count - 1); i++) { if (sky) { lines.AddLine(Coordinates.RADecTo3d(-(180.0 - geo.PointList[i].Lng) / 15 + 12, geo.PointList[i].Lat, 1), Coordinates.RADecTo3d(-(180.0 - geo.PointList[i + 1].Lng) / 15 + 12, geo.PointList[i + 1].Lat, 1), lineColor, new Dates()); } else { lines.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates()); } } } } if (feature is KmlGroundOverlay && feature.visibility) { AddGroundOverlay(feature as KmlGroundOverlay); } if (feature is KmlScreenOverlay && feature.visibility) { AddScreenOverlay(feature as KmlScreenOverlay); } } if (feature.visibility) { if (feature is KmlContainer) { KmlContainer container = (KmlContainer)feature; if (container.children != null) { foreach (KmlFeature child in container.children) { AddFeatureToDisplay(child, sky); } } } else { if (feature is KmlNetworkLink) { KmlNetworkLink netLink = (KmlNetworkLink)feature; if (netLink.LinkRoot != null) { foreach (KmlFeature child in netLink.LinkRoot.children) { AddFeatureToDisplay(child, sky); } } } } } }
public void AddPoint(string name, double ra, double dec, double altitude) { positions.Add(Coordinates.RADecTo3d(ra, -dec, -1 - (altitude / 6371000)).Vector311); names.Add(name); EmptyLabelBuffer(); }