[WorldWind学习]2.WorldWindow控件
1.[WorldWind学习]1.接触WorldWind项目
2.[WorldWind学习]2.WorldWindow控件
3.[WorldWind学习]3.Device对象4.[WorldWind学习]4.DrawArgs对象5.[WorldWind学习]5.相机对象6.[WorldWind学习]6.World类7.[WorldWind学习]7.RenderableObject对象8.[WorldWind学习]8.Cache对象9.[WorldWind学习]9.WW的屏幕坐标到经纬度坐标计算10.[WorldWind学习]10.插件结构11.[WorldWind学习]11.TerrainViewer插件和双线程12.[WorldWind学习]12.WavingFlags和WavingFlagLayer13.[WorldWind学习]13.日志类Log14.[WorldWind学习]14.ConfigurationLoader类15.[WorldWind学习]15.模型加载16.[WorldWind学习]16.Lod技术(1)17.[WorldWind学习]17.视域调度(视域体裁剪)18.[转载]WorldWind实时确定、更新、初始化和渲染地形和纹理数据19.[WorldWind学习]18.High-Performance Timer in C#20.[WorldWind学习]19.WebDownload21.[WorldWind学习]20.修改ShapeFileLayer类及托管D3D文字绘制方法22.[World Wind学习]21.影像切割23.[World Wind学习]22.相机高度和瓦片等级计算24.[WorldWind学习]23.TerrainAccessor首先查看WorldWindow 的构造函数,接着查看InitializeGraphics()函数。
1 public WorldWindow() 2 { 3 this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); 4 5 // The m_Device3d can't be created unless the control is at least 1 x 1 pixels in size 6 this.Size = new Size(1,1); 7 8 try 9 { 10 // Now perform the rendering m_Device3d initialization 11 // Skip DirectX initialization in design mode 12 if(!IsInDesignMode()) 13 this.InitializeGraphics();//初始化设备Device 14 15 //Post m_Device3d creation initialization 16 this.drawArgs = new DrawArgs(m_Device3d, this ); 17 this.m_RootWidget = new WorldWind.Widgets.RootWidget(this); 18 this.m_NewRootWidget = new WorldWind.NewWidgets.RootWidget(this); 19 20 //this.m_RootWidget.ChildWidgets.Add(layerManager); 21 DrawArgs.RootWidget = this.m_RootWidget; 22 DrawArgs.NewRootWidget = this.m_NewRootWidget; 23 24 m_FpsTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_FpsTimer_Elapsed); 25 m_FpsTimer.Start(); 26 27 TimeKeeper.Start(); 28 // WorldWind.Widgets.LayerManager layerManager = new WorldWind.Widgets.LayerManager(); 29 // m_RootWidget.ChildWidgets.Add(layerManager); 30 31 } 32 catch (InvalidCallException caught) 33 { 34 throw new InvalidCallException( 35 "Unable to locate a compatible graphics adapter. Make sure you are running the latest version of DirectX.", caught ); 36 } 37 catch (NotAvailableException caught) 38 { 39 throw new NotAvailableException( 40 "Unable to locate a compatible graphics adapter. Make sure you are running the latest version of DirectX.", caught ); 41 } 42 }

1 private void InitializeGraphics() 2 { 3 // Set up our presentation parameters 4 m_presentParams = new PresentParameters(); 5 6 m_presentParams.Windowed = true; 7 m_presentParams.SwapEffect = SwapEffect.Discard; 8 m_presentParams.AutoDepthStencilFormat = DepthFormat.D16; 9 m_presentParams.EnableAutoDepthStencil = true; 10 11 if(!World.Settings.VSync) 12 // Disable wait for vertical retrace (higher frame rate at the expense of tearing) 13 m_presentParams.PresentationInterval = PresentInterval.Immediate; 14 15 int adapterOrdinal = 0; 16 try 17 { 18 // Store the default adapter 19 adapterOrdinal = Manager.Adapters.Default.Adapter; 20 } 21 catch 22 { 23 // User probably needs to upgrade DirectX or install a 3D capable graphics adapter 24 throw new NotAvailableException(); 25 } 26 27 DeviceType dType = DeviceType.Hardware; 28 29 foreach(AdapterInformation ai in Manager.Adapters) 30 { 31 if(ai.Information.Description.IndexOf("NVPerfHUD") >= 0) 32 { 33 adapterOrdinal = ai.Adapter; 34 dType = DeviceType.Reference; 35 } 36 } 37 CreateFlags flags = CreateFlags.SoftwareVertexProcessing; 38 39 // Check to see if we can use a pure hardware m_Device3d 40 Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware); 41 42 // Do we support hardware vertex processing? 43 if(caps.DeviceCaps.SupportsHardwareTransformAndLight) 44 // // Replace the software vertex processing 45 flags = CreateFlags.HardwareVertexProcessing; 46 47 // Use multi-threading for now - TODO: See if the code can be changed such that this isn't necessary (Texture Loading for example) 48 flags |= CreateFlags.MultiThreaded | CreateFlags.FpuPreserve; 49 50 try 51 { 52 // Create our m_Device3d 53 m_Device3d = new Device(adapterOrdinal, dType, this, flags, m_presentParams); 54 } 55 catch( Microsoft.DirectX.DirectXException ) 56 { 57 throw new NotSupportedException("Unable to create the Direct3D m_Device3d."); 58 } 59 60 // Hook the m_Device3d reset event 61 m_Device3d.DeviceReset += new EventHandler(OnDeviceReset); 62 m_Device3d.DeviceResizing += new CancelEventHandler(m_Device3d_DeviceResizing); 63 OnDeviceReset(m_Device3d, null); 64 }
控件重要的方法:
OnApplicationIdle函数定义: public void OnApplicationIdle(object sender, EventArgs e)//The world render loop.实现世界的渲染循环 OnPaint函数定义: protected override void OnPaint(PaintEventArgs e) // Occurs when the control is redrawn and m_isRenderDisabled=true. protected override void OnMouseWheel(MouseEventArgs e) //处理鼠标滚轮事件 protected override void OnKeyDown(KeyEventArgs e) //重载处理键盘按下的事件 protected override void OnKeyUp(KeyEventArgs e) //重载处理键盘弹起事件 protected override void OnMouseDoubleClick(MouseEventArgs e) protected override void OnMouseUp(MouseEventArgs e)
控件几个重要的属性和字段:
private Device m_Device3d; private DrawArgs drawArgs; private World m_World; private Cache m_Cache; private Thread m_WorkerThread;
作者:太一吾鱼水
文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。
欢迎大家留言交流,转载请注明出处。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2012-03-28 ArcEngine代码整理(2)