﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-帅哥帅</title><link>http://www.cppblog.com/lll109383670/</link><description /><language>zh-cn</language><lastBuildDate>Wed, 15 Apr 2026 02:55:56 GMT</lastBuildDate><pubDate>Wed, 15 Apr 2026 02:55:56 GMT</pubDate><ttl>60</ttl><item><title>图形学资源（期刊与实验室）</title><link>http://www.cppblog.com/lll109383670/archive/2012/03/08/167402.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Thu, 08 Mar 2012 07:29:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/03/08/167402.html</guid><wfw:comment>http://www.cppblog.com/lll109383670/comments/167402.html</wfw:comment><comments>http://www.cppblog.com/lll109383670/archive/2012/03/08/167402.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lll109383670/comments/commentRss/167402.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lll109383670/services/trackbacks/167402.html</trackback:ping><description><![CDATA[<div><div align="center"><span>国内外图形学研究机构</span></div></div><div id="freenr"><ul><li>中国科学院深圳先进技术研究院：<a href="http://www.siat.cas.cn/gkjj/jgjj/">http://www.siat.cas.cn/gkjj/jgjj/</a><br />&nbsp;</li><li>微软亚洲研究院：<a href="http://www.msra.cn/">http://www.msra.cn/</a><br />&nbsp;</li><li>Carnegie Mellon School of Computer Science：<a href="http://www.cs.cmu.edu/">http://www.cs.cmu.edu/</a><br />&nbsp;</li><li>Visualization &amp; Interface Design Innovation：<a href="http://vidi.cs.ucdavis.edu/">http://vidi.cs.ucdavis.edu/</a><br />&nbsp;</li><li>Graduate School of Frontier Sciences，The University of Tokyo：<a href="http://www.k.u-tokyo.ac.jp/complex/index-e.html">http://www.k.u-tokyo.ac.jp/complex/index-e.html</a><br />&nbsp;</li><li>University of Illinois at Urbana-Champaign &#8226; College of Engineering Department of Computer Science：<a href="http://cs.illinois.edu/">http://cs.illinois.edu/<br /><br /><br /><div><div align="center"><span>国际会议列表</span></div></div><div id="freenr"><div><p><span><strong>国际会议</strong></span></p><ul><li>ACM Symposium on Solid and Physical Modeling&nbsp;&nbsp; (ACM SPM)<br />&nbsp;</li><li>Intl Conf on Machine Learning&nbsp;&nbsp; (ICML)<br />&nbsp;</li><li>ACM SIGGRAPH/Eurographics Symposium on Computer Animation(SCA)<br />&nbsp;</li><li>International Conference on Computer Vision (Theory and Applications) (ICCV)<br />&nbsp;</li><li>IEEE Computer Society Conference on Computer Vision and Pattern Recognition(CVPR)<br />&nbsp;</li><li>IEEE Visualization<br />&nbsp;</li><li>ACM International Conference for Human-computer Interaction(ACM HCI)<br />&nbsp;</li><li>ACM SIGIR Special Interest Group on Information Retrieval(SIGIR)<br />&nbsp;</li><li>ACM Special Interest Group Conf on Knowledge Discovery in Data and Data Mining(SIGKDD)<br />&nbsp;</li><li>International Symposium on Computer Architecture(ISCA)<br />&nbsp;</li><li>IEEE Virtual Reality(VR)</li></ul></div></div><br /><br /><br /><br /><div><div align="center"><span>期刊杂志列表</span></div></div><div id="freenr"><div><h3><span><span>Computer Graphics Related Journals</span></span></h3><ul><li>ACM Computer Graphics(SIGGRAPH)<br />&nbsp;</li><li>Communications of the ACM<br />&nbsp;</li><li>ACM Transactions on Graphics<br />&nbsp;</li><li>IEEE Transactions on Visualization and Computer Graphics<br />&nbsp;</li><li>IEEE Computer Graphics and Applications<br />&nbsp;</li><li>Graphical Models<br />&nbsp;</li><li>Computer Aided Design<br />&nbsp;</li><li>Computer Aided Geometric Design<br />&nbsp;</li><li>Computer Animation and Virtual Worlds<br />&nbsp;</li><li>Presence: Teleoperators &amp; Virtual Environments<br />&nbsp;</li><li>The Visual Computer<br />&nbsp;</li><li>Computer Graphics Forum<br />&nbsp;</li><li>Computers &amp; Graphics<br />&nbsp;</li><li>Computational Geometry-Theory and Applications<br />&nbsp;</li><li>International Journal of Computational Geometry and Applications<br />&nbsp;</li><li>Journal of Visualization<br />&nbsp;</li><li>Design Studies<br />&nbsp;</li><li>Engineering with Computers<br />&nbsp;</li><li>Computer Graphics World<br />&nbsp;</li><li>ACM Computers in Entertainment<br />&nbsp;</li><li>journal of graphics tools<br />&nbsp;</li><li>The International Journal of Visual Computing<br />&nbsp;</li><li>Virtual Reality<br />&nbsp;</li><li>International Journal of Shape Modeling<br />&nbsp;</li><li>International Journal of Virtual Reality<br />&nbsp;</li><li>Virtual Reality: Research Development and Applications<br />&nbsp;</li><li>Machine Graphics and Vision<br />&nbsp;</li><li>International Journal of Image and Graphics<br />&nbsp;</li><li>International Journal of CAD/CAM</li></ul><p><span><strong>Image Processing Journals Perhaps Related to Computer Graphics</strong></span></p><ul><li>IEEE Transactions on Pattern Analysis and Machine Intelligence<br />&nbsp;</li><li>IEEE Transactions on Image Processing<br />&nbsp;</li><li>Computer Vision and Image Understanding<br />&nbsp;</li><li>Image and Vision Computing<br />&nbsp;</li><li>Pattern Recognition<br />&nbsp;</li><li>Pattern Recognition Letters<br />&nbsp;</li><li>Journal of Visual Communication and Image Representation<br />&nbsp;</li><li>Real Time Imaging</li></ul></div></div><br /><br /><br /><br /></a></li></ul></div><img src ="http://www.cppblog.com/lll109383670/aggbug/167402.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-03-08 15:29 <a href="http://www.cppblog.com/lll109383670/archive/2012/03/08/167402.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>3D Graphic File Formats</title><link>http://www.cppblog.com/lll109383670/archive/2012/03/01/166830.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Wed, 29 Feb 2012 18:11:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/03/01/166830.html</guid><wfw:comment>http://www.cppblog.com/lll109383670/comments/166830.html</wfw:comment><comments>http://www.cppblog.com/lll109383670/archive/2012/03/01/166830.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lll109383670/comments/commentRss/166830.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lll109383670/services/trackbacks/166830.html</trackback:ping><description><![CDATA[<a href="http://www.mediatel.lu/workshop/graphic/3D_fileformat/h_format.html">http://www.mediatel.lu/workshop/graphic/3D_fileformat/h_format.html</a><img src ="http://www.cppblog.com/lll109383670/aggbug/166830.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-03-01 02:11 <a href="http://www.cppblog.com/lll109383670/archive/2012/03/01/166830.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UML学习</title><link>http://www.cppblog.com/lll109383670/archive/2012/02/25/166483.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Sat, 25 Feb 2012 06:17:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/02/25/166483.html</guid><wfw:comment>http://www.cppblog.com/lll109383670/comments/166483.html</wfw:comment><comments>http://www.cppblog.com/lll109383670/archive/2012/02/25/166483.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lll109383670/comments/commentRss/166483.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lll109383670/services/trackbacks/166483.html</trackback:ping><description><![CDATA[<br /><br />UML<br />组件图：<br />参考文章：<a href="http://www.ibm.com/developerworks/rational/library/dec04/bell">http://www.ibm.com/developerworks/rational/library/dec04/bell</a>&nbsp;<br />组件图表示：<br /><strong>订单系统对库存系统的引用：</strong><br /><img src="http://www.ibm.com/developerworks/rational/library/dec04/bell" alt="" /><img src="http://www.ibm.com/developerworks/rational/library/dec04/bell/Bell-Fig1.gif" width="224" height="264" alt="" /><br /><br /><strong>组件接口的二种表示方法：</strong><br /><img src="http://www.ibm.com/developerworks/rational/library/dec04/bell/Bell-Fig3.gif" alt="" /><img src="http://www.ibm.com/developerworks/rational/library/dec04/bell/Bell-Fig4.gif" alt="" /><br /><br />第二副图左边表示组件提供的对外接口（：P 可以叫棒棒糖接口），右边的是需要外部提供的接口（插座接口）<br /><br /><br /><strong>各个组件间的关系图<br /><img src="http://www.ibm.com/developerworks/rational/library/dec04/bell/Bell-Fig5.gif" width="468" height="266" alt="" /><br /><br /></strong>组件内部关系完整图：<br /><img src="http://www.ibm.com/developerworks/rational/library/dec04/bell/Bell-Fig7.gif" alt="" /><br /><br /><strong>序列图：</strong><br />参考文章：<a href="http://www.ibm.com/developerworks/rational/library/3101.html">http://www.ibm.com/developerworks/rational/library/3101.html</a>&nbsp;<br /><img src="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/feb04/3101_figure4.jpg" alt="" /><br /><strong>普通形式：</strong><br />发送消息到下一个模块中，图中表示analyst是FinacialAnalyst的一个实例，它用了system实例的getAvailableReports()这个方法，注意，发送的方法消息是由下一个模块实现。<br /><strong>调用自己的实现的函数：</strong><br /><img src="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/feb04/3101_figure5.jpg" alt="" /><br /><br /><br /><strong>几个特殊的情况</strong><br />if...else<br /><img src="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/feb04/3101_figure8.jpg" alt="" /><br /><br />switch<br /><img src="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/feb04/3101_figure9.jpg" width="626" height="527" alt="" /><br /><br /><br />循环：<br /><img src="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/feb04/3101_figure10_small.jpg" alt="" /><br /><br />引用另一个序列图：<br /><img src="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/feb04/3101_figure11.jpg" alt="" /><br /><img src="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/feb04/3101_figure14.jpg" alt="" /><br /><br />break<br /><br /><img src="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/feb04/3101_figure16.jpg" alt="" /><br />parallel<br /><img src="http://www.ibm.com/developerworks/rational/library/content/RationalEdge/feb04/3101_figure17.jpg" width="613" height="446" alt="" /><br /><img src ="http://www.cppblog.com/lll109383670/aggbug/166483.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-02-25 14:17 <a href="http://www.cppblog.com/lll109383670/archive/2012/02/25/166483.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>wxWidget小试</title><link>http://www.cppblog.com/lll109383670/archive/2012/02/24/166370.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Thu, 23 Feb 2012 16:53:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/02/24/166370.html</guid><wfw:comment>http://www.cppblog.com/lll109383670/comments/166370.html</wfw:comment><comments>http://www.cppblog.com/lll109383670/archive/2012/02/24/166370.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lll109383670/comments/commentRss/166370.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lll109383670/services/trackbacks/166370.html</trackback:ping><description><![CDATA[之前用wxlua写过脚本界面，今天尝试了一下wxWidget的win32版本。<br />没有界面设计工具怎么行，什么年代了肯定不能纯手工打造界面。<br />于是找得code:Blocks，开源的，才22M，一用，很牛B，基本上编译器功能全了，基于插件的设计和ECLIPCE一样强大。<br />但是如果用vs自带的cl编译的话，还要配置很多，设置断点还得用cdb，太麻烦了，我不就是想找一个界面设计的工具么，你给我连编译器都准备好了，过了。window下还是习惯Vs，没办法，房子都是别人建的，在别人房子里还是得守别人的规则。<br />不过有一点，如果是跨平台的话，用code:Blocks+GCC+wxWidget绝对是强大，而且还能在mac中一样用啊，强大啊强大，汗奔。不过鉴于本人太懒，不想编译gcc版本的wxWidget了，还是先放下这个诱人的工具。<br />最后尝试开源的，也没什么好选择的，就WxFormBuilder这个东东了。<br />设计与编码分离，也算是比较不错的选择了，以后做界面就用他了。MFC,win32的东西实在是不想碰，实在是不利于水平的提高，界面也丑死了。<br />不过wx，几M的dll，也是很蛋疼的。快速开发界面的有木有，有木有，一定要我用脚本来界面么。<br /><br />设计好界面，做一个继承类，直接加入工程中，以后就界面就交给基类了，改动的话，直接复制过来就好了，我们的部分逻辑在派生的类中进行。<br />用widget2.9+wXForm3.2做界面时，调试时会报错：<br />无法解析Sizer::Remove(wxWindow*) ，跟踪进去看发现如下定义 
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">1</span><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">#if</span><span style="color: #000000">&nbsp;WXWIN_COMPATIBILITY_2_6</span><span style="color: #000000"><br /></span><span style="color: #008080">2</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;Deprecated&nbsp;in&nbsp;2.6&nbsp;since&nbsp;historically&nbsp;it&nbsp;does&nbsp;not&nbsp;delete&nbsp;the&nbsp;window,<br /></span><span style="color: #008080">3</span><span style="color: #008000"><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;use&nbsp;Detach&nbsp;instead.</span><span style="color: #008000"><br /></span><span style="color: #008080">4</span><span style="color: #008000"><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;wxDEPRECATED(&nbsp;</span><span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;Remove(&nbsp;wxWindow&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">window&nbsp;)&nbsp;);<br /></span><span style="color: #008080">5</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">#endif</span><span style="color: #000000">&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;WXWIN_COMPATIBILITY_2_6</span></div>原来这个东东已经过时了，是为了兼容2.6所保留了，由于我用的是2.9，只兼容2.8，由于在生成wx库的时候，没有定义2.6的宏，所以肯定没这没个函数的定义啦。<br />但是由于wx/setup 
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;WXWIN_COMPATIBILITY_2_6&nbsp;1</span></div>里，有如下定义，这样生成库时不兼容2.6，头文件里却定义为1.<br />改回来：<br />#define WXWIN_COMPATIBILITY_2_6 0<br /><br />wxFrom自动生成四个文件<br />BaseForm.h BaseForm.cpp<br />AppForm.h AppForm.cpp<br />全部复制到工程里<br />然后：<br />.h<br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">#pragma&nbsp;&nbsp;once<br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">wx</span><span style="color: #000000">/</span><span style="color: #000000">wx.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;TestWxFrame&nbsp;:&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;wxApp<br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img id="Codehighlighter1_67_143_Open_Image" onclick="this.style.display='none'; Codehighlighter1_67_143_Open_Text.style.display='none'; Codehighlighter1_67_143_Closed_Image.style.display='inline'; Codehighlighter1_67_143_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_67_143_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_67_143_Closed_Text.style.display='none'; Codehighlighter1_67_143_Open_Image.style.display='inline'; Codehighlighter1_67_143_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_67_143_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_67_143_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;TestWxFrame();<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">~</span><span style="color: #000000">TestWxFrame();<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;OnInit();<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />DE CLARE_APP(TestWxFrame)</span></div><br />.cpp<br /><br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">1</span><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">IMPLEMENT_APP(TestWxFrame)<br /></span><span style="color: #008080">2</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;TestWxFrame::OnInit()<br /></span><span style="color: #008080">3</span><span style="color: #000000"><img id="Codehighlighter1_54_137_Open_Image" onclick="this.style.display='none'; Codehighlighter1_54_137_Open_Text.style.display='none'; Codehighlighter1_54_137_Closed_Image.style.display='inline'; Codehighlighter1_54_137_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_54_137_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_54_137_Closed_Text.style.display='none'; Codehighlighter1_54_137_Open_Image.style.display='inline'; Codehighlighter1_54_137_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_54_137_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_54_137_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">4</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;AppForm</span><span style="color: #000000">*</span><span style="color: #000000">TF&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;AppForm((wxWindow</span><span style="color: #000000">*</span><span style="color: #000000">)NULL);<br /></span><span style="color: #008080">5</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;TF</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Show(</span><span style="color: #0000ff">true</span><span style="color: #000000">);<br /></span><span style="color: #008080">6</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /></span><span style="color: #008080">7</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">8</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="color: #008080">9</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /></span></div><br /><br />DECLARE_APP()这个不用说了，和MFC一样的，动态声明全局函数wxGetApp()<br /><span style="color: #008080">
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">1</span><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;wxDECLARE_APP(appname)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</span><span style="color: #000000"><br /></span><span style="color: #008080">2</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">extern</span><span style="color: #000000">&nbsp;appname</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;wxGetApp()</span></div></span><br />IMPLEMENT_APP()没什么新意，界面消息等机制就那么一回事，包括XNA,OGRE等的回调机制都是利用多虚性。这个基类A定义好虚函数，在派生类B中重载虚函数如上面的OnInit(),然后再在循环中调用A * = GetApp()得到B类的指针，这样不管B怎么变，只要是A的派生类，重载了一些固有的行为，整个框架都不需要任何改变。（- -！，这也是刚学习MFC时，会被搞晕了的原因，因为所有的细节都被隐藏起来了，更不用说他的消息回调机制了，太过方便了就让人变得蠢，所以不太喜欢微软的东东，越学越成为一个CODE FARMER，不用费脑筋的。不过DX除外）<br />下面是隐藏的东东，一目了然，把它脱光光一看，就没有之前的欲望啦，原来也是main，原来也是地球人写的代码。 
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;wxIMPLEMENT_APP(appname)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;wxIMPLEMENT_WX_THEME_SUPPORT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;wxIMPLEMENT_APP_NO_THEMES(appname)<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;wxIMPLEMENT_APP_NO_THEMES(appname)&nbsp;&nbsp;\</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;wxIMPLEMENT_WXWIN_MAIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;wxIMPLEMENT_APP_NO_MAIN(appname)<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">：）熟悉的WinMain来了</span><span style="color: #008000"><br /></span><span style="color: #008080">10</span><span style="color: #008000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;wxIMPLEMENT_WXWIN_MAIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</span><span style="color: #000000"><br /></span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">extern</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">C</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;WINAPI&nbsp;WinMain(HINSTANCE&nbsp;hInstance,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HINSTANCE&nbsp;hPrevInstance,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wxCmdLineArgType&nbsp;WXUNUSED(lpCmdLine),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nCmdShow)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_682_1314_Open_Image" onclick="this.style.display='none'; Codehighlighter1_682_1314_Open_Text.style.display='none'; Codehighlighter1_682_1314_Closed_Image.style.display='inline'; Codehighlighter1_682_1314_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_682_1314_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_682_1314_Closed_Text.style.display='none'; Codehighlighter1_682_1314_Open_Image.style.display='inline'; Codehighlighter1_682_1314_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_682_1314_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_682_1314_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wxDISABLE_DEBUG_SUPPORT();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img id="Codehighlighter1_923_989_Open_Image" onclick="this.style.display='none'; Codehighlighter1_923_989_Open_Text.style.display='none'; Codehighlighter1_923_989_Closed_Image.style.display='inline'; Codehighlighter1_923_989_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_923_989_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_923_989_Closed_Text.style.display='none'; Codehighlighter1_923_989_Open_Image.style.display='inline'; Codehighlighter1_923_989_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_923_989_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_923_989_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;NB:&nbsp;We&nbsp;pass&nbsp;NULL&nbsp;in&nbsp;place&nbsp;of&nbsp;lpCmdLine&nbsp;to&nbsp;behave&nbsp;the&nbsp;same&nbsp;as&nbsp;&nbsp;</span><span style="color: #008000">*/</span></span><span style="color: #000000">&nbsp;\<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img id="Codehighlighter1_1002_1068_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1002_1068_Open_Text.style.display='none'; Codehighlighter1_1002_1068_Closed_Image.style.display='inline'; Codehighlighter1_1002_1068_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1002_1068_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1002_1068_Closed_Text.style.display='none'; Codehighlighter1_1002_1068_Open_Image.style.display='inline'; Codehighlighter1_1002_1068_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_1002_1068_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_1002_1068_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Borland-specific&nbsp;wWinMain()&nbsp;above.&nbsp;If&nbsp;it&nbsp;becomes&nbsp;needed&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">*/</span></span><span style="color: #000000">&nbsp;\<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img id="Codehighlighter1_1081_1147_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1081_1147_Open_Text.style.display='none'; Codehighlighter1_1081_1147_Closed_Image.style.display='inline'; Codehighlighter1_1081_1147_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1081_1147_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1081_1147_Closed_Text.style.display='none'; Codehighlighter1_1081_1147_Open_Image.style.display='inline'; Codehighlighter1_1081_1147_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_1081_1147_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_1081_1147_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;pass&nbsp;lpCmdLine&nbsp;to&nbsp;wxEntry()&nbsp;here,&nbsp;you'll&nbsp;have&nbsp;to&nbsp;fix&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">*/</span></span><span style="color: #000000">&nbsp;\<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img id="Codehighlighter1_1160_1226_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1160_1226_Open_Text.style.display='none'; Codehighlighter1_1160_1226_Closed_Image.style.display='inline'; Codehighlighter1_1160_1226_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1160_1226_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1160_1226_Closed_Text.style.display='none'; Codehighlighter1_1160_1226_Open_Image.style.display='inline'; Codehighlighter1_1160_1226_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_1160_1226_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_1160_1226_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wWinMain()&nbsp;above&nbsp;too.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">*/</span></span><span style="color: #000000">&nbsp;\<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;wxEntry(hInstance,&nbsp;hPrevInstance,&nbsp;NULL,&nbsp;nCmdShow);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;wxIMPLEMENT_WXWIN_MAIN_BORLAND_NONSTANDARD<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="color: #008080">26</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">&lt;动态定义GetApp()之类的来了</span><span style="color: #008000"><br /></span><span style="color: #008080">27</span><span style="color: #008000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;wxIMPLEMENT_APP_NO_MAIN(appname)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</span><span style="color: #000000"><br /></span><span style="color: #008080">28</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;wxAppConsole&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">wxCreateApp()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img id="Codehighlighter1_1620_1936_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1620_1936_Open_Text.style.display='none'; Codehighlighter1_1620_1936_Closed_Image.style.display='inline'; Codehighlighter1_1620_1936_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_1620_1936_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1620_1936_Closed_Text.style.display='none'; Codehighlighter1_1620_1936_Open_Image.style.display='inline'; Codehighlighter1_1620_1936_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_1620_1936_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_1620_1936_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wxAppConsole::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">your&nbsp;program</span><span style="color: #000000">"</span><span style="color: #000000">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;appname;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;wxAppInitializer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wxTheAppInitializer((wxAppInitializerFunction)&nbsp;wxCreateApp);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img id="Codehighlighter1_2193_2248_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2193_2248_Open_Text.style.display='none'; Codehighlighter1_2193_2248_Closed_Image.style.display='inline'; Codehighlighter1_2193_2248_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_2193_2248_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_2193_2248_Closed_Text.style.display='none'; Codehighlighter1_2193_2248_Open_Image.style.display='inline'; Codehighlighter1_2193_2248_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;appname</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;wxGetApp()&nbsp;</span><span id="Codehighlighter1_2193_2248_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_2193_2248_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">static_cast</span><span style="color: #000000">&lt;</span><span style="color: #000000">appname</span><span style="color: #000000">*&gt;</span><span style="color: #000000">(wxApp::GetInstance());&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;\<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img alt="" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;wxDECLARE_APP(appname)</span></div><br />生成图：（比较丑）<br /><br /><br /><img style="width: 645px; height: 513px" height="513" alt="" src="http://www.cppblog.com/images/cppblog_com/lll109383670/未命名1.jpg" width="645" border="0" /><br />不要忘记wx也是有操作系统底层函数的哦，基本上不用用到win32的API，一个wx就可以解决所有问题了。最重要的，他是跨平台的！所以尽量不要用win API.<br /><img src ="http://www.cppblog.com/lll109383670/aggbug/166370.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-02-24 00:53 <a href="http://www.cppblog.com/lll109383670/archive/2012/02/24/166370.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>地形制作全攻略（转载）</title><link>http://www.cppblog.com/lll109383670/archive/2012/02/22/166290.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Wed, 22 Feb 2012 15:16:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/02/22/166290.html</guid><wfw:comment>http://www.cppblog.com/lll109383670/comments/166290.html</wfw:comment><comments>http://www.cppblog.com/lll109383670/archive/2012/02/22/166290.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lll109383670/comments/commentRss/166290.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lll109383670/services/trackbacks/166290.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: GameRes游戏开发资源网http://www.gameres.com &nbsp;地形制作全攻略作者：程东哲&nbsp;&nbsp;前言零．地形简介一．地形生成算法1．Fault Formation2．Midpoint Displacement二．小纹理生成大地形纹理1．地形纹理介绍2．小纹理插值生成大纹理。3．添加细节纹理4．添加光...&nbsp;&nbsp;<a href='http://www.cppblog.com/lll109383670/archive/2012/02/22/166290.html'>阅读全文</a><img src ="http://www.cppblog.com/lll109383670/aggbug/166290.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-02-22 23:16 <a href="http://www.cppblog.com/lll109383670/archive/2012/02/22/166290.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Direct3D中实现图元的鼠标拾取（转）</title><link>http://www.cppblog.com/lll109383670/archive/2012/02/22/166211.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Wed, 22 Feb 2012 02:27:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/02/22/166211.html</guid><wfw:comment>http://www.cppblog.com/lll109383670/comments/166211.html</wfw:comment><comments>http://www.cppblog.com/lll109383670/archive/2012/02/22/166211.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/lll109383670/comments/commentRss/166211.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lll109383670/services/trackbacks/166211.html</trackback:ping><description><![CDATA[<span style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="center"><strong>文章来自：<a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm">http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm</a><br />Direct3D<span style="font-family: 宋体">中实现图元的鼠标拾取</span></strong></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="center">　</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="center">BY 重剑，2004.5.28&nbsp;<a href="http://www.heavysword.com/">重剑空间</a>&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><strong>索引：</strong></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#1、什么是拾取，拾取能做什么？">1、什么是拾取，拾取能做什么？</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#2、拾取操作的步骤和实现">2、拾取操作的步骤和实现</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#2.1．&nbsp; 变换并获得通过视点和屏幕上点击点的射线矢量（Dir）">&nbsp;&nbsp;&nbsp; 2.1．&nbsp; 变换并获得通过视点和屏幕上点击点的射线矢量（Dir）</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">　</p>
<blockquote>
<blockquote>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#2.1.1 确定鼠标选取点的屏幕坐标">2.1.1 确定鼠标选取点的屏幕坐标</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">　</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#2.1.2 得到Dir在观察坐标空间内的表示">2.1.2 得到Dir在观察坐标空间内的表示</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">　</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#2.1.3 转换Dir到世界坐标空间，并得到观察点在世界坐标系中的坐标">2.1.3 转换Dir到世界坐标空间，并得到观察点在世界坐标系中的坐标</a></p></blockquote></blockquote>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">　</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#2.2 &nbsp; 使用射线矢量对场景中的所有三角形图元求交，获得三角形索引值和重心坐标。">&nbsp;&nbsp;&nbsp; 2.2 &nbsp; 使用射线矢量对场景中的所有三角形图元求交，获得三角形索引值和重心坐标。</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">　</p>
<blockquote>
<blockquote>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#2.2.1 D3D扩展函数实现求交">2.2.1 D3D扩展函数实现求交</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#2..2.2射线三角面相交的数学算法">2.2.2射线三角面相交的数学算法</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#2.2.3&nbsp; 拾取完成根据获得的中心坐标计算我们关心的常见量，。">2.2.3&nbsp; 拾取完成根据获得的中心坐标计算我们关心的常见量</a></p></blockquote></blockquote>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#3、结束及声明">3、结束及声明</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#4、参考文献">4、参考文献</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">　</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><a href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm#补充：重心坐标的概念">补充：重心坐标的概念</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">　</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'">　</p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'">　</p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'">3D<span style="font-family: 宋体">交互图形应用程序中，常常要用鼠标去选择图形，其实现的机制基于鼠标拾取算法。本文主要讲述如何在</span>D3D<span style="font-family: 宋体">中实现图元的鼠标拾取。为了讨论简单，本文假定读者理解</span>D3D&nbsp;<span style="font-family: 宋体">坐标变换流程和基本的图形学知识，如果阅读有困难请参考相关资料。</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="1、什么是拾取，拾取能做什么？">1、什么是拾取，拾取能做什么？</a></strong></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">首先，拾取操作指当我们在屏幕上用鼠标点击某个图元应用程序能返回该图元的一个标志和某些相关信息。有图形程序设计经验的人都知道，有这些信息就表示我们有了对该图元的控制权，我们可以删除，可以编辑，可以任意对待该图元，至于你到底想干什么，就是阁下自己的事了</span>^_^<span style="font-family: 宋体">。</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="2、拾取操作的步骤和实现">2、拾取操作的步骤和实现</a></strong></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'" align="left"><span style="font-family: 宋体">拾取算法的思想很简单：得到鼠标点击处的屏幕坐标，通过投影矩阵和观察矩阵把该坐标转换为通过视点和鼠标点击点的一条射入场景的光线，该光线如果与场景模型的三角形相交（本文只处理三角形图元），则获取该相交三角形的信息。本文讲述的方法除可以得到三角形的一个索引号以外还可以得到相交点的重心坐标。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体">从数学角度来看，我们只要得到射线的方向矢量和射线的出射点，我们就具备了判断射线与空间一个三角面是否相交的条件，本文主要讨论如何获得这些条件，并描述了射线三角面相交判断算法和</span>D3D<span style="font-family: 宋体">的通常实现方法。</span>&nbsp;&nbsp;&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">根据拾取操作的处理顺序，大概可以依次分为以下几个步骤</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><a name="2.1．&nbsp; 变换并获得通过视点和屏幕上点击点的射线矢量（Dir）"><strong>2.1</strong><strong>．</strong><span style="font-weight: 700; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;</span><strong><span style="font-family: 宋体">变换并获得通过视点和屏幕上点击点的射线矢量（</span>Dir<span style="font-family: 宋体">）</span></strong></a></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">详细介绍之前，为了大家方便理解，我们要先简单说一下</span>d3d<span style="font-family: 宋体">坐标转换的大概流程，如下图</span>:</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; font-family: 'Times New Roman'"><img height="58" alt="" src="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.files/image002.jpg" width="448" border="0" v:shapes="_x0000_s1032" /></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">所以我们要通过一系列的反变换，得到我们关心的值在世界坐标中的表示。</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="2.1.1 确定鼠标选取点的屏幕坐标">2.1.1 确定鼠标选取点的屏幕坐标</a></strong></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">这一步是非常简单的</span>Windows<span style="font-family: 宋体">给我们提供了</span>API<span style="font-family: 宋体">来完成屏幕坐标的获取，使用</span>GetCursorPos<span style="font-family: 宋体">获得鼠标指针位置，然后再利用</span>ScreenToClient<span style="font-family: 宋体">转换坐标到客户区坐标系</span>(<span style="font-family: 宋体">以窗口视区左上角为坐标原点，单位为像素</span>)<span style="font-family: 宋体">，设该坐标为（</span>POINT screenPt<span style="font-family: 宋体">）。</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="2.1.2 得到Dir在观察坐标空间内的表示">2.1.2 得到Dir在观察坐标空间内的表示</a></strong></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">在观察坐标系中，</span>Dir<span style="font-family: 宋体">是一条从观察坐标原点出发的射线，所以我们只需要再确定一个该射线经过的点，就可以得到它在观察坐标系中的表示。假设我们要求的射线上的另外一点为该射线与透视投影平截头体近剪切面的交点，针对最普遍的透视投影而言，透视投影平截头体经投影变换后，变成一个</span>1/2<span style="font-family: 宋体">立方体（请允许我这么叫</span>^_^<span style="font-family: 宋体">，因为它的大小为一个正方体的一半，</span>x,y<span style="font-family: 宋体">方向边长为</span>2<span style="font-family: 宋体">，</span>z<span style="font-family: 宋体">方向为</span>1<span style="font-family: 宋体">）如图：</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'" align="center"><img height="118" alt="" src="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.files/image004.jpg" width="139" border="0" v:shapes="_x0000_s1031" /></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">投影坐标系以近剪切面中心为坐标原点，该立方体从</span>z<span style="font-family: 宋体">轴负向看过去与图形程序视区相对应，最终近剪切面（前剪切面）上一点与屏幕坐标之间的对应关系如下图所示：</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><img height="149" alt="" src="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.files/image006.jpg" width="448" border="0" v:shapes="_x0000_s1030" /></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'" align="center">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><strong><span style="font-family: 宋体">根据比例关系，</span>screenPt<span style="font-family: 宋体">与投影空间上的点</span>projPt<span style="font-family: 宋体">之间的关系为</span></strong></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">假设图形程序窗口的宽为</span>screenWidth,<span style="font-family: 宋体">高为</span>screenHeight,</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">projPt.x = (screenPt.x-screenWidth/2)/screenWidth*2; （公式1）</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">projPt.y = (screenPt.y-screenHeight/2)/screenHeight*2; （公式2）</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">projPt.z =0;（实际该值可任意取，不影响最终结果。为了处理简单，我们取改值为0，表示该点取在近剪切面上）</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><strong><span style="font-family: 宋体">得到</span>projPt<span style="font-family: 宋体">后，我们需要做的是把该点坐标从投影空间转换到观察空间</span>(view space),</strong></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">根据透视投影的定义，可假设点</span>(projPt.x<span style="font-family: 宋体">，</span>projPt.y<span style="font-family: 宋体">，</span>projPt.z)</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">对应的其次坐标为</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">(projPt.x*projPt.w<span style="font-family: 宋体">，</span>projPt.y*projPt.w<span style="font-family: 宋体">，</span>projPt.z*projPt.w<span style="font-family: 宋体">，</span>projPt.w)</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">我们可以通过</span>&nbsp;GetTransform(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D3DTS_PROJECTION,&nbsp;&nbsp;&nbsp;&nbsp;&amp;ProjMatrix)<span style="font-family: 宋体">函数获得投影矩阵</span>ProjMatrix,<span style="font-family: 宋体">则根据观察空间到投影空间的变换关系则</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">(projPt.x*projPt.w<span style="font-family: 宋体">，</span>projPt.y*projPt.w<span style="font-family: 宋体">，</span>projPt.z*projPt.w<span style="font-family: 宋体">，</span>projPt.w)</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">&nbsp;= (viewPt.x<span style="font-family: 宋体">，</span>viewPt.y<span style="font-family: 宋体">，</span>viewPt.z, 1)*pProjMatrx;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">根据定义和图形学原理</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">ProjMatrix =&nbsp;<img height="108" alt="" src="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.files/image008.jpg" width="135" border="0" v:shapes="_x0000_s1029" />=<img height="114" alt="" src="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.files/image010.jpg" width="138" border="0" v:shapes="_x0000_s1028" /></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">所以</span>,</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">(projPt.x*projPt.w<span style="font-family: 宋体">，</span>projPt.y*projPt.w<span style="font-family: 宋体">，</span>projPt.z*projPt.w<span style="font-family: 宋体">，</span>projPt.w)</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">= ( viewPt.x*ProjMatrix._m11,</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; text-indent: 15.75pt; font-family: 'Times New Roman'">viewPt.y*ProjMatrix._m22,</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; text-indent: 15.75pt; font-family: 'Times New Roman'">viewPt.z*Q-QZn,</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; text-indent: 15.75pt; font-family: 'Times New Roman'">viewPt.z)</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; text-indent: 15.75pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">所以</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">projPt.x*projPt.w = viewPt.x*ProjMatrix._m11</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">projPt.y*projPt.w = viewPt.y*ProjMatrix._m22</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 21pt; font-family: 'Times New Roman'">projPt.z*projPt.w = viewPt.z*Q-QZn&nbsp;<span style="color: red; font-family: 宋体">（注意</span><span style="color: red">projPt.z = 0</span><span style="color: red; font-family: 宋体">）</span></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'">projPt.w = viewPt.z;</p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">解得</span></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'">viewPt.x = projPt.x*Zn/ ProjMatrix._m11;</p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'">viewPt.y = projPt.y*Zn/ ProjMatrix._m22;</p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'">viewPt.z = Zn;</p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">好了，到这里为止我们终于求出了射线与近剪切面交点在观察坐标系中的坐标，现在我们拥有了射线的出发点</span>(0,0,0)<span style="font-family: 宋体">和射线方向上另外一点</span>(viewPt.x,viewPt.y,viewPt.z),<span style="font-family: 宋体">则该射线的方向矢量在观察空间中的表示可确定为（</span>viewPt.x-0,viewPt.y-0,viewPt.z-0<span style="font-family: 宋体">）</span>,<span style="font-family: 宋体">化简一下三个分量同除近剪切面</span>z<span style="font-family: 宋体">坐标</span>Zn<span style="font-family: 宋体">，该方向矢量可写作</span></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'">DIRview = (projPt.x/projMatrix._m11,projPt.y/projMatrix._m22,1)</p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">代入公式</span>1<span style="font-family: 宋体">，公式</span>2</p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">DIRview.x = (2*screenPt.x/screenWidth-1)/projMatrix._m11;</span></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">DIRview.y = (2*screenPt.y/screenHeight-1)/projMatrix._m22;</span></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">DIRview.z = 1;</span></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">其中screenWidth和screenHeight可以通过图像显示的backBuffer的目标表面（D3DSURFACE_DESC）来获得，该表面在程序初始化时由用户创建。</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="2.1.3 转换Dir到世界坐标空间，并得到观察点在世界坐标系中的坐标">2.1.3 转换Dir到世界坐标空间，并得到观察点在世界坐标系中的坐标</a></strong></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><strong><span style="font-size: 9pt; font-family: 新宋体">由于最终的运算要在世界坐标空间中进行，所以我们还需要把矢量DIRview从观察空间转换为世界坐标空间中的矢量DIRworld。</span></strong></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">因为</span></p>
<p style="font-size: 10.5pt; text-indent: 21pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">DIRview = DIRworld*ViewMatrix;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">其中ViewMatrix为观察矩阵，在D3D中可以用函数GetTransform( D3DTS_VIEW, &amp;ViewMatrix )得到。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">所以DIRworld = DIRview * inverse_ViewMatrix,其中inverse_ViewMatrix为</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">ViewMatrix的逆矩阵。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp; 观察点在观察坐标系中坐标为OriginView（0，0，0，1），所以其在世界坐标系中的坐标同样可以利用ViewMatrix矩阵，反变换至世界坐标系中，事实上我们可以很简单的判断出,其在世界坐标系中的表示为:</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">OriginWorld = (inverse_ViewMatrix._41,</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 63pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">inverse_ViewMatrix._42,</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 63pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">inverse_ViewMatrix._43,</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 63pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">1);</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">到这里为止，判断射线与三角面是否相交的条件就完全具备了。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="2.2 &nbsp; 使用射线矢量对场景中的所有三角形图元求交，获得三角形索引值和重心坐标。">2.2 &nbsp; 使用射线矢量对场景中的所有三角形图元求交，获得三角形索引值和重心坐标。</a></strong></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">这一步骤地实现由两种途径</span>:</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">第一种方法非常简单，利用</span>D3D<span style="font-family: 宋体">提供的扩展函数</span>D3DXIntersect<span style="font-family: 宋体">可以轻松搞定一切。见</span>2.1</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">第二种方法就是我们根据空间解析几何的知识，自己来完成射线三角形的求交算法。一般来讲，应用上用第一种方法就足够了，但是我们如果要深入的话，必须理解相交检测的数学算法，这样才能自由的扩展，面对不同的需求，内容见</span>2.2</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">下面分别讲解两种实现途径：</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="2.2.1 D3D扩展函数实现求交">2.2.1 D3D扩展函数实现求交</a></strong></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">这种方法很简单也很好用，对于应用来说应尽力是用这种方式来实现，毕竟效率比自己写得要高得多。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">实际上其实没什么好讲的，大概讲一下函数</span>D3DXIntersect<span style="font-family: 宋体">吧</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">D3D SDK<span style="font-family: 宋体">该函数声明如下</span></p><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">HRESULT&nbsp;D3DXIntersect(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;LPD3DXBASEMESH&nbsp;<em>pMesh</em>,</span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;CONST D3DXVECTOR3&nbsp;*<em>pRayPos</em>,</span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;CONST D3DXVECTOR3&nbsp;*<em>pRayDir</em>,</span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;BOOL&nbsp;*<em>pHit</em>,</span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;*<em>pFaceIndex</em>,</span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;FLOAT&nbsp;*<em>pU</em>,</span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;FLOAT&nbsp;*<em>pV</em>,</span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;FLOAT&nbsp;*<em>pDist</em>,</span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;LPD3DXBUFFER&nbsp;*<em>ppAllHits</em>,</span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;*<em>pCountOfHits</em></span></pre><pre style="font-size: 12pt; font-family: 宋体"><span style="font-size: 9pt">);</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; font-family: 宋体"><span style="font-size: 9pt; font-family: Wingdings">l<span style="font-weight: normal; font-size: 7pt; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt">pMesh指向一个ID3DXBaseMesh的对象，最简单的方式是从.x文件获得，描述了要进行相交检测的三角面元集合的信息，具体规范参阅direct9 SDK</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; font-family: 宋体"><span style="font-size: 9pt; font-family: Wingdings">l<span style="font-weight: normal; font-size: 7pt; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt">pRayPos 指向射线发出点</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; font-family: 宋体"><span style="font-size: 9pt; font-family: Wingdings">l<span style="font-weight: normal; font-size: 7pt; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt">pRayDir 指向前面我们辛辛苦苦求出的射线方向的向量</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; font-family: 宋体"><span style="font-size: 9pt; font-family: Wingdings">l<span style="font-weight: normal; font-size: 7pt; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt">pHit 当检测到相交图元时，指向一个true,不与任何图元相交则为假</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; font-family: 宋体"><span style="font-size: 9pt; color: red; font-family: Wingdings">l<span style="font-weight: normal; font-size: 7pt; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: red">pU 用于返回重心坐标U分量</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; font-family: 宋体"><span style="font-size: 9pt; color: red; font-family: Wingdings">l<span style="font-weight: normal; font-size: 7pt; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: red">pV返回重心坐标V分量</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; font-family: 宋体"><span style="font-size: 9pt; color: red; font-family: Wingdings">l<span style="font-weight: normal; font-size: 7pt; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: red">pDist 返回射线发出点到相交点的长度</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 21pt; font-family: 宋体"><span style="font-size: 9pt; color: red">注意：以上红色字体部分均指最近的一个返回结果（即*pDist最小）</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; font-family: 宋体"><span style="font-size: 9pt; font-family: Wingdings">l<span style="font-weight: normal; font-size: 7pt; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt">ppAllHits用于如果存在多个相交三角面返回相交的所有结果</span></pre><pre style="font-size: 12pt; margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; font-family: 宋体"><span style="font-size: 9pt; font-family: Wingdings">l<span style="font-weight: normal; font-size: 7pt; font-style: normal; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt">pCountOfHits 返回共有多少个三角形与该射线相交</span></pre>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><strong>&nbsp;</strong></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; color: green; font-family: 新宋体"><a name="补充：重心坐标的概念">补充：重心坐标的概念</a></span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; color: green; font-family: 新宋体">其中pU和pV用到了重心坐标的概念，下面稍作描述</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; color: green; font-family: 新宋体">一个三角形有三个顶点，在迪卡尔坐标系中假设表示为V1(x1,y1,z1),V2(x2,y2,z2),V3(x3,y3,z3),则三角形内任意一点的坐标可以表示为 pV = V1 + U(V2-V1) + V(V3-V1),所以已知三个顶点坐标的情况下，任意一点可用坐标(U,V)来表示，其中 参数U控制V2在结果中占多大的权值，参数V控制V3占多大权值，最终1－U－V控制V1占多大权值，这种坐标定义方式就叫重心坐标。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="2..2.2射线三角面相交的数学算法">2..2.2射线三角面相交的数学算法</a></strong></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体">使用</span>d3d<span style="font-family: 宋体">扩展函数，毕竟有时不能满足具体需求，掌握了该方法，我们才能够获得最大的控制自由度，任意修改算法。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; color: green; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><strong><span style="font-family: 宋体">已知条件</span></strong>:&nbsp;<span style="font-family: 宋体">射线源点</span>orginPoint,<span style="font-family: 宋体">三角形三个顶点</span>&nbsp;v1,v2,v3,<span style="font-family: 宋体">射线方向</span>&nbsp;Dir</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">（均以三维坐标向量形式表示）</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><strong><span style="font-family: 宋体">算法目的</span></strong>:&nbsp;<span style="font-family: 宋体">判断射线与三角形是否相交，如果相交求出交点的重心坐标</span>(U,V)<span style="font-family: 宋体">和射线原点到交点的距离</span>T<span style="font-family: 宋体">。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">我们可先假设射线与三角形相交则交点</span>(<span style="font-family: 宋体">注以下均为向量运算，</span>*<span style="font-family: 宋体">数乘，</span>dot(X,Y) X<span style="font-family: 宋体">，</span>Y&nbsp;<span style="font-family: 宋体">点乘，</span>cross<span style="font-family: 宋体">（</span>X<span style="font-family: 宋体">，</span>Y<span style="font-family: 宋体">）</span>X<span style="font-family: 宋体">，</span>Y<span style="font-family: 宋体">叉乘；</span>U<span style="font-family: 宋体">，</span>V<span style="font-family: 宋体">，</span>T<span style="font-family: 宋体">为标量</span>)</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">则：</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">IntersectPoint = V1 + U*(V2-V1) + V*(V3-V1) ;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">IntersectPoint = originPoint + T*Dir<span style="font-family: 宋体">；</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">所以</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">orginPoint + T*Dir = V1 + U*(V2-V1) + V*(V3-V1);</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">整理得：</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;<img height="161" alt="" src="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.files/image012.jpg" width="410" border="0" v:shapes="_x0000_s1027" /></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">这是一个简单的线性方程组，若有解则行列式</span><img height="21" alt="" src="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.files/image014.jpg" width="154" border="0" v:shapes="_x0000_s1026" /><span style="font-family: 宋体">不为</span>0<span style="font-family: 宋体">。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">根据</span>T,U,V<span style="font-family: 宋体">的含义当</span>T&gt;0, 0&lt;U&lt;1,0&lt;V&lt;1,0&lt;U+V&lt;1<span style="font-family: 宋体">时该交点在三角形内部，</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">解此方程组即可获得我们关心的值</span>,<span style="font-family: 宋体">具体解法不再赘述，克莱姆法则就够了（详细见线性代数）</span>:<span style="font-family: 宋体">射线原点到相交点的距离</span>T,<span style="font-family: 宋体">和交点的中心坐标</span>(U,V)<span style="font-family: 宋体">。</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">下面给出</span>Direct 9 SDK<span style="font-family: 宋体">示例程序中的实现代码</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">IntersectTriangle(&nbsp;<span style="color: blue">const</span>&nbsp;D3DXVECTOR3&amp; orig,</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">const</span>&nbsp;D3DXVECTOR3&amp; dir, D3DXVECTOR3&amp; v0,</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D3DXVECTOR3&amp; v1, D3DXVECTOR3&amp; v2,</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FLOAT* t, FLOAT* u, FLOAT* v )</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">{</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">// 算出两个边的向量</span></span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; D3DXVECTOR3 edge1 = v1 - v0;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; D3DXVECTOR3 edge2 = v2 - v0;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;<br /></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">//补充说明:<br />&nbsp;<img src="http://www.cppblog.com/images/cppblog_com/lll109383670/1213131.jpg" width="444" height="178" alt="" /><br />//分解为一向量点乘另它二向量的叉乘,本代码中Cross,再dot的结果就是得到上面所说行阵式的值。<br /><strong>//&lt;使用方向向量之前，最好标准化D3DXVec3Normalize,因为根据上面公式T*dir,dir必须为单位化向量</strong><br /><br />&nbsp;&nbsp;&nbsp; D3DXVECTOR3 pvec;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; D3DXVec3Cross( &amp;pvec, &amp;dir, &amp;edge2 );</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">// 如果det为0，或接近于零则射线与三角面共面或平行，不相交</span></span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; color: green; font-family: 新宋体">//此处det就相当于上面的</span><img height="21" alt="" src="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.files/image014.jpg" width="154" border="0" v:shapes="_x0000_s1025" /><span style="font-family: 宋体">，</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; FLOAT det = D3DXVec3Dot( &amp;edge1, &amp;pvec );</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; D3DXVECTOR3 tvec;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">if</span>( det &gt; 0 )</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; {</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tvec = orig - v0;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; }</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">else</span></span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; {</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tvec = v0 - orig;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; det = -det;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; }</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">if</span>( det &lt; 0.0001f )</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">return</span>&nbsp;FALSE;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">// 计算u并测试是否合法（在三角形内）</span></span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; *u = D3DXVec3Dot( &amp;tvec, &amp;pvec );</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">if</span>( *u &lt; 0.0f || *u &gt; det )</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">return</span>&nbsp;FALSE;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">// Prepare to test V parameter</span></span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; D3DXVECTOR3 qvec;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; D3DXVec3Cross( &amp;qvec, &amp;tvec, &amp;edge1 );</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">//计算u并测试是否合法（在三角形内）</span></span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; *v = D3DXVec3Dot( &amp;dir, &amp;qvec );</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">if</span>( *v &lt; 0.0f || *u + *v &gt; det )</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">return</span>&nbsp;FALSE;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 27pt; text-indent: -27pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green">/*计算t,并把t,u,v放缩为合法值（注意前面的t,v,u不同于算法描述中的相应量，乘了一个系数det）,</span><span style="color: red">注意：由于该步运算需要使用除法，所以放到最后来进行，避免不必要的运算，提高算法效率</span><span style="color: green">*/</span></span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; *t = D3DXVec3Dot( &amp;edge2, &amp;qvec );</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; FLOAT fInvDet = 1.0f / det;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; *t *= fInvDet;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; *u *= fInvDet;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; *v *= fInvDet;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="left"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">return</span>&nbsp;TRUE;</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-size: 9pt; font-family: 新宋体">}</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="2.2.3&nbsp; 拾取完成根据获得的中心坐标计算我们关心的常见量，。">2.2.3&nbsp; 拾取完成根据获得的中心坐标计算我们关心的常见量，。</a></strong></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">根据重心坐标（</span>U,V<span style="font-family: 宋体">）</span>,<span style="font-family: 宋体">我们可以很容易的算出各种相关量比如纹理坐标和交点的差值颜色，假设以纹理坐标为例设</span>V1,V2,V3<span style="font-family: 宋体">的纹理坐标分别为</span>T1(tu1,tv1),T2(tu2,tv2),T3(tu3,tv3)<span style="font-family: 宋体">则交点的坐标为</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'" align="center">IntersectPointTexture = T1 + U(T2-T1) + V(T3-T1)</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="3、结束及声明">3、结束及声明</a></strong></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">Ok,&nbsp;<span style="font-family: 宋体">到这里为止关于拾取的相关知识就介绍完了，小弟第一次写这种文章，不知道有没有把问题说清楚，希望对大家有所帮助，有任何问题可以给我发</span>email:&nbsp;<a style="color: blue; text-decoration: underline" href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#106;&#122;&#104;&#97;&#110;&#103;&#49;&#64;&#109;&#97;&#105;&#108;&#46;&#120;&#105;&#100;&#105;&#97;&#110;&#46;&#101;&#100;&#117;&#46;&#99;&#110;">jzhang1@mail.xidian.edu.cn</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">或者到我的网站留言：</span>&nbsp;<a style="color: blue; text-decoration: underline" href="http://www.heavysword.com/">www.heavysword.com</a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">声明：</span></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'"><span style="font-family: 宋体">本文写作的目的是为了广大</span>D3D<span style="font-family: 宋体">学习者方便学习服务，文中算法为作者参考相关文献总结，作者无意把这些据为自己的成果，所有权原算法提出者所有（参阅参考文献），文中代码为</span>D3d SDK<span style="font-family: 宋体">的示例内容，由笔者进行了必要的解释，代码版权归</span>microsoft<span style="font-family: 宋体">所有。</span></p>
<p style="font-size: 10.5pt; margin: 0cm 0cm 0pt 18pt; text-indent: -18pt; font-family: 'Times New Roman'"><strong><a name="4、参考文献">4、参考文献</a></strong></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">【1】Microsoft DirectX 9.0 SDK,microsoft</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">【2】fast,Minimun Storage Ray/Triangle Intersection,Tomas Moler,Ben Trumbore</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">　</p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">&nbsp;BY<a href="http://www.heavysword.com/"><img height="31" alt="" src="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.files/linklogo.gif" width="88" border="0" /></a></p>
<p style="font-size: 10.5pt; font-family: 'Times New Roman'">(转载请注明出处）</p>
<div id="maiku-toolbar" style="padding-right: 0px; display: block; padding-left: 25px; left: 1186px; background-image: url(chrome-extension://doobhdlahhejeholdpmecpdenofkhnnc/images/toolbar/logo.png); padding-bottom: 0px; width: 50px; padding-top: 0px; position: absolute; top: -24px; height: 22px; background-color: #ffffff; border-image: initial; "><a title="保存文章到麦库" style="display: inline-block;background-image: url(chrome-extension://doobhdlahhejeholdpmecpdenofkhnnc/images/toolbar/save.png); margin: 4px 5px; width: 14px; text-indent: -9999px; height: 14px" href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm##">保存文章到麦库</a><a title="关闭工具条" style="display: inline-block;background-image: url(chrome-extension://doobhdlahhejeholdpmecpdenofkhnnc/images/toolbar/close.png); margin: 4px 5px; width: 14px; text-indent: -9999px; height: 14px" href="http://dev.gameres.com/Program/Visual/3D/pick_2004_529.htm##">关闭工具条</a></div></span><a href="http://dev.gameres.com/"></a><img src ="http://www.cppblog.com/lll109383670/aggbug/166211.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-02-22 10:27 <a href="http://www.cppblog.com/lll109383670/archive/2012/02/22/166211.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>3D图形学编程指南笔记</title><link>http://www.cppblog.com/lll109383670/archive/2012/02/22/166190.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Wed, 22 Feb 2012 01:33:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/02/22/166190.html</guid><wfw:comment>http://www.cppblog.com/lll109383670/comments/166190.html</wfw:comment><comments>http://www.cppblog.com/lll109383670/archive/2012/02/22/166190.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lll109383670/comments/commentRss/166190.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lll109383670/services/trackbacks/166190.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">
<div style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; text-indent: 30px; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none"><strong id="internal-source-marker_0.8663704113569111" style="font-weight: normal">
<p dir="ltr"><span style="font-weight: bold; font-size: 48px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">3D图形学编程指南笔记</span></p><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">第二章</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">自由度：</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">前提：约束对象体，使所有的点之间的距离不变</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">平面物体有三个自由度，如位于x轴上的线段，则在沿x,y方向上有二个自由度，再沿原点旋转有一个自由度。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">3D物体有六个自由度，三轴，三旋转。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">自由度主要是有关平移和旋转。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none"></span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">有关世界到屏幕的过程。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">1.得到世界矩阵。 &nbsp;</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;首先物体有物体空间，我们要把物体变换到世界空间来，我们要预先知道物体在世界坐标系中的translate,rotate,所以DX里创建世界矩阵是可以根据平移、旋转来创建世界矩阵的。有了这几个参数，就可以把物体从物体坐标系变成世界坐标系中来。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;具体方法可以采用原点重合的方法，就是把物体坐标的原点通过一系列的平移旋转变化与世界坐标系重合，这过程中用到的联合矩阵，就是世界矩阵。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">2.得到视口矩阵，观察矩阵。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;把物体变换到世界坐标系后，还应该变换到视口坐标系，也就是观察坐标系，因为我们是通过视口坐标系来观察的，我们眼睛看向的正前方只会是视线所在的方向，也就是z轴所在。所以得把物体从世界坐标系变化到我们的视口坐标系来。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;同样是通过坐标系变换的方法，我们可以得到观察矩阵。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">3.得到屏幕坐标，投影矩阵。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;把物体变换到视口坐标系中后，我们要从屏幕上观察到，就必须把3D的视口坐标系，转换成我们可以通过屏幕看到的2D坐标，也就是屏幕坐标系，设备坐标系，在DX中设备坐标系是，正常的笛卡儿坐标第，原点在正中心，X正方向向右，Y正方向向上，单元为1。从视口坐标系到设备坐标系的过程，就可以得到投影坐标系。<br /></span>注意，如果屏幕是长方形的，有高宽比，那么对于投影矩阵来说，在垂直方向上的最终的y还要乘以宽高比.相当于缩短了垂直方向的视野，达到与屏幕的高宽比相同的视野，具体到投影矩阵，就是视距d还要乘以一个宽高比（垂直方向上）。<br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">要完成物体的拾取，其实就是一个屏幕到世界的反过程。</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">举例来说：</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">如果在屏幕上的拾取点是x,y（窗口客户区坐标，640*480）</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">那么屏幕到世界的流程是</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">1.窗口客户区坐标-》设备坐标系 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">先进行坐标系缩放（2*x/640）再进行平移-1</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">x(设) = (2*x/640) - 1</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">2.到视口坐标系</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">x(视) = x(设)/proj_matrix._11 &nbsp;&nbsp;&nbsp;&nbsp;(proj_maxtrix._11是投影矩阵的第一个元素)</span><br /><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">同理到y<br />3.到世界坐标系，乘以视图和世界矩阵的逆矩阵，得到最终拾取点在世界坐标系中的位置<br /></span><span style="font-weight: normal; font-size: 15px; vertical-align: baseline; color: #000000; font-style: normal; font-family: Arial; background-color: transparent; font-variant: normal; text-decoration: none">这样，就完成了屏幕到世界的坐标系变换，然后通过观察点与搭取点决定的射线，就可以找到交点了。<br /><br />主要流程<br /><span class="Apple-style-span" style="word-spacing: 0px; font: 14px/18px Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; text-transform: none; color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: #ffffff; text-align: left; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"> 
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial">0) Obtain your mouse coordinates within the client area</p>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial">1) Get your Projection matrix and View matrix if no Model matrix required.</p>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial">2) Multiply View * Projection</p>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial">3) Inverse the results of multiplication</p>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial">4) Construct a vector4 consisting of</p>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial"><strong style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: bold; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; background-origin: initial; background-clip: initial">x</strong><span class="Apple-converted-space">&nbsp;</span>=<span class="Apple-converted-space">&nbsp;</span><code style="border-top-width: 0px; padding-right: 5px; padding-left: 5px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 1px; margin: 0px; vertical-align: baseline; padding-top: 1px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: #eeeeee; border-right-width: 0px; background-origin: initial; background-clip: initial">mouseposition.x</code><span class="Apple-converted-space">&nbsp;</span>within a range of window x - transform to values between -1 and 1</p>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial"><strong style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: bold; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; background-origin: initial; background-clip: initial">y</strong><span class="Apple-converted-space">&nbsp;</span>=<span class="Apple-converted-space">&nbsp;</span><code style="border-top-width: 0px; padding-right: 5px; padding-left: 5px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 1px; margin: 0px; vertical-align: baseline; padding-top: 1px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: #eeeeee; border-right-width: 0px; background-origin: initial; background-clip: initial">mouseposition.y</code><span class="Apple-converted-space">&nbsp;</span>within a range of window y - transform to values between -1 and 1 - remember to invert mouseposition.y if needed</p>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial"><strong style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: bold; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; background-origin: initial; background-clip: initial">z</strong><span class="Apple-converted-space">&nbsp;</span>=<span class="Apple-converted-space">&nbsp;</span><code style="border-top-width: 0px; padding-right: 5px; padding-left: 5px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 1px; margin: 0px; vertical-align: baseline; padding-top: 1px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: #eeeeee; border-right-width: 0px; background-origin: initial; background-clip: initial">the depth value</code><span class="Apple-converted-space">&nbsp;</span>( this can be obtained with glReadPixel) - you can manually go from -1 to 1 ( zNear, zFar )</p>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial"><strong style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: bold; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; background-origin: initial; background-clip: initial">w</strong><span class="Apple-converted-space">&nbsp;</span>=<span class="Apple-converted-space">&nbsp;</span><code style="border-top-width: 0px; padding-right: 5px; padding-left: 5px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 1px; margin: 0px; vertical-align: baseline; padding-top: 1px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: #eeeeee; border-right-width: 0px; background-origin: initial; background-clip: initial">1.0</code></p>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial">5) Multiply the vector by inversed matrix created before 6) Divide result vector by it's w component after matrix multiplication ( perspective division )</p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #000000">&nbsp;&nbsp;POINT&nbsp;mousePos;<br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetCursorPos(</span><span style="color: #000000">&amp;</span><span style="color: #000000">mousePos);<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScreenToClient(&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetWindowHWND(),&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">mousePos&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CMatrix4x4&nbsp;matProjection&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;m_pCamera</span><span style="color: #000000">-&gt;</span><span style="color: #000000">getViewMatrix()&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;&nbsp;m_pCamera</span><span style="color: #000000">-&gt;</span><span style="color: #000000">getProjectionMatrix()&nbsp;;<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CMatrix4x4&nbsp;matInverse&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;matProjection.inverse();<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">float</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">4</span><span style="color: #000000">];<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">float</span><span style="color: #000000">&nbsp;winZ&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1.0</span><span style="color: #000000">;<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #000000">2.0f</span><span style="color: #000000">*</span><span style="color: #000000">((</span><span style="color: #0000ff">float</span><span style="color: #000000">)(mousePos.x</span><span style="color: #000000">-</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span style="color: #000000">/</span><span style="color: #000000">(</span><span style="color: #0000ff">this</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetResolution().x</span><span style="color: #000000">-</span><span style="color: #000000">0</span><span style="color: #000000">)))</span><span style="color: #000000">-</span><span style="color: #000000">1.0f</span><span style="color: #000000">,<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">1.0f</span><span style="color: #000000">-</span><span style="color: #000000">(</span><span style="color: #000000">2.0f</span><span style="color: #000000">*</span><span style="color: #000000">((</span><span style="color: #0000ff">float</span><span style="color: #000000">)(mousePos.y</span><span style="color: #000000">-</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span style="color: #000000">/</span><span style="color: #000000">(</span><span style="color: #0000ff">this</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetResolution().y</span><span style="color: #000000">-</span><span style="color: #000000">0</span><span style="color: #000000">)));<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">2</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">2.0</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;winZ&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1.0</span><span style="color: #000000">;<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">3</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">1.0</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CVector4&nbsp;vIn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;CVector4(</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">0</span><span style="color: #000000">],</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">1</span><span style="color: #000000">],</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">2</span><span style="color: #000000">],</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">3</span><span style="color: #000000">]);<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;vIn&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;matInverse;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.w&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1.0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;pos.w;<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.x&nbsp;</span><span style="color: #000000">*=</span><span style="color: #000000">&nbsp;pos.w;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.y&nbsp;</span><span style="color: #000000">*=</span><span style="color: #000000">&nbsp;pos.w;<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.z&nbsp;</span><span style="color: #000000">*=</span><span style="color: #000000">&nbsp;pos.w;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(strTitle,</span><span style="color: #000000">"</span><span style="color: #000000">%f&nbsp;%f&nbsp;%f&nbsp;/&nbsp;%f,%f,%f&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,m_pCamera</span><span style="color: #000000">-&gt;</span><span style="color: #000000">m_vPosition.x,m_pCamera</span><span style="color: #000000">-&gt;</span><span style="color: #000000">m_vPosition.y,m_pCamera</span><span style="color: #000000">-&gt;</span><span style="color: #000000">m_vPosition.z,pos.x,pos.y,pos.z);<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /></span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetWindowText(</span><span style="color: #0000ff">this</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetWindowHWND(),strTitle);</span></div>
<p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 14px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; word-wrap: break-word; background-origin: initial; background-clip: initial">参考文章：<a href="http://stackoverflow.com/questions/7692988/opengl-math-projecting-screen-space-to-world-space-coords-solved?answertab=active#tab-top">http://stackoverflow.com/questions/7692988/opengl-math-projecting-screen-space-to-world-space-coords-solved?answertab=active#tab-top</a><br /><br /></p></span><br /></span></strong></div></span><img src ="http://www.cppblog.com/lll109383670/aggbug/166190.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-02-22 09:33 <a href="http://www.cppblog.com/lll109383670/archive/2012/02/22/166190.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Material 和 Shader</title><link>http://www.cppblog.com/lll109383670/archive/2012/02/21/166183.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Tue, 21 Feb 2012 15:28:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/02/21/166183.html</guid><wfw:comment>http://www.cppblog.com/lll109383670/comments/166183.html</wfw:comment><comments>http://www.cppblog.com/lll109383670/archive/2012/02/21/166183.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lll109383670/comments/commentRss/166183.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lll109383670/services/trackbacks/166183.html</trackback:ping><description><![CDATA[<div>关于Material和Shader的概念纠结很久了，一直没找到合适的答案。看起来是一个东西，但总感觉应该不同，有所区别。<br />今天用FX Composer终于找到感觉了。<br />Shader可以说是代码段，是没有输入参数的，如纹理<br />Material是实例化的Shader就是说Material是包括了输入的纹理的，所以不同的纹理就有不同的Material，但用的Shader是相同的。<br />理解了这个概念就在设计类的时候就可以把Shader和Material分开来设计，Shader负责脚本的加载，而Material负责脚本参数的传入，这样就可以复用了。<br />可以参考：<a href="http://www.leadwerks.com/files/Tutorials/CPP/Materials_And_Shaders.pdf">http://www.leadwerks.com/files/Tutorials/CPP/Materials_And_Shaders.pdf</a></div><img src ="http://www.cppblog.com/lll109383670/aggbug/166183.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-02-21 23:28 <a href="http://www.cppblog.com/lll109383670/archive/2012/02/21/166183.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>静态成员（转）</title><link>http://www.cppblog.com/lll109383670/archive/2012/02/20/166084.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Mon, 20 Feb 2012 11:15:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/02/20/166084.html</guid><description><![CDATA[<p>//&lt;&nbsp; 处理静态成员函数要引用普通类成员的办法，可以获取该类的实例，再引用类的普通成员，因为静态成员函数没有传入this指针<br /><br />文章来源:<a href="http://tech.e800.com.cn/articles/2009/1231/1262237064944_1.html">http://tech.e800.com.cn/articles/2009/1231/1262237064944_1.html</a><br /><br />类体中的数据成员的声明前加上static关键字，该数据成员就成为了该类的静态数据成员。和其他数据成员一样，静态数据成员也遵守public/protected/private访问规则。同时，静态数据成员还具有以下特点：</p>
<p>&nbsp;<br />1.静态数据成员的定义</p>
<p>静态数据成员实际上是类域中的全局变量。所以，静态数据成员的定义(初始化)不应该被放在头文件中。</p>
<p>其定义方式与全局变量相同。举例如下：</p>
<p>&nbsp;</p>
<p>xxx.h文件</p>
<p>class base{</p>
<p>private:</p>
<p>static const int _i;//声明，标准c++支持有序类型在类体中初始化,但vc6不支持。</p>
<p>};</p>
<p>&nbsp;</p>
<p>xxx.cpp文件</p>
<p>const int base::_i=10;//定义(初始化)时不受private和protected访问限制.</p>
<p>&nbsp;</p>
<p>注：不要试图在头文件中定义(初始化)静态数据成员。在大多数的情况下，这样做会引起重复定义这样的错误。即使加上#ifndef #define #endif或者#pragma once也不行。</p>
<p>&nbsp;<br />2.静态数据成员被 类 的所有对象所共享（包括该类派生类的对象）</p>
<p>即派生类对象与基类对象共享基类的静态数据成员。举例如下：</p>
<p>class base{</p>
<p>public :</p>
<p>static int _num;//声明</p>
<p>};</p>
<p>int base::_num=0;//静态数据成员的真正定义</p>
<p>&nbsp;</p>
<p>class derived:public base{</p>
<p>};</p>
<p>&nbsp;</p>
<p>main()</p>
<p>{</p>
<p>base a;</p>
<p>derived b;</p>
<p>a._num++;</p>
<p>cout&lt;&lt;"base class static data number _num is"&lt;&lt;a._num&lt;&lt;endl;</p>
<p>b._num++;</p>
<p>cout&lt;&lt;"derived class static data number _num is"&lt;&lt;b._num&lt;&lt;endl;</p>
<p>}</p>
<p>// 结果为1,2;可见派生类与基类共用一个静态数据成员。</p>
<p>&nbsp;<br />3.静态数据成员可以成为成员函数的可选参数（普通数据成员则不可以）</p>
<p>举例如下：</p>
<p>class base{</p>
<p>public :</p>
<p>static int _staticVar;</p>
<p>int _var;</p>
<p>void foo1(int i=_staticVar);//正确,_staticVar为静态数据成员</p>
<p>void foo2(int i=_var);//错误,_var为普通数据成员</p>
<p>};</p>
<p>&nbsp;<br />4.&#9733;静态数据成员的类型可以是所属类的类型（普通数据成员则不可以）</p>
<p>普通数据成员的只能声明为 所属类类型的指针或引用。举例如下：</p>
<p>&nbsp;</p>
<p>class base{</p>
<p>public :</p>
<p>static base _object1;//正确，静态数据成员</p>
<p>base _object2;//错误</p>
<p>base *pObject;//正确，指针</p>
<p>base &amp;mObject;//正确，引用</p>
<p>};</p>
<p>&nbsp;<br />5.&#9733; 静态数据成员的值在const成员函数中可以被合法的改变</p>
<p>举例如下：</p>
<p>&nbsp;</p>
<p>这个特性，我不知道是属于标准c++中的特性，还是vc6自己的特性。</p>
<p>class base{</p>
<p>public:</p>
<p>base(){_i=0;_val=0;}</p>
<p>&nbsp;</p>
<p>mutable int _i;</p>
<p>static int _staticVal;</p>
<p>int _val;</p>
<p>void test() const{//const 成员函数</p>
<p>&nbsp;</p>
<p>_i++;//正确，mutable数据成员</p>
<p>_staticVal++;//正确，static数据成员</p>
<p>_val++;//错误</p>
<p>&nbsp;</p>
<p>}</p>
<p>};</p>
<p>int base::_staticVal=0;</p>
<p>&nbsp;<br />二 静态成员函数</p>
<p>静态成员函数没有什么太多好讲的。</p>
<p>&nbsp;<br />1.静态成员函数的地址可用普通函数指针储存（普通成员函数地址需要用 类成员函数指针来储存）</p>
<p>举例如下：</p>
<p>class base{</p>
<p>static int func1();</p>
<p>int func2();</p>
<p>};</p>
<p>&nbsp;</p>
<p>int (*pf1)()=&amp;base::func1;//普通的函数指针</p>
<p>int (base::*pf2)()=&amp;base::func2;//成员函数指针</p>
<p>&nbsp;</p>
<p>&nbsp;<br />2.静态成员函数不可以调用类的非静态成员</p>
<p>因为静态成员函数不含this指针。</p>
<p>&nbsp;<br />3.静态成员函数不可以同时声明为 virtual、const、volatile函数</p>
<p>举例如下：</p>
<p>class base{</p>
<p>virtual static void func1();//错误</p>
<p>static void func2() const;//错误</p>
<p>static void func3() volatile;//错误</p>
<p>};</p>
<p>&nbsp;</p><img src ="http://www.cppblog.com/lll109383670/aggbug/166084.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-02-20 19:15 <a href="http://www.cppblog.com/lll109383670/archive/2012/02/20/166084.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UNICODE 处理（转）</title><link>http://www.cppblog.com/lll109383670/archive/2012/02/20/166078.html</link><dc:creator>帅哥帅</dc:creator><author>帅哥帅</author><pubDate>Mon, 20 Feb 2012 09:52:00 GMT</pubDate><guid>http://www.cppblog.com/lll109383670/archive/2012/02/20/166078.html</guid><description><![CDATA[<br />原文：<a href="http://www.vckbase.com/bbs/prime/viewprime.asp?id=125">http://www.vckbase.com/bbs/prime/viewprime.asp?id=125</a><br />这是一个许多人（包括我自己）曾经或至今仍疑惑的问题（这里我们只讨论UTF-16，即双字节版本）。<br /><br />1.关于UNICODE<br />首先，UNICODE主要使用的字符类型是WCHAR，定义是unsigned short。从定义我们可以看出这是一个双字节的类型，就是每一个字符占2个字节。这样的话，可以表示的字符类型就可以多达6万多。所有之前的ASCII码分布在0x0000-0x00ff之间，而汉字（包括big5）分布在0x4e00到0x9fff之间。整个unicode包含了几乎世界上所有的文字。关于UNICODE的细节，可以参看以下网页<br />http://www.unicode.org/unicode/standard/translations/s-chinese.html<br /><br />2.为什么要使用UNICODE<br />1）COM：在COM规范中，明确指定了必须使用UNICODE类型，这正是微软充分考虑了跨平台的结果。这也是为什么经常在COM中可以看到BSTR（WCHAR*）类型<br />2）WIN2000和WINNT：在这两个平台中，默认的字符处理方式是UNICODE。即使你写了一个非UNICODE（multibyte)的程序，系统在执行的时候仍然会对你的字符进行一次转换，这样无疑浪费了CPU时间，使用UNICODE可以有效的提高程序的运行效率（仅使用于这两个平台）。当然将来的XP也会如此。<br />3）通用性：使用UNICODE可以使我们不在为汉字和英文字符的判断而烦恼（都是2个字节）。<br /><br />3.如何使用UNICODE <br />1）首先推荐的类型是TCHAR（通用字符类型）。当你定义了_UNICODE宏的时候，TCHAR就是WCHAR，当你没有定义这个宏的时候，TCHAR就是char，很不可思议吧，我们可以来看一下TCHAR的定义：<br /><br />#ifdef&nbsp;&nbsp;UNICODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // r_winnt<br />typedef WCHAR TCHAR, *PTCHAR;<br />#else&nbsp;&nbsp; /* UNICODE */&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // r_winnt<br />typedef char TCHAR, *PTCHAR;<br />#endif /* !_TCHAR_DEFINED */<br /><br />上面的代码来自WINNT.H我剔除了一些无关的部分。现在一切都显而易见了。<br />通过TCHAR，我们只需要这样一段代码：<br />TCHAR tStr[] = _T("t code");<br />MessageBox(tStr);<br />就可以支持UNICODE和MULTIBYTE两种版本。_T宏的作用就是转换成TCHAR。<br /><br />2）关于其他的处理<br />首先是常用的CString,它本身就支持UNICODE。下面的例子说明了用法：<br /><br />CString *pFileName = new CString("c:\\tmpfile.txt");<br /><br />#ifdef _UNICODE<br /><br />&nbsp;&nbsp; m_hFile = CreateFile(pFileName-&gt;AllocSysString(), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GENERIC_READ | GENERIC_WRITE, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FILE_SHARE_READ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OPEN_EXISTING,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FILE_ATTRIBUTE_NORMAL, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL);<br />#else<br />&nbsp;&nbsp; m_hFile = CreateFile(pFileName-&gt;GetBuffer(pFileName-&gt;GetLength()), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GENERIC_READ | GENERIC_WRITE, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FILE_SHARE_READ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OPEN_EXISTING,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FILE_ATTRIBUTE_NORMAL, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL);<br />#endif<br /><br />另外，VC还提供了一些函数如WideCharToMultiByte和MultiByteToWideChar还有另外的一些宏来支持转换。大家可以看MSDN。 <br /><br /><img src ="http://www.cppblog.com/lll109383670/aggbug/166078.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lll109383670/" target="_blank">帅哥帅</a> 2012-02-20 17:52 <a href="http://www.cppblog.com/lll109383670/archive/2012/02/20/166078.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>