博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[WorldWind学习]2.WorldWindow控件
阅读量:6541 次
发布时间:2019-06-24

本文共 5538 字,大约阅读时间需要 18 分钟。

首先查看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 initialization11                 // Skip DirectX initialization in design mode12                 if(!IsInDesignMode())13                     this.InitializeGraphics();//初始化设备Device14 15                 //Post m_Device3d creation initialization16                 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         }
View Code
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             try17             {18                 // Store the default adapter19                 adapterOrdinal = Manager.Adapters.Default.Adapter;20             }21             catch22             {23                 // User probably needs to upgrade DirectX or install a 3D capable graphics adapter24                 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_Device3d40             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 processing45                 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             try51             {52                 // Create our m_Device3d53                 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 event61             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;

转载地址:http://cfsdo.baihongyu.com/

你可能感兴趣的文章
android控件库(1)-带删除功能的EditText
查看>>
android-解决EditText的inputType为Password时, 字体不一致的问题
查看>>
JQuery基础知识(1)
查看>>
Github 创建新分支
查看>>
3.字符串
查看>>
BZOJ 2809 APIO 2012 dispatching 平衡树启示式合并
查看>>
Weblogic java生成wlfullclient.jar
查看>>
IEnumerable<T> 转换为数组
查看>>
LVS+DR源码安装
查看>>
【译】在Asp.Net中操作PDF – iTextSharp -利用块,短语,段落添加文本
查看>>
#pragma once 与 #ifndef 解析
查看>>
05 redis中的Setbit位图法统计活跃用户
查看>>
PacBio全基因组测序和组装
查看>>
Jaxb2 实现JavaBean与xml互转
查看>>
Android的事件处理-android学习之旅(四十四)
查看>>
突袭HTML5之SVG 2D入门10 - 滤镜
查看>>
java最小公倍数与最大公约数
查看>>
程序员跳槽全攻略
查看>>
摩拜北京员工将搬迁至美团总部办公 CEO刘禹离职创业
查看>>
智能终端闪耀中国移动全球合作伙伴大会 华为斩获四项大奖
查看>>