worldwind学习系列一至六.docx

上传人:b****2 文档编号:18003063 上传时间:2023-08-05 格式:DOCX 页数:54 大小:284.88KB
下载 相关 举报
worldwind学习系列一至六.docx_第1页
第1页 / 共54页
worldwind学习系列一至六.docx_第2页
第2页 / 共54页
worldwind学习系列一至六.docx_第3页
第3页 / 共54页
worldwind学习系列一至六.docx_第4页
第4页 / 共54页
worldwind学习系列一至六.docx_第5页
第5页 / 共54页
worldwind学习系列一至六.docx_第6页
第6页 / 共54页
worldwind学习系列一至六.docx_第7页
第7页 / 共54页
worldwind学习系列一至六.docx_第8页
第8页 / 共54页
worldwind学习系列一至六.docx_第9页
第9页 / 共54页
worldwind学习系列一至六.docx_第10页
第10页 / 共54页
worldwind学习系列一至六.docx_第11页
第11页 / 共54页
worldwind学习系列一至六.docx_第12页
第12页 / 共54页
worldwind学习系列一至六.docx_第13页
第13页 / 共54页
worldwind学习系列一至六.docx_第14页
第14页 / 共54页
worldwind学习系列一至六.docx_第15页
第15页 / 共54页
worldwind学习系列一至六.docx_第16页
第16页 / 共54页
worldwind学习系列一至六.docx_第17页
第17页 / 共54页
worldwind学习系列一至六.docx_第18页
第18页 / 共54页
worldwind学习系列一至六.docx_第19页
第19页 / 共54页
worldwind学习系列一至六.docx_第20页
第20页 / 共54页
亲,该文档总共54页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

worldwind学习系列一至六.docx

《worldwind学习系列一至六.docx》由会员分享,可在线阅读,更多相关《worldwind学习系列一至六.docx(54页珍藏版)》请在冰点文库上搜索。

worldwind学习系列一至六.docx

worldwind学习系列一至六

WorldWind系列一:

顺利起航篇

来源:

博客园  作者:

无痕客

  今天从官方下载WorldWind1.4版的源代码开始研究,可是运行时,发现有很多问题。

下面是我的解决对策,帮助遇到相同问题的网友顺利起航!

  错误1:

  

  

  原因:

无法找到引用的DLL文件

  解决方法:

  1.更改发布模式为调试模式(最简单,不用重新添加引用)

  2.将Debug文件下所有文件复制到World_Wind_1.4.0_Source\WorldWind\bin\x86\Release目录下

  参看:

      

  假定所有的源文件的根目录为World_Wind_1.4.0_Source,在该目录下,找到World_Wind_1.4.0_Source\bin\Debug,将该目录下的Config、Data和Plugins目录,以及AviFile.dll、FlickrNet.dll、Org.Mentalis.Security.dll、ZedGraph.dll等拷贝粘贴到World_Wind_1.4.0_Source\WorldWind\bin\x86\Release目录下即可。

  错误2:

LoaderLock问题 

  解决方法:

  ctrl+D+E或alt+ctl+e或使用菜单(调试-》异常)——》异常窗口——》ManagerDebuggingAssistants——》去  掉LoaderLock选项

参照我的blog:

  错误3:

Debug调试状态下运行,生成成功,但没有启动程序

  原因:

不详

  解决方法:

  1ctrl+f5不调试下运行

  2.设置解决方案平台为x86

  下面是我搜集相关的内容,现转载其内容:

    

  NASAWorldWind开源项目配置详细解说

  2009-05-3119:

46

  NASAWorldWind开源项目配置详细解说

  NASAWorldWind是C#开发地个人电脑上地开源地3D图形虚拟地球系统。

它结合了美国国家航空航天局(NASA)从卫星拍摄地图像,这些图像来源于BlueMarble,Landsat7,SRTM,MODIS以及其它。

  用户可以到这里下载.net源码http:

//worldwind.arc.nasa.gov/

  下载后,打开解决方案,运用地是VS2005(2008)均可,一共有16个项目组成。

  配置步骤如下:

  一、安装DirectX

  编译运行之前首先要安装DirectX,因为WorlWind中的子项目有对其的引用,如下:

  PluginSDK项目需三个引用:

Microsoft.DirectX,Microsoft.DirectX.Direct3D,Microsoft.DirectX.Direct3DX;

  WorldWind项目需四个引用:

Microsoft.DirectX,Microsoft.DirectX.Direct3D,Microsoft.DirectX.Direct3DX,Microsoft.DirectX.DirectInput。

  DirectX是微软一系列技术地集成,用来提供Windows平台多媒体运行地API,支持应用程序、多媒体软件和3D游戏非常声效。

  我下载地是DirectX9.0c多语言版,解压后,运行程序DXSETUP.exe。

  二、修改语法错误

  不知何故,下载下来的源码有很低级的语法错误,而且犯错的地方比较多,不过,没关系,因为很容易修改。

语法错误的地方主要发生在表示经纬度的度的输出代码左右,往往是引号不配对,只需将缺失的引号添加完整即可。

  ----例子----:

  修改前:

  labelText+=string.Format("\nBearing:

{0:

f1}?

Azimuth.Degrees);

  修改后:

  labelText+=string.Format("\nBearing:

{0:

f1}?

",Azimuth.Degrees);

  这种语法的错误挺多,但要注意,缺失的引号包括单引号和双引号。

  三、其他引用的添加

  1、上述工作完成,重新编译项目,PluginSDK和WorldWindow得先编译生成Dll,以满足其他子项目引用所需;

  2、假定所有的源文件的根目录为World_Wind_1.4.0_Source,在该目录下,找到World_Wind_1.4.0_Source\bin\Debug,将该目录下的Config、Data和Plugins目录,以及AviFile.dll、FlickrNet.dll、Org.Mentalis.Security.dll、ZedGraph.dll等拷贝粘贴到World_Wind_1.4.0_Source\WorldWind\bin\x86\Release目录下即可。

  好了,完成上述工作后,你就可以成功编译运行WorldWind源码了。

编译过程中,出现的错误提示都不用理会,直管“继续”往下,直到“完成”。

你就可以看见WorldWind的运行窗口了。

  转载我的补充说明:

  1.“一、安装DirectX":

我之所以没遇到这个问题可能是因为我现在自己的电脑上安装了WorldWind的安装版,它会帮你装上DirectX的。

  2.“二、修改语法错误”:

我仍然遇到相关问题,是因为缺少单引号或双引号的问题。

但上面转载的修改可能有问题,就是要将“?

”转为“"”。

问号在此没意义的。

如果不去掉问号会出现下面的问题, 

  3.“三、其他引用的添加”中在Release模式下无法调试的,只适用于发布,不适合研究学习。

WorldWind系列二:

擒贼先擒王篇1

来源:

博客园  作者:

无痕客

有了WorldWind学习系列一的基础,我们已经可以进行正常调试运行啦!

可以先操作看看软件的功能吧,这样我们才可以知道WorldWind有哪些功能等待我们学习的。

     开始我们的“WorldWind学习系列二:

擒贼先擒王”分析WorldWind主窗体,从Main函数入口一步步解析学习。

至少对于我来说,里面有很多知识要学的。

(补充一下:

无法进入WorldWind.cs窗体的设计界面,这个问题我早就发现了,但没解决,我们根据功能直接看代码吧)

    1.  使用System.Version在内部,读取软件版本信息,并格式化输出。

我们在外面配置软件版本,“关于”部分中版本自动更改。

获取格式化版本号

     // Establish the version number string used for user display,

    // such as the Splash and Help->About screens.

    // To change the Application.ProductVersion make the

    // changes in \WorldWind\AssemblyInfo.cs

    // For alpha/beta versions, include " alphaN" or " betaN"

    // at the end of the format string.

    Version ver = new System.Version(Application.ProductVersion);

    Release = string.Format("{0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision);

    2.判断该软件是否已经有个实例启动,如果有,则不启动。

判断是否已启动实例

     // If World Wind is already running, pass any commandline

    // arguments from this instance, and quit.

    IntPtr handle = GetWWHandle();  //此处通过获取线程指针

    if (!

System.IntPtr.Zero.Equals(handle))

    {

     if(args.Length>0)

      NativeMethods.SendArgs( handle, string.Join("\n",args) );

     return;

    }

 此处通过获取线程指针的方式,让我们来解析GetWWHandle函数。

  public static IntPtr GetWWHandle()

   {

     return NativeMethods.FindWindow(null, "NASA World Wind");

   }

    可知,它调用了NativeMethods类的FindWindow方法,该方法实质上是引用user32.dll的非托管函数FindWindow。

也即:

GetWWHandle()调用了user32.dll的非托管函数FindWindow。

非托管函数调用

/// 

/// API function to find window based on WindowName and class.

/// 

[DllImport("user32.dll")]

internal static extern IntPtr FindWindow (string lpClassName, string lpWindowName);

   可参看我的平台调用:

C#使用非托管dll函数

     注:

此处判断是否已经有启动实例的方法可以借鉴。

我以前是通过自己写代码判断是否存在进程的方式来确定是否有实例启动了。

判断是否已存在该程序进程

        /// 

        /// 判断是否已经存在该程序进程

        /// 

        /// 

        private static bool IsExistProcess()

        {

            bool result = false;

            Process[] p = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Application.ExecutablePath));

            if (p !

= null && p.Length > 1)

            {

                result = true;

            }

            return result;

        }  

  3.判断计算机中已经存在的协议数目。

主要是针对.NetFrameWork1.1版的bug(不允许多于50个协议)。

因为该软件要启用自己的新协议"worldwind:

//"。

现在2.0以后不存在该问题啦。

  //abortif50bindingsproblempresentanduseroptstogotothedownloadpage

    if(BindingsCheck.FiftyBindingsWarning())return;

    虽然我们说该功能可以不要,但是其函数中的知识点还是值得一看的。

FiftyBindingsWarning()中主要是DetermineProtocolBindings()和IsBindingsHotFixApplied()。

前一个是判断绑定协议数,后一个是判断CLR的版本号。

        static int DetermineProtocolBindings() 

        {

            int errorNumber = 0;

            const long sizeOfOneProtocolInfoStructure = 628;//此处我们可知协议信息的结构体长度是固定的为628

            long sizeOfAllProtocolInfoStructures = 0;

            // request all protocol info structures, but provide no space to store them -

            // this will yield the total size of the structure array in bytes

            WSCEnumProtocols(IntPtr.Zero, IntPtr.Zero, ref sizeOfAllProtocolInfoStructures, ref errorNumber);

            if(errorNumber !

= WSAENOBUFS) return -1; // not what we expected, unable to determine number of bindings

            // divide total size by size of one structure to get number of bindings.

            return (int)(sizeOfAllProtocolInfoStructures / sizeOfOneProtocolInfoStructure);

        }

        // Determines whether the CLR version is newer than the first one that included the fix.

        static bool IsBindingsHotFixApplied() 

        {

            // check if CLR version is 1.1.4322.946 or higher

            return System.Environment.Version >= new Version("1.1.4322.946");

  //System.Environment.Version用来读取系统环境的版本号 

        }

 

 前一个函数DetermineProtocolBindings()同样也调用了外面的非托管代码函数。

如下:

  [DllImport("Ws2_32.dll")]

  staticexternintWSCEnumProtocols(IntPtrlpiProtocols,IntPtrlpProtocolBuffer,reflonglpdwBufferLength,refintlpErrno);

 

  今天先就写到这啦,我分析的太深入了,如果这样写下去要把这个系列写到100篇吧。

出于应用为目的其实不用分析的太透彻啦。

以后的系列中,我会多以提纲引导方式简化些内容,重点知识点我还会关注的。

WorldWind系列二:

擒贼先擒王篇2

来源:

博客园  作者:

无痕客

4.解析Main(string[]args)中参数args。

主要是在控制台中启动程序时同时赋予了参数的形式。

   // ParseArgs may set values that are used elsewhere,

    // such as startFullScreen and CurrentSettingsDirectory.

    ParseArgs(args);

     args中参数可能是:

      "worldwind:

//":

加载定位显示球体某处。

     “/f”:

全屏启动。

      “/s=……”:

指定加载“配置”的文件夹路径。

       这里要注意的事,Main函数一般是没有参数的,如果我们以后要写可以在控制台下给启动程序传入参数,可以借鉴一下。

  5.加载上次使用的配置信息,包括上次使用的WorldWind主窗体使用信息和上次使用的World球体显示信息

加载配置

if(CurrentSettingsDirectory == null)

{

// load program settings from default directory

LoadSettings();

World.LoadSettings();

}

else

{

LoadSettings(CurrentSettingsDirectory);

World.LoadSettings(CurrentSettingsDirectory);

}

 

这里有几个知识点可以学习一下:

(1)C#对象的序列化为XML文件和反序列化Xml文件为对象,参看:

SettingsBase类的Load方法中的反序列化:

XmlSerializer ser = new XmlSerializer(defaultSettings.GetType());

using(TextReader tr = new StreamReader(fileName)) 

{

settings = (SettingsBase)ser.Deserialize(tr);

settings.m_fileName = fileName; // remember where we loaded from for a later save

}

 

 

(2)C#中的StreamWriter类的学习使用

Log类主要用于输出ErrorBugWarning等输出记录。

主WorldWind.log是保存所有的记录,然后对Debug信息单独输出单个的.log文件。

logWriter负责写WorldWind.log

logPath = DefaultSettingsDirectory();

Directory.CreateDirectory(logPath);

// TODO:

 do not hardcode logfile name?

logFilePath = Path.Combine( logPath, "WorldWind.log" );

logWriter = new StreamWriter(logFilePath, true);

logWriter.AutoFlush = true;

 

publicstaticvoidWrite(Exceptioncaught)负责写单独每个Error的输出。

单个Log文件输出

string functionName = "Unknown";

 string[] stacktrace = null;

if (caught.StackTrace !

= null)

 {

 stacktrace = caught.StackTrace.Split('\n');

 string firstStackTraceLine = stacktrace[0];

  functionName = firstStackTraceLine.Trim().Split(" (".ToCharArray())[1];

  }

 string logFileName = string.Format("DEBUG_{0}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ffff"));  //以DEBUG+日期作为文件名

 string logFullPath = Path.Combine(logPath, logFileName);

 using (StreamWriter sw = new StreamWriter(logFullPath, false))

 {

    sw.WriteLine(caught.ToString());

  }

 

 

  6.启动主程序,还有对线程异常事件处理和程序空闲处理(防止过度休眠)

Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

MainApplication app = new MainApplication();

Application.Idle += new EventHandler(app.WorldWindow.OnApplicationIdle);

Application.Run(app);

 

  7.程序启动后,将状态配置保存起来

    //SaveWorldsettings

    World.Settings.Save();

    其中用到了,将World的配置对象WorldSettings(注意:

不是其父类SettingsBase,只是调用其父类的Save方法)序列化为XML文件,并保存,以备下次启动前读取World(即球体)上次状态配置。

将WorldSettings序列化

        public virtual void Save(string fileName) 

        {

            XmlSerializer ser = null;

            try 

            {

                ser = new XmlSerializer(this.GetType());

                using(TextWriter tw = new StreamWriter(fileName)) 

                {

                    ser.Serialize(tw, this);

                }

            }

            catch(Exception ex) 

            {

                throw new System.Exception(String.Format("Saving settings class '{0}' to {1} failed", thi

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2