public ToastTile(int level, int x, int y, IImageSet dataset, Tile parent) { this.level = level; this.x = x; this.y = y; this.dataset = dataset; topDown = !dataset.BottomsUp; demSize = 513; if (dataset.MeanRadius != 0) { DemScaleFactor = dataset.MeanRadius; } else { if (dataset.DataSetType == ImageSetType.Earth) { DemScaleFactor = 6371000; } else { DemScaleFactor = 3396010; } } ComputeQuadrant(); ComputeBoundingSphere( parent, parent !=null ? parent.demAverage : 0); insideOut = Dataset.DataSetType == ImageSetType.Sky || Dataset.DataSetType == ImageSetType.Panorama; }
public override bool Draw3D(RenderContext11 renderContext, float transparancy, Tile parent) { RenderedGeneration = CurrentRenderGeneration; TilesTouched++; InViewFrustum = true; if (!ReadyToRender) { TileCache.AddTileToQueue(this); return false; } TilesInView++; if (!CreateGeometry(renderContext, true)) { return false; } renderContext.SetVertexBuffer(vertexBuffer); renderContext.MainTexture = texture; renderContext.SetIndexBuffer( indexBuffer[0]); int partCount = this.TriangleCount; TrianglesRendered += partCount; renderContext.devContext.DrawIndexed(indexBuffer[0].Count, 0, 0); return true; }
public PlotTile(int level, int x, int y, IImageSet Imageimageset, Tile parent) { this.level = level; this.x = x; this.y = y; dataset = Imageimageset; InViewFrustum = true; }
public TangentTile(int level, int x, int y, IImageSet dataset, Tile parent) { this.level = level; this.x = x; this.y = y; this.dataset = dataset; topDown = !dataset.BottomsUp; ComputeBoundingSphere(parent); VertexCount = ((SubDivisions + 1) * (SubDivisions + 1)); }
public SphericalTile(int level, int x, int y, IImageSet dataset, Tile parent) { this.level = level; this.x = x; this.y = y; this.dataset = dataset; this.topDown = !dataset.BottomsUp; ComputeBoundingSphere(); VertexCount = ((subDivisionsX + 1) * (subDivisionsY + 1)); }
public EquirectangularTile(int level, int x, int y, IImageSet dataset, Tile parent) { this.level = level; this.x = x; this.y = y; this.dataset = dataset; topDown = !dataset.BottomsUp; ComputeBoundingSphere(parent); VertexCount = ((SubDivisions + 1) * (SubDivisions + 1)); insideOut = Dataset.DataSetType == ImageSetType.Sky || Dataset.DataSetType == ImageSetType.Panorama; }
public SkyImageTile(int level, int x, int y, IImageSet dataset, Tile parent) { this.level = level; this.x = x; this.y = y; this.dataset = dataset; demSize = 513; DemScaleFactor = 800000; GetParameters(); Height = 0; Width = 0; }
public static bool AddTileToQueue(Tile tile) { queueMutex.WaitOne(); int hitValue; hitValue = 256; if (!tile.TextureReady) { if (queue.ContainsKey(tile.Key)) { ((Tile)queue[tile.Key]).RequestHits += hitValue; } else { tile.RequestHits = hitValue; queue[tile.Key] = tile; } } queueMutex.ReleaseMutex(); return true; }
public static void RemoveTile(Tile tile) { tile.CleanUp(true); tileMutex.WaitOne(); tiles.Remove(tile.Key); tileMutex.ReleaseMutex(); }
public MercatorTile(int level, int x, int y, IImageSet dataset, Tile parent) { this.level = level; this.x = x; this.y = y; this.dataset = dataset; if (dataset.MeanRadius != 0) { DemScaleFactor = dataset.MeanRadius; } else { if (dataset.DataSetType == ImageSetType.Earth) { DemScaleFactor = 6371000; } else { DemScaleFactor = 3396000; } } if (parent != null) { ComputeBoundingSphere(parent as MercatorTile, parent.demAverage); } else { ComputeBoundingSphere(parent as MercatorTile, 0); } VertexCount = ((SubDivisions + 1) * (SubDivisions + 1)); }
protected void ComputeBoundingSphere(Tile parent) { if (!topDown) { ComputeBoundingSphereBottomsUp(parent); return; } var tileDegrees = (float)dataset.BaseTileDegrees / ((float)Math.Pow(2, level)); var latMin = (float)((dataset.BaseTileDegrees / 2 - (((double)y) * tileDegrees)) + dataset.OffsetY); var latMax = (float)((dataset.BaseTileDegrees / 2 - (((double)(y + 1)) * tileDegrees)) + dataset.OffsetY); var lngMin = (float)((((double)x * tileDegrees) - (float)dataset.BaseTileDegrees / dataset.WidthFactor) + dataset.OffsetX); var lngMax = (float)(((((double)(x + 1)) * tileDegrees) - (float)dataset.BaseTileDegrees / dataset.WidthFactor) + dataset.OffsetX); var latCenter = (latMin + latMax) / 2.0; var lngCenter = (lngMin + lngMax) / 2.0; sphereCenter = GeoTo3d(latCenter, lngCenter, false); TopLeft = GeoTo3d(latMin, lngMin, false); BottomRight = GeoTo3d(latMax, lngMax, false); TopRight = GeoTo3d(latMin, lngMax, false); BottomLeft = GeoTo3d(latMax, lngMin, false); var distVect = GeoTo3d(latMin, lngMin, false); distVect.Subtract(sphereCenter); sphereRadius = distVect.Length(); tileDegrees = lngMax - lngMin; if (level == 0) { localCenter = sphereCenter; } else { localCenter = parent.localCenter; } }
protected void ComputeBoundingSphereBottomsUp(Tile parent) { var tileDegrees = dataset.BaseTileDegrees / Math.Pow(2, level); var latMin = (dataset.BaseTileDegrees / 2 + ((y + 1) * tileDegrees)) + dataset.OffsetY; var latMax = (dataset.BaseTileDegrees / 2 + (y * tileDegrees)) + dataset.OffsetY; var lngMin = ((x * tileDegrees) - dataset.BaseTileDegrees / dataset.WidthFactor) + dataset.OffsetX; var lngMax = (((x + 1) * tileDegrees) - dataset.BaseTileDegrees / dataset.WidthFactor) + dataset.OffsetX; var latCenter = (latMin + latMax) / 2.0; var lngCenter = (lngMin + lngMax) / 2.0; sphereCenter = GeoTo3d(latCenter, lngCenter, false); TopLeft = GeoTo3d(latMin, lngMin, false); BottomRight = GeoTo3d(latMax, lngMax, false); TopRight = GeoTo3d(latMin, lngMax, false); BottomLeft = GeoTo3d(latMax, lngMin, false); var distVect = TopLeft; distVect.Subtract(sphereCenter); sphereRadius = distVect.Length(); tileDegrees = lngMax - lngMin; if (level == 0) { localCenter = sphereCenter; } else { localCenter = parent.localCenter; } }
public static Tile GetNewTile(IImageSet imageset, int level, int x, int y, Tile parent) { switch (imageset.Projection) { case ProjectionType.Mercator: { var newTile = new MercatorTile(level, x, y, imageset, parent); return newTile; } case ProjectionType.Equirectangular: { return new EquirectangularTile(level, x, y, imageset, parent); } case ProjectionType.Spherical: { return new SphericalTile(level, x, y, imageset, parent); } case ProjectionType.Toast: { return new ToastTile(level, x, y, imageset, parent); } case ProjectionType.SkyImage: { return new SkyImageTile(level, x, y, imageset, parent); } case ProjectionType.Plotted: { return new PlotTile(level, x, y, imageset, parent); } default: case ProjectionType.Tangent: { var newTile = new TangentTile(level, x, y, imageset, parent); return newTile; } } }
public override bool Draw3D(RenderContext11 renderContext, float transparancy, Tile parent) { InViewFrustum = true; transparancy = transparancy / 100; if (transparancy > 1f) { transparancy = 1.0f; } if (transparancy < 0f) { transparancy = 0; } if (!ReadyToRender) { TileCache.AddTileToQueue(this); if (texture == null) { return false; } } if (!CreateGeometry(renderContext, true)) { return false; } renderContext.MainTexture = texture; renderContext.SetVertexBuffer(vertexBuffer); renderContext.SetIndexBuffer(indexBuffer); renderContext.PreDraw(); renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; renderContext.devContext.DrawIndexed(6, 0, 0); return true; }
public virtual bool Draw3D(RenderContext11 renderContext, float opacity, Tile parent) { RenderedGeneration = CurrentRenderGeneration; TilesTouched++; AccessCount = TileCache.AccessID++; if (errored) { return false; } int xMax = 2; InViewFrustum = true; if (!ReadyToRender) { if (fastLoad) { TextureReady = true; DemReady = true; if (!CreateGeometry(renderContext, false)) { TextureReady = false; DemReady = false; TileCache.AddTileToQueue(this); return false; } } else { TileCache.AddTileToQueue(this); return false; } } int childIndex = 0; int yOffset = 0; if (dataset.Mercator || dataset.BottomsUp ) { yOffset = 1; } int xOffset = 0; if (PurgeRefresh) { PurgeTextureAndDemFiles(); } Matrix3d savedWorld = renderContext.World; Matrix3d savedView = renderContext.View; bool usingLocalCenter = false; if (localCenter != Vector3d.Empty) { usingLocalCenter = true; Vector3d temp = localCenter; renderContext.World = Matrix3d.Translation(temp) * renderContext.WorldBase * Matrix3d.Translation(-renderContext.CameraPosition); renderContext.View = Matrix3d.Translation(renderContext.CameraPosition) * renderContext.ViewBase; } try { bool anythingToRender = false; bool childRendered = false; for (int y1 = 0; y1 < 2; y1++) { for (int x1 = 0; x1 < xMax; x1++) { // if (level < (demEnabled ? 12 : dataset.Levels)) if (level < dataset.Levels) { Tile child = TileCache.GetTile(level + 1, x * 2 + ((x1 + xOffset) % 2), y * 2 + ((y1 + yOffset) % 2), dataset, this); childrenId[childIndex] = child.Key; if (child.IsTileInFrustum(renderContext.Frustum)) { InViewFrustum = true; if (child.IsTileBigEnough(renderContext)) { renderPart[childIndex].TargetState = !child.Draw3D(renderContext, opacity, this); if (renderPart[childIndex].TargetState) { childRendered = true; } } else { renderPart[childIndex].TargetState = true; } } else { renderPart[childIndex].TargetState = renderPart[childIndex].State = false; } if (renderPart[childIndex].TargetState == true || !blendMode) { renderPart[childIndex].State = renderPart[childIndex].TargetState; } } else { renderPart[childIndex].State = true; } if (renderPart[childIndex].State == true) { anythingToRender = true; } childIndex++; } } if (childRendered || anythingToRender) { RenderedAtOrBelowGeneration = CurrentRenderGeneration; if (parent != null) { parent.RenderedAtOrBelowGeneration = RenderedAtOrBelowGeneration; } } if (!anythingToRender) { return true; } if (!CreateGeometry(renderContext, true)) { return false; } TilesInView++; if ( wireFrame) { renderContext.MainTexture = null; } else { renderContext.MainTexture = texture; } renderContext.SetVertexBuffer(vertexBuffer); accomidation = ComputeAccomidation(); for (int i = 0; i < 4; i++) { if (blendMode) //|| ShowElevation == false) { if ((renderPart[i].State && opacity == 1.0) || renderPart[i].TargetState) { renderContext.LocalCenter = localCenter; renderContext.PreDraw(); if (dataset.DataSetType == ImageSetType.Sky) { HDRPixelShader.constants.opacity = renderPart[i].Opacity * opacity; HDRPixelShader.Use(renderContext.devContext); } RenderPart(renderContext, i, renderPart[i].Opacity * opacity, false); } } else { if (renderPart[i].TargetState) { renderContext.LocalCenter = localCenter; renderContext.PreDraw(); if (dataset.DataSetType == ImageSetType.Sky) { HDRPixelShader.constants.opacity = opacity; HDRPixelShader.Use(renderContext.devContext); } RenderPart(renderContext, i, opacity, false); } } } } finally { if (usingLocalCenter) { renderContext.World = savedWorld; renderContext.View = savedView; } } return true; }
public static Tile GetTileNow(int level, int x, int y, IImageSet dataset, Tile parent) { if (level < dataset.BaseLevel) { return null; } Tile retTile = null; long tileKey = ImageSetHelper.GetTileKey(dataset, level, x, y); try { if (!tiles.ContainsKey(tileKey)) { retTile = ImageSetHelper.GetNewTile(dataset, level, x, y, parent); tileMutex.WaitOne(); tiles.Add(tileKey, retTile); tileMutex.ReleaseMutex(); } else { retTile = tiles[tileKey]; } } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("GetTile: Exception"); } } finally { //todoperf get rid of this write for GC retTile.AccessCount = AccessID++; } // Create if not ready to render if (!retTile.ReadyToRender) { TileCache.GetTileFromWeb(retTile, false); retTile.CreateGeometry(Earth3d.MainWindow.RenderContext11, false); } return retTile; }
public static Tile GetTile(int level, int x, int y, IImageSet dataset, Tile parent) { if (level < dataset.BaseLevel) { return null; } Tile retTile = null; long tileKey = ImageSetHelper.GetTileKey(dataset, level, x, y); try { if (!tiles.ContainsKey(tileKey)) { retTile = ImageSetHelper.GetNewTile(dataset, level, x, y, parent); tileMutex.WaitOne(); tiles.Add(tileKey, retTile); tileMutex.ReleaseMutex(); } else { retTile = tiles[tileKey]; } } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("GetTile: Exception"); } } finally { //todoperf get rid of this write for GC retTile.AccessCount = AccessID++; } return retTile; }
protected void ComputeBoundingSphere(Tile parent, double altitude) { InitializeGrids(); var pointList = BufferPool11.GetVector3dBuffer(vertexList.Count); var scaleFactor = (1 + (altitude / DemScaleFactor)); if (DemEnabled) { for (var i = 0; i < vertexList.Count; i++) { pointList[i] = Vector3d.Scale(vertexList[i].Position, scaleFactor); } } else { for (var i = 0; i < vertexList.Count; i++) { pointList[i] = vertexList[i].Position; } } TopLeft = new Vector3d(Vector3d.Scale(bounds[0, 0].Position, scaleFactor)); BottomRight = new Vector3d(Vector3d.Scale(bounds[2, 2].Position, scaleFactor)); TopRight = new Vector3d(Vector3d.Scale(bounds[2, 0].Position, scaleFactor)); BottomLeft = new Vector3d(Vector3d.Scale(bounds[0, 2].Position, scaleFactor)); CalcSphere(pointList); BufferPool11.ReturnVector3dBuffer(pointList); if (Level == 5 || Level == 12) { localCenter = sphereCenter; localCenter.Round(); } else if (Level > 5) { localCenter = parent.localCenter; } ReturnBuffers(); }
//todoperf this needs to be pointer free protected void RemoveChild(Tile child) { //We are pointer free so this is not needed }
public static Tile GetCachedTile(int level, int x, int y, IImageSet dataset, Tile parent) { if (level < dataset.BaseLevel) { return null; } Tile retTile = null; long tileKey = ImageSetHelper.GetTileKey(dataset, level, x, y); try { if (!tiles.ContainsKey(tileKey)) { return null; } else { retTile = tiles[tileKey]; } } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile Initialize: Exception"); } } return retTile; }
protected void ComputeBoundingSphereBottomsUp(Tile parent) { var tileDegrees = dataset.BaseTileDegrees / Math.Pow(2, level); var latMin = (-90 + ((y + 1) * tileDegrees)); var latMax = (-90 + (y * tileDegrees)); var lngMin = ((x * tileDegrees) - 180.0); var lngMax = (((x + 1) * tileDegrees) - 180.0); var latCenter = (latMin + latMax) / 2.0; var lngCenter = (lngMin + lngMax) / 2.0; if (level == 12 || level == 19) { var temp = Coordinates.GeoTo3dDouble(latCenter, lngCenter); localCenter = new Vector3d(temp.X, temp.Y, temp.Z); } else if (level > 12) { localCenter = parent.localCenter; } sphereCenter = GeoTo3d(latCenter, lngCenter, false); TopLeft = GeoTo3dWithAltitude(latMin, lngMin, false); BottomRight = GeoTo3dWithAltitude(latMax, lngMax, false); TopRight = GeoTo3dWithAltitude(latMin, lngMax, false); BottomLeft = GeoTo3dWithAltitude(latMax, lngMin, false); var distVect = TopLeft; distVect.Subtract(sphereCenter); sphereRadius = distVect.Length(); tileDegrees = lngMax - lngMin; }
public static void GetDemTileFromWeb(Tile retTile) { string directory = retTile.DemDirectory; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string filename = retTile.DemFilename; FileInfo fi = new FileInfo(filename); bool exists = fi.Exists; if (exists) { if (fi.Length != 2178 && fi.Length != 1026 && fi.Length != 2052 && (retTile.Dataset.Projection != ProjectionType.Mercator)) { try { File.Delete(filename); } catch { } exists = false; } } if (!exists) { try { WebClient Client = new WebClient(); Client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"); string dlFile = string.Format("{0}.tmp{1}", filename, NodeID); Client.DownloadFile(CacheProxy.GetCacheUrl(retTile.DemURL), dlFile); try { if (File.Exists(dlFile)) { if (File.Exists(filename)) { File.Delete(filename); } File.Move(dlFile, filename); } } catch { } fi = new FileInfo(filename); exists = fi.Exists; } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Dem Download: Exception"); } exists = false; } } retTile.DemReady = true; retTile.demFileExists = exists; return; }
protected void ComputeBoundingSphereBottomsUp(Tile parent) { double tileDegrees = (double)this.dataset.BaseTileDegrees / ((double)Math.Pow(2, this.level)); double latMin = ((double)this.dataset.BaseTileDegrees / 2 + (((double)(this.y + 1)) * tileDegrees)) + dataset.OffsetY; double latMax = ((double)this.dataset.BaseTileDegrees / 2 + (((double)this.y) * tileDegrees)) + dataset.OffsetY; double lngMin = (((double)this.x * tileDegrees) - this.dataset.BaseTileDegrees / dataset.WidthFactor) + dataset.OffsetX; double lngMax = ((((double)(this.x + 1)) * tileDegrees) - this.dataset.BaseTileDegrees / dataset.WidthFactor) + dataset.OffsetX; double latCenter = (latMin + latMax) / 2.0; double lngCenter = (lngMin + lngMax) / 2.0; this.sphereCenter = GeoTo3d(latCenter, lngCenter, false); TopLeft = GeoTo3d(latMin, lngMin, false); BottomRight = GeoTo3d(latMax, lngMax, false); TopRight = GeoTo3d(latMin, lngMax, false); BottomLeft = GeoTo3d(latMax, lngMin, false); Vector3d distVect = TopLeft; distVect.Subtract(sphereCenter); this.sphereRadius = distVect.Length(); tileDegrees = lngMax - lngMin; if (level == 0) { localCenter = sphereCenter; } else { localCenter = parent.localCenter; } }
public static Tile GetTileFromWeb(Tile retTile, bool Initialize) { WebClient Client = null; if (retTile.Dataset.Projection == ProjectionType.SkyImage && retTile.Dataset.Url.EndsWith("/screenshot.png")) { SkyImageTile tile = retTile as SkyImageTile; Client = new WebClient(); string url = tile.URL; tile.ImageData = Client.DownloadData(url); retTile.DemReady = true; retTile.FileExists = true; retTile.ReadyToRender = true; retTile.TextureReady = true; //retTile.CreateGeometry(Tile.prepDevice); Client.Dispose(); return retTile; } Tile parent = retTile.Parent; if (retTile.DemEnabled && (parent == null || (parent != null && parent.DemGeneration == 0))) { GetDemTileFromWeb(retTile); } else { retTile.DemReady = true; } if (retTile.Dataset.WcsImage != null && retTile.Dataset.WcsImage is FitsImage) { retTile.TextureReady = true; InitializeTile(retTile); return retTile; } string directory = retTile.Directory; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string filename = retTile.FileName; Client = new WebClient(); FileInfo fi = new FileInfo(filename); bool exists = fi.Exists; if (exists) { if (fi.Length != 8 && fi.Length < 100 || retTile.Volitile) { try { File.Delete(filename); } catch { } exists = false; } } if (!exists) { try { if (retTile.Dataset.IsMandelbrot) { retTile.ComputeMandel(); fi = new FileInfo(filename); exists = fi.Exists; } else { Client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"); string url = retTile.URL; if (string.IsNullOrEmpty(url)) { retTile.errored = true; } else { string dlFile = string.Format("{0}.tmp{1}",filename,NodeID); Client.DownloadFile(CacheProxy.GetCacheUrl(url), dlFile); try { if (File.Exists(dlFile)) { if (File.Exists(filename)) { File.Delete(filename); } File.Move(dlFile, filename); } } catch { // UiTools.ShowMessageBox("File Download collision catch"); } fi = new FileInfo(filename); exists = fi.Exists; } // Code for drawing tile it onto tile for debuggin //if (retTile.Dataset.Projection == ProjectionType.Toast) //{ // //Bitmap bmpText = new Bitmap(filename); // Bitmap bmpText = UiTools.LoadBitmap(filename); // Graphics g = Graphics.FromImage(bmpText); // g.DrawString(retTile.Key, UiTools.StandardRegular, UiTools.StadardTextBrush, new RectangleF(0, 0, 255, 255), UiTools.StringFormatCenterCenter); // g.Flush(); // g.Dispose(); // bmpText.Save(filename); // bmpText.Dispose(); //} } } catch { //todo retry login on non - HTTP failuers. if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile Download: Exception" ); } retTile.errored = true; } } try { if (exists) { if (fi.Length < 100 || (fi.Length == 1033)) { retTile.errored = true; return retTile; } } // todo 3d Cities remove support for 3d Cities for now if (retTile.Dataset.Projection == ProjectionType.Mercator && Properties.Settings.Default.Show3dCities) { string tileID = retTile.GetTileID(); //check coverage cache before downloading int gen = CoverageMap.GetCoverage(tileID); if (gen > 0) { //try downloading mesh try { string meshFilename = retTile.FileName + ".mesh"; if (!File.Exists(meshFilename)) { Client.Headers.Add("User-Agent", "Win8Microsoft.BingMaps.3DControl/2.214.2315.0 (;;;;x64 Windows RT)"); string dlFile = string.Format("{0}.tmp{1}", meshFilename, NodeID); Client.DownloadFile(string.Format("http://ak.t{1}.tiles.virtualearth.net/tiles/mtx{0}?g={2}", tileID, Tile.GetServerID(retTile.X, retTile.Y), gen.ToString()), dlFile); try { if (File.Exists(dlFile)) { if (File.Exists(meshFilename)) { File.Delete(meshFilename); } File.Move(dlFile, meshFilename); } } catch { // UiTools.ShowMessageBox("File Download collision catch"); } } } catch { } } } retTile.FileExists = true; retTile.TextureReady = true; if (Initialize) { InitializeTile(retTile); } } catch (System.Exception) { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile Initialize: Exception"); } retTile.errored = true; } return retTile; }
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( Resources.StarProfile); var count = stars.Count; var index = 0; starCount = count; starVertexBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice); var points = (PositionColorSize[])starVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs) foreach (var star in stars) { var pos = Coordinates.RADecTo3d(star.RA + 12, star.Dec, 1f); points[index].Position = pos.Vector3; points[index].Color = star.Col; var 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); var mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11; mvp.Transpose(); PointSpriteShader11.WVPMatrix = mvp; PointSpriteShader11.Color = Color.White; var adjustedScale = (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360)); PointSpriteShader11.ViewportScale = new Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale); PointSpriteShader11.PointScaleFactors = new Vector3(0.0f, 0.0f, 10000.0f); PointSpriteShader11.Use(renderContext.Device.ImmediateContext); renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, starProfile.ResourceView); renderContext.devContext.InputAssembler.PrimitiveTopology = 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 static void InitializeTile(Tile tile) { bool loaded = false; while (!loaded && TileCache.running) { WaitingTileQueueMutex.WaitOne(); if (CountToLoad > 0) { CountToLoad--; CountToLoad = Math.Max(0, CountToLoad); // CountToLoad = 0; loaded = true; } WaitingTileQueueMutex.ReleaseMutex(); if (loaded) { if (tile != null) { tile.CreateGeometry(Earth3d.MainWindow.RenderContext11, false); tilesLoadedThisFrame++; } } else { WaitingTileQueueEvent.WaitOne(); } } }
protected void ComputeBoundingSphereBottomsUp(Tile parent) { double tileDegrees = (double)this.dataset.BaseTileDegrees / ((double)Math.Pow(2, this.level)); double latMin = (-90 + (((double)(this.y + 1)) * tileDegrees)); double latMax = (-90 + (((double)this.y) * tileDegrees)); double lngMin = (((double)this.x * tileDegrees) - 180.0); double lngMax = ((((double)(this.x + 1)) * tileDegrees) - 180.0); double latCenter = (latMin + latMax) / 2.0; double lngCenter = (lngMin + lngMax) / 2.0; if (level == 12 || level == 19) { Vector3d temp = Coordinates.GeoTo3dDouble(latCenter, lngCenter); localCenter = new Vector3d(temp.X, temp.Y, temp.Z); } else if (level > 12) { localCenter = parent.localCenter; } this.sphereCenter = GeoTo3d(latCenter, lngCenter, false); TopLeft = GeoTo3dWithAltitude(latMin, lngMin, false); BottomRight = GeoTo3dWithAltitude(latMax, lngMax, false); TopRight = GeoTo3dWithAltitude(latMin, lngMax, false); BottomLeft = GeoTo3dWithAltitude(latMax, lngMin, false); Vector3d distVect = TopLeft; distVect.Subtract(sphereCenter); this.sphereRadius = distVect.Length(); tileDegrees = lngMax - lngMin; }