/// <summary> /// This is where we do our rendering /// Called from UI thread = UI code safe in this function /// </summary> public override void Render(DrawArgs drawArgs) { if (!isInitialized) { return; } if (world.Name != "Earth") { return; // Earth only } // Check for update if (!isDownloading && DateTime.Now > latestTime.AddHours(refreshHours)) { if (retryCount < maxRetry && DateTime.Now > lastDownloadTime.AddSeconds(retryDelaySeconds)) { StartDownload(cachePath, "clouds_" + DateTimeStamp(DateTime.Now) + ".jpg"); } } // Camera & Device shortcuts ;) CameraBase camera = drawArgs.WorldCamera; //Device device = drawArgs.device; // Render cloud layer if (texture != null) { double cloudAlt = 20e3; // clouds altitude in meters (20 x 10e3) if (camera.Altitude < 4000e3) { return; } double sphereRadius = camera.WorldRadius + cloudAlt; // Create sphere if (layerMesh == null) { layerMesh = TexturedSphere(drawArgs.device, (float)sphereRadius, 64, 64); } // set texture drawArgs.device.SetTexture(0, texture); drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Modulate; drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; drawArgs.device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse; drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1; drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; drawArgs.device.VertexFormat = CustomVertex.PositionNormalTextured.Format; // save world and projection transform Matrix origWorld = drawArgs.device.Transform.World; Matrix origProjection = drawArgs.device.Transform.Projection; // Save fog status and disable fog bool origFog = drawArgs.device.RenderState.FogEnable; drawArgs.device.RenderState.FogEnable = false; // Set new projection (to avoid being clipped) - probably better ways of doing this? double aspectRatio = (double)drawArgs.device.Viewport.Width / drawArgs.device.Viewport.Height; drawArgs.device.Transform.Projection = ConvertDX.FromMatrix4d(Matrix4d.PerspectiveFovRH(camera.Fov.Radians, aspectRatio, 1, double.MaxValue)); //translate to the camera reference center drawArgs.device.Transform.World = Matrix.Translation( (float)-drawArgs.WorldCamera.ReferenceCenter.X, (float)-drawArgs.WorldCamera.ReferenceCenter.Y, (float)-drawArgs.WorldCamera.ReferenceCenter.Z ); // draw drawArgs.device.RenderState.ZBufferEnable = false; layerMesh.DrawSubset(0); // Restore device states drawArgs.device.Transform.World = origWorld; drawArgs.device.Transform.Projection = origProjection; drawArgs.device.RenderState.FogEnable = origFog; drawArgs.device.RenderState.ZBufferEnable = true; } // Render progress bar if downloading if (isDownloading) { if (progressBar == null) { progressBar = new WorldWind.VisualControl.ProgressBar(40, 4); } progressBar.Draw(drawArgs, drawArgs.screenWidth - 34, drawArgs.screenHeight - 10, ProgressPercent, downloadProgressColor); drawArgs.device.RenderState.ZBufferEnable = true; } }
/// <summary> /// This is where we do our rendering /// Called from UI thread = UI code safe in this function /// </summary> public override void Render(DrawArgs drawArgs) { if (!isInitialized) return; if (world.Name != "Earth") return; // Earth only // Check for update if (!isDownloading && DateTime.Now > latestTime.AddHours(refreshHours)) { if (retryCount < maxRetry && DateTime.Now > lastDownloadTime.AddSeconds(retryDelaySeconds)) { StartDownload(cachePath, "clouds_" + DateTimeStamp(DateTime.Now) + ".jpg"); } } // Camera & Device shortcuts ;) CameraBase camera = drawArgs.WorldCamera; //Device device = drawArgs.device; // Render cloud layer if (texture != null) { double cloudAlt = 20e3; // clouds altitude in meters (20 x 10e3) if (camera.Altitude < 4000e3) return; double sphereRadius = camera.WorldRadius + cloudAlt; // Create sphere if (layerMesh == null) layerMesh = TexturedSphere(drawArgs.device, (float)sphereRadius, 64, 64); // set texture drawArgs.device.SetTexture(0, texture); drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Modulate; drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; drawArgs.device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse; drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1; drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; drawArgs.device.VertexFormat = CustomVertex.PositionNormalTextured.Format; // save world and projection transform Matrix origWorld = drawArgs.device.Transform.World; Matrix origProjection = drawArgs.device.Transform.Projection; // Save fog status and disable fog bool origFog = drawArgs.device.RenderState.FogEnable; drawArgs.device.RenderState.FogEnable = false; // Set new projection (to avoid being clipped) - probably better ways of doing this? double aspectRatio = (double)drawArgs.device.Viewport.Width / drawArgs.device.Viewport.Height; drawArgs.device.Transform.Projection = ConvertDX.FromMatrix4d(Matrix4d.PerspectiveFovRH(camera.Fov.Radians, aspectRatio, 1, double.MaxValue)); //translate to the camera reference center drawArgs.device.Transform.World = Matrix.Translation( (float)-drawArgs.WorldCamera.ReferenceCenter.X, (float)-drawArgs.WorldCamera.ReferenceCenter.Y, (float)-drawArgs.WorldCamera.ReferenceCenter.Z ); // draw drawArgs.device.RenderState.ZBufferEnable = false; layerMesh.DrawSubset(0); // Restore device states drawArgs.device.Transform.World = origWorld; drawArgs.device.Transform.Projection = origProjection; drawArgs.device.RenderState.FogEnable = origFog; drawArgs.device.RenderState.ZBufferEnable = true; } // Render progress bar if downloading if (isDownloading) { if (progressBar == null) progressBar = new WorldWind.VisualControl.ProgressBar(40, 4); progressBar.Draw(drawArgs, drawArgs.screenWidth - 34, drawArgs.screenHeight - 10, ProgressPercent, downloadProgressColor); drawArgs.device.RenderState.ZBufferEnable = true; } }
public void RenderDownloadProgress(DrawArgs drawArgs, GeoSpatialDownloadRequest request, int offset) { int halfIconHeight = 24; int halfIconWidth = 24; Vector3 projectedPoint = new Vector3(DrawArgs.ParentControl.Width - halfIconWidth - 10, DrawArgs.ParentControl.Height - 34 - 4 * offset, 0.5f); // Render progress bar if (progressBar == null) progressBar = new ProgressBar(40, 4); progressBar.Draw(drawArgs, projectedPoint.X, projectedPoint.Y + 24, request.ProgressPercent, World.Settings.DownloadProgressColor.ToArgb()); DrawArgs.Device.RenderState.ZBufferEnable = true; // Render server logo if (ServerLogoFilePath == null) return; if (m_iconTexture == null) m_iconTexture = ImageHelper.LoadIconTexture(ServerLogoFilePath); if (sprite == null) { using (Surface s = m_iconTexture.GetSurfaceLevel(0)) { SurfaceDescription desc = s.Description; m_spriteSize = new Rectangle(0, 0, desc.Width, desc.Height); } this.sprite = new Sprite(DrawArgs.Device); } float scaleWidth = (float)2.0f * halfIconWidth / m_spriteSize.Width; float scaleHeight = (float)2.0f * halfIconHeight / m_spriteSize.Height; this.sprite.Begin(SpriteFlags.AlphaBlend); this.sprite.Transform = Matrix.Transformation2D(new Vector2(0.0f, 0.0f), 0.0f, new Vector2(scaleWidth, scaleHeight), new Vector2(0, 0), 0.0f, new Vector2(projectedPoint.X, projectedPoint.Y)); this.sprite.Draw(m_iconTexture, m_spriteSize, new Vector3(1.32f * 48, 1.32f * 48, 0), new Vector3(0, 0, 0), World.Settings.DownloadLogoColor); this.sprite.End(); }
/// <summary> /// Render download indicator rectangles /// </summary> protected virtual void RenderProgress(DrawArgs drawArgs, GeoSpatialDownloadRequest request) { const int height = 4; const int spacing = 2; // Render progress bar if(m_progressBar==null) m_progressBar = new ProgressBar(HalfWidth*2 * 4/5, height); // 4/5 of icon width m_progressBar.Draw(drawArgs, m_renderPosition.X, m_renderPosition.Y-height, request.Progress, request.Color); m_renderPosition.Y -= height+spacing; }