博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[WorldWind学习]1.接触WorldWind项目
阅读量:7048 次
发布时间:2019-06-28

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

1.WorldWind资源下载: 或者SourceForge上下载。

2.依赖:d3d9托管类库,通过安装WorldWind获得

  编译项目

3.Main程序入口

  在WorldWind.cs文件中查看,Main()函数写在public class MainApplication : System.Windows.Forms.Form, IGlobe类内部。

1 ///   2         /// The main entry point. Parses arguments, runs the MainApplication and saves settings  3         ///   4         /// The arguments to parse  5         [STAThread]  6         static void Main(string[] args)  7         {  8             try  9             { 10                 // Establish the version number string used for user display, 11                 // such as the Splash and Help->About screens. 12                 // To change the Application.ProductVersion make the 13                 // changes in \WorldWind\AssemblyInfo.cs 14                 // For alpha/beta versions, include " alphaN" or " betaN" 15                 // at the end of the format string. 16                 Version ver = new Version(Application.ProductVersion); 17                 Release = string.Format("{0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision); 18  19                 // If World Wind is already running, pass any commandline 20                 // arguments from this instance, and quit. 21                 IntPtr handle = GetWWHandle(); 22                 if (!System.IntPtr.Zero.Equals(handle)) 23                 { 24                     if(args.Length>0) 25                         NativeMethods.SendArgs( handle, string.Join("\n",args) ); 26                     return; 27                 } 28  29                 // abort if 50 bindings problem present and user opts to go to the download page 30                 if(BindingsCheck.FiftyBindingsWarning()) return; 31  32                 // Name the main thread 33                 System.Threading.Thread.CurrentThread.Name = "Main Thread"; 34  35                 // ParseArgs may set values that are used elsewhere, 36                 // such as startFullScreen and CurrentSettingsDirectory. 37                 ParseArgs(args); 38  39                 if(CurrentSettingsDirectory == null) 40                 { 41                     // load program settings from default directory 42                     LoadSettings();//如果设置路径为空,加载系统默认设置 43                     World.LoadSettings();//如果设置路径为空,加载世界默认设置 44                 } 45                 else 46                 { 47                     LoadSettings(CurrentSettingsDirectory); 48                     World.LoadSettings(CurrentSettingsDirectory); 49                 } 50  51                 Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); 52  53                 MainApplication app = new MainApplication(); 54                 Application.Idle += new EventHandler(app.WorldWindow.OnApplicationIdle); 55                 Application.Run(app); 56  57                 // Save World settings 58                 World.Settings.Save(); 59  60                 // Encrypt encoded user credentials before saving program settings 61                 DataProtector dp = new DataProtector(DataProtector.Store.USE_USER_STORE); 62                 Settings.ProxyUsername = dp.TransparentEncrypt(Settings.ProxyUsername); 63                 Settings.ProxyPassword = dp.TransparentEncrypt(Settings.ProxyPassword); 64  65                 // Save program settings 66                 Settings.Save(); 67             } 68             catch (NullReferenceException) 69             { 70                 // HACK 71             } 72             // uncomment this if you want easy debugging ;) 73             //#if !DEBUG 74             catch (Exception caught) 75             { 76                 Exception e; 77                 string errorMessages; 78                 try 79                 { 80                     // log the error 81                     Log.Write(caught); 82                 } 83                 catch 84                 { 85                     // ignore errors while trying to write the error to the log 86                 } 87                 finally 88                 { 89                     e = caught; 90                     errorMessages = "The following error(s) occurred:"; 91                     do 92                     { 93                         errorMessages += "\r\n" + e.Message; 94                         e = e.InnerException; 95                     } 96                     while( e != null ); 97                     Abort(errorMessages); 98                 } 99             }100             //#endif101         }

 Main函数实现了如下功能:

* WW程序的入口在WorldWind.cs的Main函数中,其中,args可通过命令行等方式进行

 * 传递参数,例如程序目录等。详见ParseArgs(args)。在主函数中,包括以下部分:
 * 1. 获得该应用程序的版本号
 * 2. 如果已经运行了WW,将该实例参数传出,并退出
 * 3. 如果服务器上有超过50个用户同时在线则退出
 * 4. 命名主线程
 * 5. 解析由命令行输入的args参数
 * 6. 载入配置文件 (重点***)
 * 7. 添加线程异常事件处理句柄
 * 8. 创建主应用程序实例 (重点*****)
 * 9. 保存World设置
 * 10.在保存程序设置之前对用户资格证书进行加密
 * 11.保存程序设置

加载系统配置文件 LoadSettings();//如果设置路径为空,加载系统默认设置,主要包括各种插件的加载,配置文件夹路径和数据文件夹路径。

 * 1. 除非在args里传入CurrentSettingsDirectory参数,否则都进入默认目录下找配置文件
 * 2. 默认配置文件目录  window7 和 XP 下的目录不一样
 *    "C:/Documents and Settings/XXXXXX/Application Data/NASA/World Wind/1.4.0.0/WorldWind.xml" 
 *    "C:/Users/XXXXXX/AppData/Roaming/NASA/World Wind/1.4.0.0/WorldWind.xml"
 *    XXXXX为相应的用户,上面的是XP目录,下面的是win7目录
 *    在SettingsBase.cs中有专门设置默认路径的函数。Settings是WorldWindSettings类

加载世界配置文件 World.LoadSettings();//如果设置路径为空,加载世界默认设置,主要包括显示的是地球还是月球等,大气显隐,太阳显隐等。

World.LoadSetting主要是对World类中的Setting进行配置,其类型为WorldSettings

 * WorldWindSettings和WorldSettings两个类的基类都属于SettingsBase,不论是哪个配置文件,最终都将调用SettingsBase.Load(defaultSettings, fileName)
 * 其相似和不同之处在于:
 * 1、其配置文件名为World.xml,目录与WorldWind.xml一致,读取的反序列化方法一致
 * 2、不同在于基本配置内容,在WorldSettings.cs文件中主要包含以下几个部分配置:
 *    1) Atomosphere 大气层是否显示
 *    2) UI 界面窗口显示,除toolbar之类的显示外还包括字体字号设置
 *    3) Grid 格网设置,颜色等
 *    4) World 世界图层,地名国界等
 *    5) Camera 相机视频的参数设置,这直接关系到视角转动的问题
 *    6) Time 时间
 *    7) 3D 三维设置,如贴图格式设置成dds
 *    8) Terrain 地形最小采样率
 *    9) Measure tool 测量工具
 *    10)Units 单位,米
 *    11)Layers 图层,此处新建list,未加载任何图层loadedLayers
 * 3、通过对World.xml进行加载后,会加载上一次退出时对以上参数的设置。

  可以在路径‘C:\Users\yangfan\AppData\Roaming\NASA\World Wind\1.4.0.0(Win7)中查看配置文件World、WorldWind,主要采用XML序列化和反序列化实现。

 参考文献:   

         推荐此文

转载于:https://www.cnblogs.com/yhlx125/archive/2013/03/28/2784752.html

你可能感兴趣的文章
ASP.NET SignalR2持久连接层解析
查看>>
利用mk-table-checksum监测Mysql主从数据一致性操作记录
查看>>
Access自定义函数(人民币大写)
查看>>
云计算学习(3-2)云计算的由来-行业背景
查看>>
java file类
查看>>
HTML(一):HTML基本元素标签
查看>>
[hbase] 查询数据
查看>>
HTML5学习笔记(十一):JavaScript基础
查看>>
Java中的反射
查看>>
非[无]root权限 服务器 下安装perl以及perl模块
查看>>
[macOS] PHP双版本,5.6跟7.1
查看>>
asd
查看>>
python图片处理(一)
查看>>
Eclipse下导入外部jar包的3种方式
查看>>
【转】Nginx配置location总结及rewrite规则写法
查看>>
Matlab之合并音频
查看>>
前端自动化构建工具-yoman浅谈
查看>>
算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)
查看>>
Struts2新漏洞S2-046在线实验环境全球首发
查看>>
lambda续集——2
查看>>