public class World : RenderableObject
World对象是WW中最重要的对象,他包含了一个渲染对象的集合,同时他自身也是一个渲染对象。
重载的Render方法:
1 public override void Render(DrawArgs drawArgs) 2 { 3 try 4 { 5 6 if (m_WorldSurfaceRenderer != null && World.Settings.UseWorldSurfaceRenderer) 7 { 8 m_WorldSurfaceRenderer.RenderSurfaceImages(drawArgs); 9 } 10 11 // Old method -- problems with RenderPriority sorting 12 // RenderableObjects.Render(drawArgs); 13 14 RenderStars(drawArgs, RenderableObjects); 15 16 if (drawArgs.CurrentWorld.IsEarth && World.Settings.EnableAtmosphericScattering) 17 { 18 float aspectRatio = (float)drawArgs.WorldCamera.Viewport.Width / drawArgs.WorldCamera.Viewport.Height; 19 float zNear = (float)drawArgs.WorldCamera.Altitude * 0.1f; 20 double distToCenterOfPlanet = (drawArgs.WorldCamera.Altitude + equatorialRadius); 21 double tangentalDistance = Math.Sqrt(distToCenterOfPlanet * distToCenterOfPlanet - equatorialRadius * equatorialRadius); 22 double amosphereThickness = Math.Sqrt(m_outerSphere.m_radius * m_outerSphere.m_radius + equatorialRadius * equatorialRadius); 23 Matrix proj = drawArgs.device.Transform.Projection; 24 drawArgs.device.Transform.Projection = Matrix.PerspectiveFovRH((float)drawArgs.WorldCamera.Fov.Radians, aspectRatio, zNear, (float)(tangentalDistance + amosphereThickness)); 25 drawArgs.device.RenderState.ZBufferEnable = false; 26 drawArgs.device.RenderState.CullMode = Cull.CounterClockwise; 27 m_outerSphere.Render(drawArgs); 28 drawArgs.device.RenderState.CullMode = Cull.Clockwise; 29 drawArgs.device.RenderState.ZBufferEnable = true; 30 31 drawArgs.device.Transform.Projection = proj; 32 } 33 34 if (World.Settings.EnableSunShading) 35 RenderSun(drawArgs); 36 37 //render SurfaceImages 38 Render(RenderableObjects, WorldWind.Renderable.RenderPriority.TerrainMappedImages, drawArgs); 39 40 if (m_projectedVectorRenderer != null) 41 m_projectedVectorRenderer.Render(drawArgs); 42 43 //render AtmosphericImages 44 Render(RenderableObjects, WorldWind.Renderable.RenderPriority.AtmosphericImages, drawArgs); 45 46 //render LinePaths 47 Render(RenderableObjects, WorldWind.Renderable.RenderPriority.LinePaths, drawArgs); 48 49 //render Placenames 50 Render(RenderableObjects, WorldWind.Renderable.RenderPriority.Placenames, drawArgs); 51 52 //render Icons 53 Render(RenderableObjects, WorldWind.Renderable.RenderPriority.Icons, drawArgs); 54 55 //render Custom 56 Render(RenderableObjects, WorldWind.Renderable.RenderPriority.Custom, drawArgs); 57 58 if (Settings.showPlanetAxis) 59 this.DrawAxis(drawArgs); 60 } 61 catch (Exception ex) 62 { 63 Log.Write(ex); 64 } 65 }
其中多次调用的Render私有方法:
1 private void Render(WorldWind.Renderable.RenderableObject renderable, WorldWind.Renderable.RenderPriority priority, DrawArgs drawArgs) 2 { 3 if (!renderable.IsOn || (renderable.Name != null && renderable.Name.Equals("Starfield"))) 4 return; 5 6 try 7 { 8 if (priority == WorldWind.Renderable.RenderPriority.Icons && renderable is Icons) 9 { 10 renderable.Render(drawArgs); 11 } 12 else if (renderable is WorldWind.Renderable.RenderableObjectList) 13 { 14 WorldWind.Renderable.RenderableObjectList rol = (WorldWind.Renderable.RenderableObjectList)renderable; 15 for (int i = 0; i < rol.ChildObjects.Count; i++) 16 { 17 Render((WorldWind.Renderable.RenderableObject)rol.ChildObjects[i], priority, drawArgs); 18 } 19 } 20 // hack at the moment 21 else if (priority == WorldWind.Renderable.RenderPriority.TerrainMappedImages) 22 { 23 if (renderable.RenderPriority == WorldWind.Renderable.RenderPriority.SurfaceImages || renderable.RenderPriority == WorldWind.Renderable.RenderPriority.TerrainMappedImages) 24 { 25 renderable.Render(drawArgs); 26 } 27 } 28 else if (renderable.RenderPriority == priority) 29 { 30 renderable.Render(drawArgs); 31 } 32 } 33 catch (Exception ex) 34 { 35 Log.Write(ex); 36 } 37 }
重载的Update方法:
1 public override void Update(DrawArgs drawArgs) 2 { 3 if (!this.isInitialized) 4 { 5 this.Initialize(drawArgs); 6 } 7 8 if (this.RenderableObjects != null) 9 { 10 this.RenderableObjects.Update(drawArgs); 11 } 12 if (this.m_WorldSurfaceRenderer != null) 13 { 14 this.m_WorldSurfaceRenderer.Update(drawArgs); 15 } 16 17 if (this.m_projectedVectorRenderer != null) 18 { 19 this.m_projectedVectorRenderer.Update(drawArgs); 20 } 21 22 if (this.TerrainAccessor != null) 23 { 24 if (drawArgs.WorldCamera.Altitude < 300000) 25 { 26 if (System.DateTime.Now - this.lastElevationUpdate > TimeSpan.FromMilliseconds(500)) 27 { 28 drawArgs.WorldCamera.TerrainElevation = (short)this.TerrainAccessor.GetElevationAt(drawArgs.WorldCamera.Latitude.Degrees, drawArgs.WorldCamera.Longitude.Degrees, 100.0 / drawArgs.WorldCamera.ViewRange.Degrees); 29 this.lastElevationUpdate = System.DateTime.Now; 30 } 31 } 32 else 33 drawArgs.WorldCamera.TerrainElevation = 0; 34 } 35 else 36 { 37 drawArgs.WorldCamera.TerrainElevation = 0; 38 } 39 40 if (World.Settings.EnableAtmosphericScattering && m_outerSphere != null) 41 m_outerSphere.Update(drawArgs); 42 }
重载的PerformSelectionAction方法:
1 public override bool PerformSelectionAction(DrawArgs drawArgs) 2 { 3 return this._renderableObjects.PerformSelectionAction(drawArgs); 4 }