﻿<?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++博客-jack-wang-随笔分类-游戏引擎</title><link>http://www.cppblog.com/jack-wang/category/10929.html</link><description>小王</description><language>zh-cn</language><lastBuildDate>Sat, 23 Mar 2013 06:28:57 GMT</lastBuildDate><pubDate>Sat, 23 Mar 2013 06:28:57 GMT</pubDate><ttl>60</ttl><item><title>向量的点积和叉积定义</title><link>http://www.cppblog.com/jack-wang/archive/2010/08/11/123123.html</link><dc:creator>小王</dc:creator><author>小王</author><pubDate>Wed, 11 Aug 2010 15:26:00 GMT</pubDate><guid>http://www.cppblog.com/jack-wang/archive/2010/08/11/123123.html</guid><wfw:comment>http://www.cppblog.com/jack-wang/comments/123123.html</wfw:comment><comments>http://www.cppblog.com/jack-wang/archive/2010/08/11/123123.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jack-wang/comments/commentRss/123123.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jack-wang/services/trackbacks/123123.html</trackback:ping><description><![CDATA[<h2>&nbsp;</h2>
<p>转：<a href="http://www.cppblog.com/lovedday/archive/2008/07/01/22890.html">http://www.cppblog.com/lovedday/archive/2008/07/01/22890.html</a></p>
<div style="FONT-SIZE: 12pt" class=postText>
<p style="FONT-SIZE: 12pt">向量的点积：<br><br>假设向量<strong>u</strong>(<strong>u</strong><sub>x</sub>, <strong>u</strong><sub>y</sub>)和<strong>v</strong>(<strong>v</strong><sub>x</sub>, <strong>v</strong><sub>y</sub>)，<strong>u</strong>和<strong>v</strong>之间的夹角为&#945;，从三角形的边角关系等式出发，可作出如下简单推导：<br><br>&nbsp; |<strong>u</strong> - <strong>v</strong>||<strong>u</strong> - <strong>v</strong>| = |<strong>u</strong>||<strong>u</strong>| + |<strong>v</strong>||<strong>v</strong>| - 2|<strong>u</strong>||<strong>v</strong>|cos&#945;&nbsp;&nbsp; <br><br>===&gt;<br>&nbsp; <br>&nbsp; （<strong>u</strong><sub>x</sub> - <strong>v</strong><sub>x</sub>）<sup>2</sup> + (<strong>u</strong><sub>y</sub> - <strong>v</strong><sub>y</sub>)<sup>2&nbsp; </sup>= <strong>u</strong><sub>x</sub><sup>2 </sup>+ <strong>u</strong><sub>y</sub><sup>2</sup> +<strong>v</strong><sub>x</sub><sup>2</sup>+<strong>v</strong><sub>y</sub><sup>2</sup>- 2|<strong>u</strong>||<strong>v</strong>|cos&#945; <br><br>===&gt;<br>&nbsp;&nbsp; <br>&nbsp;&nbsp; -2<strong>u</strong><sub>x</sub><strong>v</strong><sub>x</sub> - 2<strong>u</strong><sub>y</sub><strong>v</strong><sub>y</sub> = -2|<strong>u</strong>||<strong>v</strong>|cos&#945;<br><br>===&gt;<br><br>&nbsp;&nbsp; cos&#945; = (<strong>u</strong><sub>x</sub><strong>v</strong><sub>x</sub> + <strong>u</strong><sub>y</sub><strong>v</strong><sub>y</sub>) / (|<strong>u</strong>||<strong>v</strong>|)<br><br>这样，就可以根据向量<strong>u</strong>和<strong>v</strong>的坐标值计算出它们之间的夹角。<br><br>定义<strong>u</strong>和<strong>v</strong>的点积运算：&nbsp;<strong>u</strong> . <strong>v</strong> = (<strong>u</strong><sub>x</sub><strong>v</strong><sub>x</sub> + <strong>u</strong><sub>y</sub><strong>v</strong><sub>y</sub>)，</p>
<p style="FONT-SIZE: 12pt">上面的cos&#945;可简写成：&nbsp;cos&#945; = <strong>u</strong> . <strong>v</strong> / (|<strong>u</strong>||<strong>v</strong>|)<br><br>当<strong>u</strong> . <strong>v</strong> = 0时（即<strong>u</strong><sub>x</sub><strong>v</strong><sub>x</sub> + <strong>u</strong><sub>y</sub><strong>v</strong><sub>y</sub> = 0），向量<strong>u</strong>和<strong>v</strong>垂直；当<strong>u</strong> . <strong>v</strong> &gt; 0时，<strong>u</strong>和<strong>v</strong>之间的夹角为锐角；当<strong>u</strong> . <strong>v</strong> &lt; 0时，<strong>u</strong>和<strong>v</strong>之间的夹角为钝角。<br><br>可以将运算从2维推广到3维。</p>
<p style="FONT-SIZE: 12pt"><br><br>向量的叉积：<br><br>假设存在向量u(<strong>u</strong><sub>x</sub>, <strong>u</strong><sub>y</sub>, <strong>u</strong><sub>z</sub>), v(<strong>v</strong><sub>x</sub>, <strong>v</strong><sub>y</sub>, <strong>v</strong><sub>z</sub>), 求同时垂直于向量<strong>u</strong>, <strong>v</strong>的向量<strong>w</strong>(<strong>w</strong><sub>x</sub>, <strong>w</strong><sub>y</sub>, <strong>w</strong><sub>z</sub>).<br><br>因为<strong>w</strong>与<strong>u</strong>垂直，同时<strong>w</strong>与<strong>v</strong>垂直，所以<strong>w</strong> . <strong>u</strong> = 0, <strong>w</strong> . <strong>v</strong> = 0; 即<br><br><strong>u</strong><sub>x</sub><strong>w</strong><sub>x</sub> + <strong>u</strong><sub>y</sub><strong>w</strong><sub>y</sub> + <strong>u</strong><sub>z</sub><strong>w</strong><sub>z</sub> = 0;<br><strong>v</strong><sub>x</sub><strong>w</strong><sub>x</sub> + <strong>v</strong><sub>y</sub><strong>w</strong><sub>y</sub> + <strong>v</strong><sub>z</sub><strong>w</strong><sub>z</sub> = 0;<br><br>分别削去方程组的<strong>w</strong><sub>y</sub>和<strong>w</strong><sub>x</sub>变量的系数，得到如下两个等价方程式：<br><br>(<strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>)<strong>w</strong><sub>x</sub> = (<strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub>)<strong>w</strong><sub>z</sub><br>(<strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>)<strong>w</strong><sub>y</sub> = (<strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub>)<strong>w</strong><sub>z</sub><br><br>于是向量w的一般解形式为：<br><br><strong>w</strong> = (<strong>w</strong><sub>x</sub>, <strong>w</strong><sub>y</sub>, <strong>w</strong><sub>z</sub>) = ((<strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub>)<strong>w</strong><sub>z</sub> / (<strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>), (<strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub>)<strong>w</strong><sub>z</sub> / (<strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>), <strong>w</strong><sub>z</sub>)<br>&nbsp; = (<strong>w</strong><sub>z</sub> / (<strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>) * (<strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub>, <strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub>, <strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>))<br><br>因为：<br><br>&nbsp;&nbsp; <strong>u</strong><sub>x</sub>(<strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub>) + <strong>u</strong><sub>y</sub>(<strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub>) + <strong>u</strong><sub>z</sub>(<strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>)<br>&nbsp;= <strong>u</strong><sub>x</sub><strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>u</strong><sub>x</sub><strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub> + <strong>u</strong><sub>y</sub><strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>u</strong><sub>y</sub><strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub> + <strong>u</strong><sub>z</sub><strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>z</sub><strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub><br>&nbsp;= (<strong>u</strong><sub>x</sub><strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>u</strong><sub>y</sub><strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub>) + (<strong>u</strong><sub>y</sub><strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>u</strong><sub>z</sub><strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>) + (<strong>u</strong><sub>z</sub><strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>x</sub><strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub>)&nbsp;&nbsp; <br>&nbsp;= 0 + 0 + 0 = 0<br><br>&nbsp;&nbsp; <strong>v</strong><sub>x</sub>(<strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub>) + <strong>v</strong><sub>y</sub>(<strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub>) + <strong>v</strong><sub>z</sub>(<strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>)&nbsp;&nbsp; <br>&nbsp;= <strong>v</strong><sub>x</sub><strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>v</strong><sub>x</sub><strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub> + <strong>v</strong><sub>y</sub><strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>v</strong><sub>y</sub><strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub> + <strong>v</strong><sub>z</sub><strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>v</strong><sub>z</sub><strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub><br>&nbsp;= (<strong>v</strong><sub>x</sub><strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>v</strong><sub>z</sub><strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>) + (<strong>v</strong><sub>y</sub><strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>v</strong><sub>x</sub><strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub>) + (<strong>v</strong><sub>z</sub><strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>v</strong><sub>y</sub><strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub>)<br>&nbsp;= 0 + 0 + 0 = 0<br><br>由此可知，向量(<strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub>, <strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub>, <strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>)是同时垂直于向量<strong>u</strong>和<strong>v</strong>的。<br><br>为此，定义向量<strong>u</strong> = (<strong>u</strong><sub>x</sub>, <strong>u</strong><sub>y</sub>, <strong>u</strong><sub>z</sub>)和向量 <strong>v</strong> = (<strong>v</strong><sub>x</sub>, <strong>v</strong><sub>y</sub>, <strong>v</strong><sub>z</sub>)的叉积运算为：<strong>u</strong> x <strong>v</strong> = (<strong>u</strong><sub>y</sub><strong>v</strong><sub>z</sub> - <strong>u</strong><sub>z</sub><strong>v</strong><sub>y</sub>, <strong>u</strong><sub>z</sub><strong>v</strong><sub>x</sub> - <strong>u</strong><sub>x</sub><strong>v</strong><sub>z</sub>, <strong>u</strong><sub>x</sub><strong>v</strong><sub>y</sub> - <strong>u</strong><sub>y</sub><strong>v</strong><sub>x</sub>)<br><br>上面计算的结果可简单概括为：向量<strong>u </strong>x<strong> v</strong>垂直于向量<strong>u</strong>和<strong>v</strong>。</p>
<p style="FONT-SIZE: 12pt"><br>根据叉积的定义，沿x坐标轴的向量<strong>i</strong> = (1, 0, 0)和沿y坐标轴的向量<strong>j</strong> = (0, 1, 0)的叉积为：<br><br>&nbsp;<strong>i</strong> x <strong>j</strong> = (1, 0, 0) x (0, 1, 0) = (0 * 0 - 0 * 1, 0 * 0 - 1 * 0, 1 * 1 - 0 * 0) = (0, 0, 1) = <strong>k</strong><br><br>同理可计算<strong>j</strong> x <strong>k</strong>:<br>&nbsp;<br>&nbsp;<strong>j</strong> x <strong>k</strong> = (0, 1, 0) x (0, 0, 1) = (1 * 1 - 0 * 0, 0 * 0 - 0 * 1, 0 * 0 - 0 * 0) = (1, 0, 0) = <strong>i</strong><br><br>以及<strong>k</strong> x <strong>i</strong>:<br><br>&nbsp;k x <strong>i</strong> = (0, 0, 1) x (1, 0, 0) = (0 * 0 - 1 * 0, 1 * 1 - 0 * 0, 0 * 0 - 0 * 0) = (0, 1, 0) = <strong>j</strong><br><br>由叉积的定义，可知：<br><br>&nbsp;<strong>v</strong> x <strong>u</strong> = (<strong>v</strong><sub>y</sub><strong>u</strong><sub>z</sub> - <strong>v</strong><sub>z</sub><strong>u</strong><sub>y</sub>, <strong>v</strong><sub>z</sub><strong>u</strong><sub>x</sub> - <strong>v</strong><sub>x</sub><strong>u</strong><sub>z</sub>, <strong>v</strong><sub>x</sub><strong>u</strong><sub>y</sub> - <strong>v</strong><sub>y</sub><strong>u</strong><sub>x</sub>) = - (<strong>u</strong> x <strong>v</strong>)<br></p>
</div>
<img src ="http://www.cppblog.com/jack-wang/aggbug/123123.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jack-wang/" target="_blank">小王</a> 2010-08-11 23:26 <a href="http://www.cppblog.com/jack-wang/archive/2010/08/11/123123.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转：【OGRE人门教程】OGRE源码成功编译记081227</title><link>http://www.cppblog.com/jack-wang/archive/2009/11/27/102026.html</link><dc:creator>小王</dc:creator><author>小王</author><pubDate>Thu, 26 Nov 2009 19:15:00 GMT</pubDate><guid>http://www.cppblog.com/jack-wang/archive/2009/11/27/102026.html</guid><wfw:comment>http://www.cppblog.com/jack-wang/comments/102026.html</wfw:comment><comments>http://www.cppblog.com/jack-wang/archive/2009/11/27/102026.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jack-wang/comments/commentRss/102026.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jack-wang/services/trackbacks/102026.html</trackback:ping><description><![CDATA[<div>
<div>
<h2><a id=viewpost1_TitleUrl href="http://www.cppblog.com/welflau/archive/2008/12/28/70570.html">【原创】【OGRE人门教程】OGRE源码成功编译记081227</a> </h2>
Posted on 2008-12-28 17:54 <a href="http://www.cppblog.com/welflau/">刘文峰</a> 阅读(1814) <a href="http://www.cppblog.com/welflau/archive/2009/02/24/70570.html#Post">评论(7)</a> &nbsp;<a href="http://www.cppblog.com/welflau/admin/EditPosts.aspx?postid=70570">编辑</a>&nbsp;<a href="http://www.cppblog.com/welflau/AddToFavorite.aspx?id=70570">收藏</a> <a href="http://www.cppblog.com/welflau/services/trackbacks/70570.aspx">引用</a> <img src="http://www.cppblog.com/welflau/aggbug/70570.html?webview=1" width=1 height=1> <br><br>原帖：<a href="http://www.cppblog.com/welflau/archive/2009/02/24/70570.html">http://www.cppblog.com/welflau/archive/2009/02/24/70570.html</a><!--
--></div>
<div>&nbsp;
<p><span>OGRE</span><span>源码成功编译记</span><span>081227</span></p>
<p><strong><span>Made by welflau</span></strong></p>
<p><strong><span>1 </span></strong><strong><span>下载最新的</span><span>OGRE</span></strong><strong><span>源码包</span><st1:chsdate Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False" w:st="on"><span>1.6.0</span></st1:chsdate></strong></p>
<p>&nbsp;<img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122701.JPG" width=612 height=519></p>
<p>&nbsp;<strong><span>2 </span></strong><strong><span>直接解压到</span><span>D</span></strong><strong><span>盘根目录下<br><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122702.JPG" width=514 height=713><br><br>&nbsp; </p>
<p><strong><span>3 </span></strong><strong><span>打开</span><span>sln </span></strong><strong><span>我装是的</span><span>VS2005</span></strong></p>
</span></strong>
<p><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122703.JPG" width=187 height=56>&nbsp;<br><br></p>
<p><span>打开后</span></p>
<p><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122704.JPG" width=1024 height=708></p>
<p><strong><span>4 </span><span>编译生成</span><span>OgreMain</span></strong><br><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122705.JPG" width=379 height=177><br><br>&nbsp;&nbsp;&nbsp; </p>
<p><strong><span>5 </span></strong><strong><span>会出错，还没下</span><span>Dependencies</span></strong></p>
<p><span>因为链接器中显示了有<strong>附加库</strong></span></p>
<p><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122706.JPG" width=674 height=461><br><span><br><strong>&nbsp; </strong></p>
<p><strong><span>6 下载</span><span>ogre-dependencies 注意要下载最新版</span></strong></p>
<p><span><strong>下载地址：</strong></span></p>
<p><span><strong>http://sourceforge.net/project/showfiles.php?group_id=2997</strong></span></p>
<br><strong><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122707.JPG" width=1024 height=708><br><br></strong>
<p><span>下一个页面选择</span></p>
<img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122708.JPG" width=630 height=323><br>&nbsp;
<p><strong><span>7 </span></strong><strong><span>解压到</span><span>D:\ogre-l.6.0\ogre</span></strong></p>
<br><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122709.JPG" width=531 height=629><br><br>&nbsp;
<p><span>解压完后，再重新编译生成</span></p>
<p><span>OgreMain</span><span>编译得要一段时间</span></p>
<p><span>而且编译后</span><span>Obj</span><span>文件有</span><st1:chmetcnv w:st="on" TCSC="0" NumberType="1" Negative="False" HasSpace="False" SourceValue="1.6" UnitName="g"><span>1.6G</span></st1:chmetcnv><span>左右的大小，所以编译之前要保证你的硬盘有足够的空间</span></p>
<p><span>【注意】还有一个</span><span>Samples</span><span>文件夹也要覆盖到</span><span>Ogre</span><span>目录下</span></p>
<img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122710.jpg" width=443 height=99><br><br>&nbsp;
<p><span>里面是执行时所需的</span><span>dll</span><span>文件</span></p>
<p><span>终于编译完后，不过还是有错，少文件</span></p>
<p><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122711.JPG" width=983 height=119></p>
<p>&nbsp; </p>
<p><span>我去</span><span>&nbsp;Dependencies\include\zzip </span><span>目录下看的确没这个文件</span></p>
<p><span>我又下了</span><span>Dependencies</span><span>其他版本</span><span>OgreDependencies_VC8SP1_Eihort_20070323</span></p>
<p><span>发现有该文件</span></p>
<img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122712.JPG" width=682 height=116><br>
<p align=left><strong><span><br>8 </span></strong><strong><span>可能是版本不对再到</span><span>OGRE</span></strong><strong><span>官方网站<br></span></strong><span>http://www.ogre3d.org/index.php?option=com_content&amp;task=view&amp;id=412&amp;Itemid=132<br><br><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122713.JPG" width=1024 height=708></span></p>
<br>&nbsp;
<p><span>下载红框所示那个包：</span><strong><span>OgreDependencies_VC8SP1_Eihort_20071227.zip</span></strong></p>
<p><span>解压到</span><span>OGRE</span><span>目录</span><strong><span>D:\ogre-l.6.0\ogre</span></strong><span>下到重新覆盖一遍</span></p>
<p><span>再编译生成</span></p>
<p><span>终于成功生成</span></p>
<img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122714.JPG" width=1024 height=708><br><br>
<p><span>生成的</span><span>lib</span><span>和</span><span>dll</span><span>如下图</span></p>
<img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122715.JPG" width=924 height=163><br><br>&nbsp; <br>
<p><span>其中</span><span>OgreMain</span><span>生成的目标文件有</span><st1:chmetcnv w:st="on" TCSC="0" NumberType="1" Negative="False" HasSpace="False" SourceValue="1.53" UnitName="g"><span>1.53G<br><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/welflau/08122716.JPG" width=475 height=470></span></st1:chmetcnv></p>
<br><u><font color=#810081>&nbsp;</font></u>
<p><a href="http://hi.baidu.com/welflau/blog/item/e15f8d01fb7defd1267fb525.html" target=_blank>【游戏开发】【原创教程连载】WelfGame【第7讲】(08120803按钮颜色可控)</a></p>
<p><a href="http://hi.baidu.com/welflau/blog/item/d38833db97093a61d1164e5a.html" target=_blank>【游戏开发】【原创教程连载】WelfGame【第6讲】(08120702加入皮肤对话框)</a></p>
<p><a href="http://hi.baidu.com/welflau/blog/item/1d092aa4c7d361f09152ee5f.html" target=_blank><font color=#0000ff>【游戏开发】【原创教程连载】WelfGame【第5讲】(WelfGame(08120302三维操作)</font></a></p>
<p><a href="http://hi.baidu.com/welflau/blog/item/1553b312c711abc9c2fd7853.html" target=_blank><font color=#0000ff>【游戏开发】【原创教程连载】WelfGame【第4讲】(08120301导入三维数据文件 .x）</font></a></p>
<p><a href="http://hi.baidu.com/welflau/blog/item/309af8d3d5d142d8a8ec9a2c.html" target=_blank>【游戏开发】WelfGame【第3讲】(08120203图像透明及颜色)</a></p>
<p><a href="http://hi.baidu.com/welflau/blog/item/9c589716170efc56f2de325b.html" target=_blank><font color=#0000ff>【游戏开发】WelfGame【第2讲】(08120202绘制文字和图像）</font></a></p>
<p><a href="http://hi.baidu.com/welflau/blog/item/1b17032320bb05499358075e.html" target=_blank><font color=#0000ff>【游戏开发】原创：我的游戏开发学习过程（连载中...）(第一讲)</font></a></p>
</span></div>
</div>
<img src ="http://www.cppblog.com/jack-wang/aggbug/102026.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jack-wang/" target="_blank">小王</a> 2009-11-27 03:15 <a href="http://www.cppblog.com/jack-wang/archive/2009/11/27/102026.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在OGRE中使用CEGUI的笔记 （转自清源游民的网络笔记本）</title><link>http://www.cppblog.com/jack-wang/archive/2009/11/27/102025.html</link><dc:creator>小王</dc:creator><author>小王</author><pubDate>Thu, 26 Nov 2009 19:09:00 GMT</pubDate><guid>http://www.cppblog.com/jack-wang/archive/2009/11/27/102025.html</guid><wfw:comment>http://www.cppblog.com/jack-wang/comments/102025.html</wfw:comment><comments>http://www.cppblog.com/jack-wang/archive/2009/11/27/102025.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jack-wang/comments/commentRss/102025.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jack-wang/services/trackbacks/102025.html</trackback:ping><description><![CDATA[<p style="COLOR: #000000; FONT-SIZE: 10pt" class=postTitle>转：<a href="http://www.cppblog.com/yuanyajie/archive/2006/11/01/14485.html">http://www.cppblog.com/yuanyajie/archive/2006/11/01/14485.html</a><br><br><span>使用 cegui 来制作界面 , 不论在何种平台下 , 有基本的三大步骤要做 : <br>1, 创建一个 CEGUI::Render 实例 <br>2, 创建 CEGUI::System 对象 <br>3, 调用各种方法来渲染用户界面 <br>第一步 , 在我使用的 ogre 环境下使用以下代码来创建 CEGUI::Render 实例 <br>Ogre3D <br>CEGUI::OgreCEGUIRenderer* myRenderer = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new CEGUI::OgreCEGUIRenderer(myRenderWindow); <br>第二步相当简单 , 可使用 <br>new CEGUI::System(myRenderer); <br>第三步，基本上来讲，大部分平台下，如 direct3D, OpenGL, 我们在渲染循环的尾部调用 <br>CEGUI::System::renderGUI 来开始界面的渲染。如果我们使用 ogre3d 引擎，这一步不需要 <br>我们显示的执行。因为 ogre 引擎已经考虑了。 <br>除了这三大步之外，我们还有一些工作要做，首先，我们需要加载数据文件，并且完成初始化工作。 <br>CEGUI 使用了许多类型的文件。 CEGUI 使用一个称为 ResourceProvider 的帮助对象，用它来做为核心 CEGUI 库与外部文件加载系统的接口。通过实现一个特定的 ResourceProvider 对象， cegui 的渲染模块就可以与外部系统的资源管理器、文件加载子系统无缝地集成。 CEGUI 需要的数据文件便可以通过外部系统提供的功能来进行加载。 CEGUI 中的大部分文件是以 XML 的文件格式来保存的。缺省情况下， CEGUI 在内部使用 Xerces-C++ 库来分析 XML 文件，使用 schema 来对 xml 进行校验， schema 文件以标准的 .xsd 扩展名来保存 . 许多文件本质上都是 XML 格式的文件，但是根据其意义不同，分别使用了不同的文件扩展名。 <br>.Imageset 文件可将一幅图像看做若干小图像的集合。换名话说，就是将一幅图像的某个区域看做一幅独立的图片来使用。 <br>.Font 定义了在 CEGUI 中所使用的字体类型。 <br>.scheme 　可以将许多数据组合在一起使用，它也是装载与注册 widget 最方便的方法。在一个 .scheme 文件中可以包括下列几种数据： <br>Imagest,font, window Set, window Alias <br>window set 指定了装载模块（ .dll 等）的名称，和一组可以注册到系统中的 widget. <br>window alias 提供了别名的功能，实现已经注册的 window/widget 的形式上的隐藏。 <br>.Layout 　包含了窗口布局的 xml 表示。每个嵌套的 'window' 元素定义了被创建的 window 或是 widget."Property" 元素定义了窗口的设置与属性值。 <br>.config 是可供选择的配置文件，他可指定一些缺省的属性。 <br>我们使用 CEGUI 来制作图形界面，至少要使用以下三种文件： <br>.imageset, .Font . Scheme; <br>当然，我们知道在一个 Scheme 中是可以包括 imageset 与 Font 的。 <br>CEGUI::SchemeManager::getSingleton().loadScheme(&#8220;../datafiles/schemes/TaharezLook.scheme&#8221;); <br>// load in a font.&nbsp; The first font loaded automatically becomes the default font. <br>CEGUI::FontManager::getSingleton().createFont(&#8220;../datafiles/fonts/Commonwealth-10.font&#8221;); <br>对于 ogre 的使用者来讲，应该在 resources.cfg 将这些资源所在的目录加进去。 <br>我们可用下面的语句来指定 cegui 所需要的缺省的 font 与 cursor 资源。 <br>在 cegui 的概念里，每个 widget 都是一个 window, 从编程的角度来讲，每个 widget 类都是从同一个相同的 window 基类继承而来的 . 因此， widget 与 window 有着基本相同的行为。 <br>窗体的许多属性与设置在窗口层树上是可以遗传的。高一级窗口的属性与行为会影响到下一级窗口的属性与行为。例如附着在某个 window 上的 window 与 widget 会被父 window 影响。当父窗口被 destroy 时，它所附属的所有的子窗口与 widget 也都将被 destroy. <br>创建 CEGUI 窗口，我们可以使用两种形式，一是 C ＋＋代码，二是编辑 XML layout 文件。 <br>注意：在 CEGUI 中，所有的 window 都是由 WindowManager singleton object 来统一创建的。我们首先得到这个对象： <br>using namespace CEGUI; <br>WindowManager&amp; wmgr = WindowManager::getSingleton(); <br>一般来讲，我们总是创建一个 DefaultWindow 来做为我们将使用的窗口的 Root, 在这种方式下，我们会有比较好的灵活性。 <br>Window* myRoot = wmgr.createWindow(&#8220;DefaultWindow&#8221;, &#8220;root&#8221;); <br>System::getSingleton().setGUISheet(myRoot); <br>createwindows() 函数所使用的第一个参数，指明了将要创建的窗口类型，它一般是在我们使用的 .scheme 文件中所注册过的，当然还有一些系统定义的，总是有效的窗口类型如上面所提到的 DefaultWindow.DefualtWindow 是不可见的，它只是做为所有窗口的 root 来使用。 <br>一般我们总是要创建一个 Framewindow, 它可以包括其他窗口与 widget ，本身也是可视的。 <br>FrameWindow* fWnd = (FrameWindow*)wmgr.createWindow(&#8220;TaharezLook/FrameWindow&#8221;, &#8220;testWindow&#8221;); <br>之后，我们将创建的窗口挂到 root 上，形成一个层次关系。 <br>myRoot-&gt;addChildWindow(fWnd); <br>编辑 xml layout 文件，可使用专门提供的制作工具。具体的使用方法可以参阅相关文档，这里说一下如何使用制作好的 xml layout 文件。 <br>using namespace CEGUI; <br>Window* myRoot = WindowManager::getSingleton().loadWindowLayout(&#8220;test.layout&#8221;); <br>System::getSingleton().setGUISheet(myRoot); <br>首先，将 layout 文件装载进来，再指定根结点。 <br>CEGUI 本身侦测用户输入，这些不是 CEGUI 的责任，而是程序的员的责任。当有用户外部输入时，我 <br>们可以选择将这些消息告知 CEGUI ，这样 CEGUI 才会响应。 <br>在 ceguir::System 类中定义了一组函数，它作为我们进行消息传递的接口。 <br>bool injectMouseMove(float delta_x, float delta_y); <br>bool injectMousePosition(float x_pos, float y_pos); <br>bool injectMouseLeaves(void); <br>bool injectMouseButtonDown(MouseButton button); <br>bool injectMouseButtonUp(MouseButton button); <br>bool injectKeyDown(uint key_code); <br>bool injectKeyUp(uint key_code); <br>bool injectChar(utf32 code_point); <br>bool injectMouseWheelChange(float delta); <br>bool injectTimePulse(float timeElapsed); <br>这些函数的返回值说明了 CEGUI 是否已经将传入的消息 consume 掉了。 <br>CEGUI 使用回调机制来进行消息处理。可以为某个窗体的特定事件注册一个函数，当窗体事件发生时， CEGUI 会自动调用所注册的函数。 <br>bool TutorialApplication::handlePopMenu(constCEGUI::EventArgs&amp; e) <br>｛ <br>// 。。。。。进行事件响应 <br>｝ <br>void setupEventHandlers(void) <br>&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CEGUI::WindowManager&amp; wmgr = CEGUI::WindowManager::getSingleton(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmgr .getWindow((CEGUI::utf8*)"MyButton")-&gt;subscribeEvent( <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CEGUI ::PushButton::EventClicked, CEGUI::Event::Subscriber(&amp;TutorialApplication::handlePopMenu, this)); <br>&nbsp;&nbsp; }</span> </p>
<p style="FONT-SIZE: 10pt">EventClicked :: 系统预定义的事件 . subscribeEvent:: 注册函数，它事件与响应函数联接在一起。 <br>在 ogre 程序中，当侦听器收到键盘，鼠标消息时，首先经过适当的转换（ CEGUI 可以识别）再传递给 CEGUI 。下面这个函数执行鼠标键标识转换。 <br>CEGUI::MouseButton convertOgreButtonToCegui(int buttonID) <br>{ <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch (buttonID) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MouseEvent::BUTTON0_MASK: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return CEGUI::LeftButton; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MouseEvent::BUTTON1_MASK: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return CEGUI::RightButton; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MouseEvent::BUTTON2_MASK: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return CEGUI::MiddleButton; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MouseEvent::BUTTON3_MASK: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return CEGUI::X1Button; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return CEGUI::LeftButton; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>} </p>
<p style="FONT-SIZE: 10pt">将 CEGUI 需要知道的键盘，鼠标消息告知它。即在 OGRE 处理这些消息时通知 CEGUI 。以下这函数说明了用法。 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void mouseMoved (MouseEvent *e)// 鼠标移动 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CEGUI::System::getSingleton().injectMouseMove( <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e-&gt;getRelX() * mGUIRenderer-&gt;getWidth(), <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e-&gt;getRelY() * mGUIRenderer-&gt;getHeight()); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e-&gt;consume(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </p>
<p style="FONT-SIZE: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void mousePressed (MouseEvent *e)// 鼠标按下 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CEGUI::System::getSingleton().injectMouseButtonDown( <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; convertOgreButtonToCegui(e-&gt;getButtonID())); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e-&gt;consume(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void mouseReleased (MouseEvent *e)// 鼠标弹起 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CEGUI::System::getSingleton().injectMouseButtonUp( <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; convertOgreButtonToCegui(e-&gt;getButtonID())); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e-&gt;consume(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </p>
<p style="FONT-SIZE: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void keyPressed(KeyEvent* e)// 键按下 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CEGUI::System::getSingleton().injectKeyDown(e-&gt;getKey()); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CEGUI::System::getSingleton().injectChar(e-&gt;getKeyChar()); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e-&gt;consume(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void keyReleased(KeyEvent* e)// 键弹起 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CEGUI::System::getSingleton().injectKeyUp(e-&gt;getKey()); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e-&gt;consume(); </p>
<p style="FONT-SIZE: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>在 CEGUI 中使用中文的问题：&nbsp;&nbsp; 现在总结了一下在 CEGUI 中显示中文需要注意的事项 :<br>&nbsp;&nbsp;&nbsp; 1 、将 simhei.ttf copy to \ogrenew\Samples\Media\gui<br>&nbsp;&nbsp;&nbsp; 2 、将 simhei-12.font&nbsp; 拷到上目录内容为 <br>&lt;?xml version="1.0"&nbsp; ?&gt;<br>&lt;Font Name="SimHei-12" Filename="simhei.ttf" Type="Dynamic" Size="12" NativeHorzRes="800" NativeVertRes="600"&nbsp; <br>AutoScaled="true"&gt;<br>&lt;GlyphSet Glyphs=" 你好世界退出演示渲染到新材质建编辑窗口 " /&gt; （ &lt;---- 自己要用到的汉字） <br>&lt;/Font&gt; <br>注意大小写！！ GlyphSet Glyphs 是在程序中要用到的汉字，它是让 cegui 预生成一个字符图像集用的（想当然的 :-P ）如果修改了这个文件，注意要用 Unicode （ UTF-8 ）的编码来保存，在 vc7.1 中：文件 -&gt; 高级保存选项&nbsp;&nbsp; 的&nbsp;&nbsp; 编码&nbsp;&nbsp; 栏中选择。 <br>&nbsp;&nbsp;&nbsp; 3 、在 TaharezLook.scheme 中 <br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;Font Name="Tahoma-12" Filename="tahoma-12.font" /&gt; 后加入 <br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;Font Name="SimHei-12" Filename="simhei-12.font" /&gt;&nbsp; 注意大小写 <br>&nbsp;&nbsp;&nbsp;&nbsp; 以上是一些准备工作 <br>&nbsp;&nbsp;&nbsp; 4 、在自己的应用中设置默认字体 <br>&nbsp;&nbsp;&nbsp; mGUISystem-&gt;setDefaultFont((CEGUI::utf8*)"Tahoma-12"); 改为 <br>&nbsp;&nbsp;&nbsp; mGUISystem-&gt;setDefaultFont((CEGUI::utf8*)"SimHei-12"); <br>&nbsp;&nbsp;&nbsp; 5 、在自己的应用程序中就可以把相关的 Text 属性该为中文了，如： <br>&nbsp;&nbsp;&nbsp; item = new CEGUI::ListboxTextItem((CEGUI::utf8*)" 退出 ", 6); <br>&nbsp;&nbsp;&nbsp; 同样要注意的是要保存为 Unicode （ UTF-8 ）的编码。同时这些字要是在 simhei-12.font 中定义过的字，当然也可以象那个 CEGUIChieseDemo <br>那样用动态生成如： <br>&nbsp;&nbsp;&nbsp; gfont-&gt;defineFontGlyphs(gfont-&gt;getAvailableGlyphs() + (utf8*)" 当前最佳坏平均的框架率三角 "); <br>&nbsp;&nbsp;&nbsp; 编译自己的程序，应该就可以看到中文了，罗嗦一下，记住只要有汉字出现的文件就保存为 Unicode （ UTF-8 ）编码的！！！ </p>
<img src ="http://www.cppblog.com/jack-wang/aggbug/102025.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jack-wang/" target="_blank">小王</a> 2009-11-27 03:09 <a href="http://www.cppblog.com/jack-wang/archive/2009/11/27/102025.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>编译运行Orz</title><link>http://www.cppblog.com/jack-wang/archive/2009/11/18/101270.html</link><dc:creator>小王</dc:creator><author>小王</author><pubDate>Wed, 18 Nov 2009 00:05:00 GMT</pubDate><guid>http://www.cppblog.com/jack-wang/archive/2009/11/18/101270.html</guid><wfw:comment>http://www.cppblog.com/jack-wang/comments/101270.html</wfw:comment><comments>http://www.cppblog.com/jack-wang/archive/2009/11/18/101270.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jack-wang/comments/commentRss/101270.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jack-wang/services/trackbacks/101270.html</trackback:ping><description><![CDATA[1.vc2005一定要安装补丁程序VS80sp1-KB926604-X86-CHS.exe。<br>2.注意，从svn上下载的代码，工程的默认当前路径为Orz\Scripts\vc8（如果使用vc8编译）。奇怪！<br>3.从官网上下载依赖文件（dependencies文件夹），将dependencies文件夹放置于包含Orz_vc8.sln的目录中。<br>各个工程文件的&#8220;附加包含目录&#8221;中做如此修改：..\..\dependencies\dependencies\include<br>链接器的&#8220;附加包含库&#8221;中做如此修改：..\..\dependencies\dependencies\lib\debug 
<img src ="http://www.cppblog.com/jack-wang/aggbug/101270.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jack-wang/" target="_blank">小王</a> 2009-11-18 08:05 <a href="http://www.cppblog.com/jack-wang/archive/2009/11/18/101270.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vs2005环境下CELayoutEditor源码编译详细步骤 </title><link>http://www.cppblog.com/jack-wang/archive/2009/06/18/88040.html</link><dc:creator>小王</dc:creator><author>小王</author><pubDate>Thu, 18 Jun 2009 14:51:00 GMT</pubDate><guid>http://www.cppblog.com/jack-wang/archive/2009/06/18/88040.html</guid><wfw:comment>http://www.cppblog.com/jack-wang/comments/88040.html</wfw:comment><comments>http://www.cppblog.com/jack-wang/archive/2009/06/18/88040.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/jack-wang/comments/commentRss/88040.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jack-wang/services/trackbacks/88040.html</trackback:ping><description><![CDATA[vs2005环境下CELayoutEditor源码编译详细步骤：<br>今天初试了一下CEGUI的官方编辑器——CELayoutEditor，其过程真可谓&#8220;饱受挫折&#8221;。现简要写下其源码的编译过程，已使可能会用到的朋友少走些弯路。<br>1. 要编译CELayoutEditor，自然需要先编译CEGUI的东东，有2种选择： <br>1.1 安装SDK，这是下载地址：http://jaist.dl.sourceforge.net/sourceforge/crayzedsgui/CEGUI-SDK-0.5.0b-vc8.exe，不过并不推荐这种方法，因为SDK里的debug版dll似乎有问题。。。 <br>1.2 编译其源代码。下载地址：http://jaist.dl.sourceforge.net/sourceforge/crayzedsgui/CEGUI-0.5.0b.zip，另外还需要下载依赖文件包dependencies package ，下载地址是：http://jaist.dl.sourceforge.net/sourceforge/crayzedsgui/CEGUI-DEPS-0.5.0b-vc8.zip，然后将依赖文件解压进源代码文件夹就OK了。&nbsp;<br>1.2.1 先别急着找solution，有个地方需要注意。CEGUI默认的是OPENGL渲染，如果是用D3D的话还得改一个地方。进..\makefiles\premake文件夹找到config.lua文件，记事本打开。改成&#8220;OPENGL_RENDERER = false，DIRECTX9_RENDERER = true&#8221;，保存。 <br>1.2.2 运行build_vs2005.bat文件，执行完毕后会生成CEGUI.sln文件，打开就可直接编译了 <br>1.3 建立环境变量：我的电脑\属性\高级\环境变量，然后在上面的用户变量区新建一个，变量名是CEGUI，变量值是CEGUI的解压目录。注意这步不能省 <br><br>2 由于CELayoutEditor使用了wxWidgets，所以在编译CELayoutEditor之前还需要下载wxWidgets。目前最新版本是2.86，进入官方下载网页http://www.wxwidgets.org/downloads/ 选择WxAll下载。 <br>2.1 建立环境变量：我的电脑\属性\高级\环境变量，然后在上面的用户变量区新建一个，变量名是WXWIDGETS，变量值是wxWidgets的解压目录。 2.2 进wxWidgets的解压目录找到wx.dsw，打开、&#8220;Yes To All&#8221;转换。转换完毕后先别编译，还需要改下。<br>因为wxWidgets默认并不是OPENGL Open $(WXWIDGETS)\include\wx\msw\setup.h and replace Code: #define wxUSE_GLCANVAS 0 WITH Code: #define wxUSE_GLCANVAS 1 7.2 Open $(WXWIDGETS)\include\wx\univ\setup.h and replace Code: #if defined(__WIN32__) #define wxUSE_GLCANVAS 1 else #define wxUSE_GLCANVAS 0 WITH Code: #define wxUSE_GLCANVAS 1 <br>2.3 现在就可以开始编译了。<br>注意要选择&#8220;Unicode Debug&#8221;和&#8220;'Unicode Release&#8221;方式 <br><br>3 下载CELayoutEditor。<br>我是用SVN接的，地址是 https://crayzedsgui.svn.sourceforge.net/svnroot/crayzedsgui/CELayoutEditor/trunk <br>3.1 解压后打开工程，将Include和Lib路径改成自己的，其他的不用改。<br>3.2 建立环境变量：我的电脑\属性\高级\环境变量，然后在上面的用户变量区新建一个，变量名是CE_LAYOUT_EDITOR ，变量值是CELayoutEditor的解压目录。注意这步不能省。<br>3.3 终于可以开始编译了。。。 <br><br>4 4.1 编译会出现一个错误，暂时我还没找到解决方法，仅仅是给错误的地方注释掉了。。。然后就编译成功了。 <br>4.2 拷一些东西过来 <br>TO $(CE_LAYOUT_EDITOR)\bin\debug (Debug configuration) - CEGUIBase_d.dll - CEGUIExpatParser_d.dll - CEGUIFalagardWRBase_d.dll - CEGUISILLYImageCodec_d.dll - CEGUITGAImageCodec_d.dll - OpenGLGUIRenderer_d.dll - SILLY_d.dll TO $(CE_LAYOUT_EDITOR)\bin\release (Release configuration) - CEGUIBase.dll - CEGUIExpatParser.dll - CEGUIFalagardWRBase.dll - CEGUISILLYImageCodec.dll - CEGUITGAImageCodec.dll - OpenGLGUIRenderer.dll - SILLY.dll 4.3 SILLY.dll和SILLY_d.dll在依赖文件夹里 <br>OK。。。到这里就完了，虽然这个工具的bug很多，不过不怕，编译它就是为了要改造它，呵呵。<br>希望此文对你有所帮助。
<img src ="http://www.cppblog.com/jack-wang/aggbug/88040.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jack-wang/" target="_blank">小王</a> 2009-06-18 22:51 <a href="http://www.cppblog.com/jack-wang/archive/2009/06/18/88040.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用OgreOde创建一个会走动的角色</title><link>http://www.cppblog.com/jack-wang/archive/2009/01/02/70974.html</link><dc:creator>小王</dc:creator><author>小王</author><pubDate>Thu, 01 Jan 2009 20:56:00 GMT</pubDate><guid>http://www.cppblog.com/jack-wang/archive/2009/01/02/70974.html</guid><wfw:comment>http://www.cppblog.com/jack-wang/comments/70974.html</wfw:comment><comments>http://www.cppblog.com/jack-wang/archive/2009/01/02/70974.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jack-wang/comments/commentRss/70974.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jack-wang/services/trackbacks/70974.html</trackback:ping><description><![CDATA[<div id=content><strong><span>用<span>OgreOde</span>创建一个会走动的角色</span></strong> <br>
<p align=left>原文<a href="http://www.game798.com/html/2007-12/5156.htm">http://www.game798.com/html/2007-12/5156.htm</a><br><span><br></span><span>第一版<span> by SuperMegaMau </span></span></p>
<p align=left><span>这个教程包括的代码和算法是作者自己的经验<span>,</span>也许不正确或不怎么准确<span>,</span>如果发现问题请纠正。</span></p>
<p align=left>&nbsp;</p>
<table cellPadding=0 width=318 border=0>
    <tbody>
        <tr>
            <td>
            <p align=left><strong><span>内容</span></strong></p>
            <ul type=disc>
                <li><u><span>1 </span></u><u><span>介绍</span></u>
                <li><span>2 <span><span>创建物理模型</span></span><span><span> </span></span>&nbsp;</span>
                <ul type=circle>
                    <li><span>2.1 <span><span>创建角色</span></span><span><span> </span></span>&nbsp;</span>
                    <li><u><span>2.2 </span></u><u><span>获取<span> AABB</span></span></u><span> </span>
                    <li><u><span>2.3 </span></u><u><span>创建新空间 </span></u><span>&nbsp;</span>
                    <li><u><span>2.4 </span></u><u><span>创建球 </span></u><span>&nbsp;</span>
                    <li><u><span>2.5 </span></u><u><span>创建椭球 </span></u><span>&nbsp;</span>
                    <li><u><span>2.6 </span></u><u><span>创建关节 </span></u><span>&nbsp;</span> </li>
                </ul>
                <li><u><span>3 </span></u><u><span>移动角色 </span></u><span>&nbsp;</span>
                <ul type=circle>
                    <li><u><span>3.1 </span></u><u><span>前后移动</span></u><span> </span>
                    <li><span>3.2 <span><span>左右旋转</span></span><span><span> </span></span>&nbsp;</span> </li>
                </ul>
                <li><u><span>4 </span></u><u><span>让角色爬起来 </span></u>
                <li><u><span>5 </span></u><u><span>问题 </span></u></li>
            </ul>
            </td>
        </tr>
    </tbody>
</table>
<p align=left><strong><span>介绍</span></strong></p>
<p align=left><span>我相信我不是第一人自问如何用<span>OgreOde</span>创建一个运动角色。搜索论坛和<span>wiki</span>后，我意识到这是一个很有用的信息。这个教程解释了如何创建一个可以在地形上行走的运动角色（包括其它<span>meshes</span>，如树和房屋）。</span></p>
<p align=left><strong><span>创建物理模型</span></strong></p>
<p align=left><span>我按照在<span>Monster</span>的方法用下图代表一个角色：</span></p>
<p align=left><span></span></p>
<p align=left><span>下面<span>,</span>我假设你对<span>Ogre</span>的<span>SceneNodes, meshes </span>和<span>AlignedBoxes</span>都有所了解，并且会用<span>SceneManager</span>创建地形。</span></p>
<p align=left><strong><span>创建角色</span></strong></p>
<p align=left><span>首先创建一个<span>SceneNode</span>来放角色的<span>mesh</span>，在这个例子中我用了<span>Ogre</span>例子中的忍者模型。创建两个<span>SceneNode</span>并把它们连在一起。后面我会解释为什么是两个<span>Node</span>。</span></p>
<p align=left><span>Entity* ninja = mSceneMgr-&gt;createEntity("ninja","ninja.mesh");</span></p>
<p align=left><span>SceneNode* ninjaNode = mSceneMgr-&gt;getRootSceneNode()-&gt;createChildSceneNode("ninja");</span></p>
<p align=left><span>SceneNode* modelNode = ninjaNode-&gt;createChildSceneNode("ninja_model");</span></p>
<p align=left><span>modelNode-&gt;attachObject(ninja);</span></p>
<p align=left><span>ninjaNode-&gt;setScale(0.05,0.05,0.05);</span></p>
<p align=left><span>
<table cellSpacing=0 cellPadding=0 width="100%">
    <tbody>
        <tr>
            <td>
            <div>
            <p><span>RootSceneNode</span></p>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<table cellSpacing=0 cellPadding=0 width="100%">
    <tbody>
        <tr>
            <td>
            <div>
            <p><span>ninjaNode</span></p>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<table cellSpacing=0 cellPadding=0 width="100%">
    <tbody>
        <tr>
            <td>
            <div>
            <p><span>modelNode</span></p>
            </div>
            </td>
        </tr>
    </tbody>
</table>
</span></p>
<p align=left><span>也许你已经注意到，<span>ninjaNode</span>被缩放得很小，这是因为如果<span>mesh</span>很大的话渲染的速度就变很慢（不知道为什么）。</span></p>
<p align=left><strong><span>获取<span> AABB(</span></span></strong><strong><span>AxisAlignedBox, </span></strong><strong><span>轴对齐包围盒</span></strong><strong><span>) </span></strong></p>
<p align=left><span>现在用<span>AxisAlignedBox</span>获取<span>mesh</span>的大小。</span></p>
<p align=left><span>AxisAlignedBox aab = modelNode-&gt;getAttachedObject("ninja")-&gt;getBoundingBox(); </span></p>
<p align=left><span>Ogre::Vector3 min = aab.getMinimum()*ninjaNode-&gt;getScale();</span></p>
<p align=left><span>Ogre::Vector3 max = aab.getMaximum()*ninjaNode-&gt;getScale();</span></p>
<p align=left><span>Ogre::Vector3 center = aab.getCenter()*ninjaNode-&gt;getScale();</span></p>
<p align=left><span>Ogre::Vector3 size(fabs(max.x-min.x),fabs(max.y-min.y),fabs(max.z-min.z));</span></p>
<p align=left><span>float radius = (size.x&gt;size.z)?size.z/2.0f:size.x/2.0f; </span></p>
<p align=left>&nbsp;</p>
<p align=left><strong><span>创建一个新空间<span> </span></span></strong></p>
<p align=left><span>我们需要创建一个新空间把角色放在其中，并且取消内部碰撞检测。</span></p>
<p align=left><span>OgreOde::SimpleSpace* dollSpace = new OgreOde::SimpleSpace(_world-&gt;getDefaultSpace());</span></p>
<p align=left><span>dollSpace-&gt;setInternalCollisions(false);</span></p>
<p align=left><strong><span>创建球体<span>(</span><span>腿部<span>) </span></span></span></strong></p>
<p align=left><span>现在有了两个<span>SceneNodes</span>，<span> "ninjaNode" </span>和<span> "modelNode"</span>。<span>ninjaNode</span>是代表你角色的节点，<span>modelNode</span>是你真正贴<span>mesh</span>的地方。这么做是因为<span>mesh</span>的中心总是在<span>OgreOde::Body</span>的中心，所以我们用<span>ninjaNode</span>来创建碰撞体的位置，然后根据<span>ninjaNode</span>和<span>OgreOde::Body</span>来获得<span>mesh</span>的正确位置。</span></p>
<p align=left><span></span></p>
<p align=left><span>左边图是用一个<span>SceneNode</span>所得到的效果，右边是用两个<span>SceneNode</span>。你可以注意到，左边的角色悬浮在半空中。下面代码创建了一个球体代表角色的脚部。我们需要一个<span>SphereGeometry</span>和一个<span>TransformGeometry </span>将球体放到正确位置。</span></p>
<p align=left><strong><span>译注：注释为我的猜想，具体不知道步骤这么复杂，欢迎纠正。<span> </span></span></strong></p>
<p align=left><span><span>（1）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>创建一个碰撞体，命名为<span>feet</span></span></p>
<p align=left><span><span>（2）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>设置碰撞体为球形物体，半径为<span>AABB</span>获得的半径</span></p>
<p align=left><span><span>（3）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>SphereGeometry</span><span>，半径为<span>AABB</span>获得的半径</span></p>
<p align=left><span><span>（4）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>TransformGeometry</span><span>，空间为刚才创建的空间<span>, TransformGeometry</span>似乎是为了包含某特定形状的几何体</span></p>
<p align=left><span><span>（5）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><u><span>改变<span>modelNode</span>相对于<span>ninjiaNode</span>的位置，以便让脚占到地上</span></u></p>
<p align=left><span><span>（6）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>让<span>TransformGeometry</span>包含一个<span>OgreOde::Body</span>和一个几何体</span></p>
<p align=left><span><span>（7）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>将<span>Ogre::Body</span>粘到<span>ninjaNode</span>上</span></p>
<p align=left><span>怀疑创建<span>SphereGeometry</span>是否只是让<span>Ogre::Body</span>具象化</span></p>
<p align=left>&nbsp;</p>
<p align=left><span>OgreOde::Body* dollFeetBody = new OgreOde::Body("feet");<span>&nbsp;&nbsp; </span></span></p>
<p align=left><span>dollFeetBody-&gt;setMass(OgreOde::SphereMass(70*2.5,radius)); </span></p>
<p align=left><span>OgreOde::SphereGeometry* feetGeom = new OgreOde::SphereGeometry(radius);</span></p>
<p align=left><span>OgreOde::TransformGeometry* feetTrans = new OgreOde::TransformGeometry(dollSpace); </span></p>
<p align=left><span>modelNode-&gt;translate(Vector3(0,-radius/ninjaNode-&gt;getScale().y,0));</span></p>
<p align=left><span>feetTrans-&gt;setBody(dollFeetBody); </span></p>
<p align=left><span>feetTrans-&gt;setEncapsulatedGeometry(feetGeom);</span></p>
<p align=left><span>ninjaNode-&gt;attachObject(dollFeetBody);</span></p>
<p align=left><strong><span>创建椭球体<span> </span></span></strong></p>
<p align=left><span>对于角色的上半身用一个椭球体来表示。<span> </span></span></p>
<p align=left><strong><span>译注</span></strong><span>：和上面一样。</span></p>
<p align=left><span><span>（1）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>创建<span>Ogre::Body</span></span></p>
<p align=left><span><span>（2）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>设置<span>Ogre::Body</span>形状，另外设置不被重力影响，</span></p>
<p align=left><span><span>（3）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>创建<span>TransformGeometry</span>，空间为刚才创建的空间</span></p>
<p align=left><span><span>（4）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>创建<span>CapsuleGeometry</span>，半径为<span>AABB</span>获得半径</span></p>
<p align=left><span><span>（5）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>设置<span>CapsuleGeometry</span>位置和方向和阻尼</span></p>
<p align=left><span><span>（6）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>让<span>TransformGeometry</span>包含<span>Ogre::body</span></span></p>
<p align=left><span><span>（7）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>让<span>TransformGeometry</span>包含<span>CapsuleGeometry</span></span></p>
<p align=left><span><span>（8）<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span>将<span>Ogre::Body</span>粘到<span>ninjiaNode</span>上</span></p>
<p align=left><span>OgreOde::Body* dollTorsoBody = new OgreOde::Body("torso"); </span></p>
<p align=left><span>dollTorsoBody-&gt;setMass(OgreOde::CapsuleMass(70*2.5,radius,Vector3::UNIT_Y,radius)); </span></p>
<p align=left><span>dollTorsoBody-&gt;setAffectedByGravity(false);</span></p>
<p align=left><span>dollTorsoBody-&gt;setDamping(0,50000);</span></p>
<p align=left><span>OgreOde::TransformGeometry* torsoTrans = new OgreOde::TransformGeometry(dollSpace); </span></p>
<p align=left><span>OgreOde::CapsuleGeometry* torsoGeom = new OgreOde::CapsuleGeometry(radius,size.y-4*radius,dollSpace); </span></p>
<p align=left><span>torsoGeom-&gt;setPosition(Ogre::Vector3(0,size.y-((size.y-4*radius)/2+2*radius),0)); //can't find a good way to explain this</span></p>
<p align=left><span>torsoGeom-&gt;setOrientation(Quaternion(Degree(90),Vector3::UNIT_X));</span></p>
<p align=left><span>torsoTrans-&gt;setBody(dollTorsoBody); </span></p>
<p align=left><span>torsoTrans-&gt;setEncapsulatedGeometry(torsoGeom);</span></p>
<p align=left><span>ninjaNode-&gt;attachObject(dollTorsoBody);</span></p>
<p align=left><span>这个几何体和脚的几何体在同一个空间，所以我们要取消内部碰撞检测。讲阻尼设置高些，并且取消重力，不然它会从那个球体上掉下来。</span></p>
<p align=left><strong><span>创建关节<span> </span></span></strong></p>
<p align=left><span>剩下的事情就是将两个碰撞体连在一起了。一个绞连连接的代表是自行车前轮。<span> </span></span></p>
<p align=left><span>OgreOde::HingeJoint* joint = new OgreOde::HingeJoint();</span></p>
<p align=left><span>joint-&gt;attach(dollTorsoBody,dollFeetBody);</span></p>
<p align=left><span>joint-&gt;setAxis(Ogre::Vector3::UNIT_X);<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>//set the rotation axis</span></p>
<p align=left><strong><span>注意：</span></strong><span>不要忘记记录所有碰撞体和连接的位置以便你之后能得到它们。你可以用<span>ogre</span>堆栈或者创建你自己的。</span></p>
<p align=left><strong><span>移动角色<span> </span></span></strong></p>
<p align=left><span>你可以通过不同方法移动或者旋转你的角色，我决定通过改变碰撞体方向而不是施加力或者力矩。</span></p>
<p align=left><strong><span>前后移动<span> </span></span></strong></p>
<p align=left><span>下面代码可以放在按键响应里执行，象<span>KC_UP</span>。现在你需要获取碰撞体，从堆栈或者<span>hashTable</span>中获得，然后获取它的方向。我用：</span></p>
<p align=left><strong><span>译注：猜想堆栈就是你为屏幕上所有物体所创建的<span>Ogre::Body</span>的一个列表。<span> </span></span></strong></p>
<p align=left><span>OgreOde::Body* torso = torsoBodies-&gt;getObject("ninja");</span></p>
<p align=left><span>Quaternion q = torso-&gt;getOrientation();</span></p>
<p align=left><span>然后赋予脚一个角速度。<span> </span></span></p>
<p align=left><span>OgreOde::Body* feet = feetBodies-&gt;getObject("ninja");</span></p>
<p align=left><span>feet-&gt;wake();</span></p>
<p align=left><span>feet-&gt;setAngularVelocity(q*Ogre::Vector3(10*cos(1),0,10*sin(1)));</span></p>
<p align=left><span>10</span><span>是我们用的角速度，必须乘以三角函数以便让角色向正确的方向前进。</span></p>
<p align=left><strong><span>左右转动<span> </span></span></strong></p>
<p align=left><span>下面代码同样放在按键响应中执行，比如<span>KC_RIGHT</span>。<span> </span></span></p>
<p align=left><span>OgreOde::Body* torso = torsoBodies-&gt;getObject("ninja");</span></p>
<p align=left><span>Quaternion q1 = torso-&gt;getOrientation();</span></p>
<p align=left><span>Quaternion q2(Degree(-4),Ogre::Vector3::UNIT_Y);</span></p>
<p align=left><span>torso-&gt;setOrientation(q1*q2);</span></p>
<p align=left><span>用<span>Degree(-4)</span>让角色向右转动，用正数向左转动。也许你已经注意到，我总是从椭球体获取或者设置方向。我没有太多想，我想如果你从脚的球体来获取和设置也应该没有什么问题。</span></p>
<p align=left><strong><span>注意：</span></strong><span>如果你松开按键，你必须把速度设置为<span>0</span>来停止运动。</span></p>
<p align=left><span>feetbody-&gt;setAngularVelocity(Vector3(0,0,0));</span></p>
<p align=left><span>feetBody-&gt;setLinearVelocity(Vector3(0,feetBody-&gt;getLinearVelocity().y,0));</span></p>
<p align=left><strong><span>让角色爬起来<span> </span></span></strong></p>
<p align=left><span>最后，我们要确定你的角色不摔倒，所以我们需要不时重新设定他的垂直方向。<span> </span></span></p>
<p align=left><span>OgreOde::Body* torso = torsoBodies-&gt;getObject("ninja");</span></p>
<p align=left><span>Quaternion q = torso-&gt;getOrientation();<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>
<p align=left>&nbsp;</p>
<p align=left><span>Vector3 x = q.xAxis();</span></p>
<p align=left><span>Vector3 y = q.yAxis();</span></p>
<p align=left><span>Vector3 z = q.zAxis();</span></p>
<p align=left>&nbsp;</p>
<p align=left><span>torso-&gt;wake();</span></p>
<p align=left><span>torso-&gt;setOrientation(Quaternion(x,Vector3::UNIT_Y,z));</span></p>
<p align=left><strong><span>问题<span> </span></span></strong></p>
<p align=left><span>部分代码没有我想象的那么好。我重新设定垂直方向会让角色有奇怪的行为。虽然我设置了速度为<span>0</span>，但是角色在一些不规则的表面上仍然无法停下来。<span> </span></span></p>
</div>
<img src ="http://www.cppblog.com/jack-wang/aggbug/70974.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jack-wang/" target="_blank">小王</a> 2009-01-02 04:56 <a href="http://www.cppblog.com/jack-wang/archive/2009/01/02/70974.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DXUT进阶(翻译)</title><link>http://www.cppblog.com/jack-wang/archive/2009/01/02/70964.html</link><dc:creator>小王</dc:creator><author>小王</author><pubDate>Thu, 01 Jan 2009 19:36:00 GMT</pubDate><guid>http://www.cppblog.com/jack-wang/archive/2009/01/02/70964.html</guid><wfw:comment>http://www.cppblog.com/jack-wang/comments/70964.html</wfw:comment><comments>http://www.cppblog.com/jack-wang/archive/2009/01/02/70964.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jack-wang/comments/commentRss/70964.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jack-wang/services/trackbacks/70964.html</trackback:ping><description><![CDATA[<h3>DXUT进阶(翻译)</h3>
<div class=t_msgfont id=message77751>
<div id=ad_thread3_1></div>
DXUT进阶<br><br>概要<br>这个指南涵盖了更多DXUT的高级应用. 这个指南里的大部分功能是可选的, 为了以最小的代价来增强你的应用程序. DXUT提供了一个简单的基于GUI系统的精灵和一个设备设置对话框. 另外, 它还提供了一些摄像机类.<br>这个指南的结果是一个具有完善功能的GUI 用于更改设备和场景的设置. 它将有按钮, 滑块, 和文本来示范这些功能.<br>导航<br>&#8226; DXUT摄像机 <br>&#8226; DXUT对话框 <br>&#8226; 资源管理程序初始化 <br>&#8226; 3D设置对话框 <br>&#8226; 文本渲染<br>DXUT 摄像机<br>DXUT中的CModelViewerCamera 类可以简单的的管理视图变换和透视变换, 就像GUI 的功能一样.<br>&nbsp; &nbsp; CModelViewerCamera g_Camera;&nbsp; // A model viewing camera<br>摄像机类提供的第一个功能是创建视图和透视矩阵. 有了这个摄像机,没有必要担心这些矩阵. 反而, 你可以指定你在哪, 你看着什么,还有窗口的大小. 然后, 把这些参数传递给摄像机对象, 它会在后台创建这些矩阵.<br>这里我们设置摄像机的一部分视图参数. 我们指定我们在哪,和我们看着什么.<br>&nbsp; &nbsp; // Initialize the camera<br>&nbsp; &nbsp; D3DXVECTOR3 Eye( 0.0f, 0.0f, -800.0f );<br>&nbsp; &nbsp; D3DXVECTOR3 At( 0.0f, 0.0f, 0.0f );<br>&nbsp; &nbsp; g_Camera.SetViewParams( &amp;Eye, &amp;At );<br>接下来,我们指定摄像机的投影参数. 也就是说, 我们需要提供观察角度,纵横比, 和视图截锥的近、远裁剪面. 这些信息跟之前的指南提供的一样, 不同的是, 你不必担心怎么去创建矩阵.<br>&nbsp; &nbsp; // Setup the camera's projection parameters<br>&nbsp; &nbsp; float fAspectRatio = pBackBufferSurfaceDesc-&gt;Width / (FLOAT)pBackBufferSurfaceDesc-&gt;Height;<br>&nbsp; &nbsp; g_Camera.SetProjParams( D3DX_PI/4, fAspectRatio, 0.1f, 5000.)0f );<br>&nbsp; &nbsp; g_Camera.SetWindow( pBackBufferSurfaceDesc-&gt;Width, p00BackBufferSurfaceDesc-&gt;Height );<br>另外, 这个摄像机还封装了简单的鼠标反馈. 在这里, 我们指定三个鼠标按键给提供的鼠标操作: 模型旋转, 放缩, 还有摄像机旋转.试着编译工程并用每个按键体会一下各个操作.<br>&nbsp; &nbsp; g_Camera.SetButtonMasks( MOUSE_LEFT_BUTTON, MOUSE_WHEEL, MOUSE_MIDDLE_BUTTON );<br>在这个按钮组的基础上, 摄像机会监听这些输入并产生相应效果. 为了响应用户输入, 需要加入一个监听到MsgProc回调函数（DXUT消息处理函数）.<br>&nbsp; &nbsp; // Pass all remaining windows messages to camera so it can respond to user input<br>&nbsp; &nbsp; g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );<br>最后,在把所有数据都输入摄像机后, 就是取出真正的变换矩阵的时候了. 这里我们用相关函数获取投影矩阵和视图矩阵. 摄像机对象会自己计算这些矩阵.<br>&nbsp; &nbsp; g_pProjectionVariable-&gt;SetMatrix( (float*)g_Camera.GetProjMatrix() );<br>&nbsp; &nbsp; g_pViewVariable-&gt;SetMatrix( (float*)g_Camera.GetViewMatrix() );<br>DXUT 对话框<br>用户交互可以用CDXUTDialog来实现, 它在一个包含控件的对话框里接受用户输入,并且通过程序句柄传递它们. 首先, 对话框类要实例化, 然后每个单独的控件才能加入.<br>声明<br>在这个指南里, 有两个对话框会被加入, 一个叫 g_HUD跟D3D10示例共享相同的代码, 另一个叫 g_SampleUI 用于显示函数细节给这个指南. 第二个对话框用来控制模型的"胖瘦",就是设置一个变量传递给shaders.<br>&nbsp; &nbsp; CDXUTDialog g_HUD;&nbsp; &nbsp; &nbsp; // manages the 3D UI<br>&nbsp; &nbsp; CDXUTDialog g_SampleUI; // dialog for sample specific controls<br>这些对话框被CDXUTDialogResourceManager控制着.这个管理程序会在对话框之间传递消息并处理共享资源.<br>&nbsp; &nbsp; CDXUTDialogResourceManager g_DialogResourceManager; // manager for shared resources of dialogs<br>最后, 一些回调函数与GUI处理的实际消息相关联. 这个函数用于处理控件间的交互.<br>&nbsp; &nbsp; void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext );<br>对话框初始化<br>既然已经介绍了许多有用的东西, 那么需要被初始化, 这个指南将这些模块的真正初始化转移到一个单独的函数, 叫 InitApp().<br>每个对话框的控件被初始化就是在这个函数里. 每个对话框都需要调用它的初始化函数, 并传递给资源管理者来指定把控件供给谁. 同样, 它们设置回调函数来处理GUI 响应. 既然这样, 这个相关的回调函数是 OnGUIEvent.<br>&nbsp; &nbsp; g_HUD.Init( &amp;g_DialogResourceManager );<br>&nbsp; &nbsp; g_SampleUI.Init( &amp;g_DialogResourceManager );<br>&nbsp; &nbsp; g_HUD.SetCallback( OnGUIEvent );<br>&nbsp; &nbsp; g_SampleUI.SetCallback( OnGUIEvent );<br>在它们被初始化后, 每个都对话框可以加入它们想要使用的控件. 对话框 HUD加入了3个按钮用于基本功能: 切换全屏, 切换引用 (软件) 渲染器, 和改变设备.<br>要加入一个按钮, 你要指定你想要使用的IDC 标识符, 一个用于显示的字符串, 坐标, 宽和高, 还有可选的与它关联的热键. 热键可以用键盘快速地开关这些按钮.<br>注意指定的坐标与对话框的定位相关.<br>&nbsp; &nbsp; int iY = 10; <br>&nbsp; &nbsp; g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 35, iY, 125, 22 );<br>&nbsp; &nbsp; g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 35, iY += 24, 125, 22 );<br>&nbsp; &nbsp; g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 35, iY += 24, 125, 22, VK_F2 );<br>同样对于sample UI, 加入了这些控件,一个静态文本,一个滑块, 还有一个复选按钮.<br>传递给静态文本的参数是IDC 标识符,字符串,坐标, 和宽高.<br>滑块的参数是IDC 标识符,字符串,坐标, 和宽高, 还有滑块的最大最小值, 最后是存储结果的变量.<br>复选按钮包括IDC标识符,一个字符串标签,wf坐标, 宽高,还有存储结果的布尔值.<br>&nbsp; &nbsp; iY = 10;<br>&nbsp; &nbsp; WCHAR sz[100];<br>&nbsp; &nbsp; iY += 24;<br>&nbsp; &nbsp; StringCchPrintf( sz, 100, L"Puffiness: %0.2f", g_fModelPuffiness ); <br>&nbsp; &nbsp; g_SampleUI.AddStatic( IDC_PUFF_STATIC, sz, 35, iY += 24, 125, 22 );<br>&nbsp; &nbsp; g_SampleUI.AddSlider( IDC_PUFF_SCALE, 50, iY += 24, 100, 22, 0, 2000, (int)(g_fModelPuffiness*100.0f) );<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; iY += 24;<br>&nbsp; &nbsp; g_SampleUI.AddCheckBox( IDC_TOGGLESPIN, L"Toggle Spinning", 35, iY += 24, 125, 22, g_bSpinning );<br>一旦初始化了, 这个对话框要显示在屏幕上. 这个由 OnD3D10ResizedSwapChain 调用来完成既然屏幕坐标每次改变这个交换链会重建 (可能由于窗口大小的变化).<br>&nbsp; &nbsp; g_HUD.SetLocation( pBackBufferSurfaceDesc-&gt;Width-170, 0 );<br>&nbsp; &nbsp; g_HUD.SetSize( 170, 170 );<br>&nbsp; &nbsp; g_SampleUI.SetLocation( pBackBufferSurfaceDesc-&gt;Width-170, pBackBufferSurfaceDesc-&gt;Height-300 );<br>&nbsp; &nbsp; g_SampleUI.SetSize( 170, 300 );<br>对话框的最后一步在哪需要鉴别它们自己是 OnD3D10FrameRender 函数. 一个对话框如果你不绘制它并且用户看不到不太好吧?<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; // Render the UI<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; g_HUD.OnRender( fElapsedTime ); <br>&nbsp; &nbsp; g_SampleUI.OnRender( fElapsedTime );<br>资源管理程序初始化<br>资源管理程序在每次回调初始化和销毁时需要被初始化. 这是因为在每次设备被重建的时候 GUI需被重建, 或者交换链被重建的时候. CDXUTDialogResourceManager 类包含符合每个这样的回调的函数, 具有一模一样的名字. 因此, 它仅仅是在合适的地方插入代码来调用它们.<br>&nbsp; &nbsp; V_RETURN( g_DialogResourceManager.OnD3D10CreateDevice( pd3dDevice ) );<br>&nbsp; &nbsp; V_RETURN( g_DialogResourceManager.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );<br>&nbsp; &nbsp; g_DialogResourceManager.OnD3D10ReleasingSwapChain();<br>&nbsp; &nbsp; g_DialogResourceManager.OnD3D10DestroyDevice();<br>响应GUI事件<br>当全部初始化完成后, 我们最后可以开始写代码来处理GUI交互了. 在我们初始化对话框的时候,我们设置这些对话框的回调函数做为OnGUIEvent. 现在我们将要创建 OnGUIEvent 函数, 它会监听并处理GUI 相关事件(被框架调用的).<br>这是一个简单的对每个IDC标识符包含一个case代码块的函数，它在对话框创建时被监听. 在每个case块中会是处理代码,假设用户以某种方式控制.这里的处理控制的代码跟 Win32 代码很像.<br>跟HUD 相关的控制实际上调用DXUT内置的函数. 有一个DXUT 函数关系到切换全屏, 绑定引用软件渲染器, 并且更改设备设置(它会调用下面提到的3D设置对话框).<br>SampleUI 对话框包含自定义的代码操作跟滑块相关联的变量. 它会收集数值, 更新与它相关的文本, 并把数值传递给滑块.<br>&nbsp; &nbsp; void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; switch( nControlID )<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case IDC_TOGGLEFULLSCREEN: DXUTToggleFullScreen(); break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case IDC_TOGGLEREF:&nbsp; &nbsp; &nbsp; &nbsp; DXUTToggleREF(); break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case IDC_CHANGEDEVICE:&nbsp; &nbsp; g_D3DSettingsDlg.SetActive( !g_D3DSettingsDlg.IsActive() ); break;<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case IDC_TOGGLESPIN:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_bSpinning = g_SampleUI.GetCheckBox( IDC_TOGGLESPIN )-&gt;GetChecked();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case IDC_PUFF_SCALE: <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_fModelPuffiness = (float) (g_SampleUI.GetSlider( IDC_PUFF_SCALE )-&gt;Getvalue() * 0.01f);<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WCHAR sz[100];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StringCchPrintf( sz, 100, L"Puffiness: %0.2f", g_fModelPuffiness ); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_SampleUI.GetStatic( IDC_PUFF_STATIC )-&gt;SetText( sz );<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_pPuffiness-&gt;SetFloat( g_fModelPuffiness );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; }<br>更新消息处理<br>既然现在我们有对话框消息和用户交互, 那就会有传递给应用程序的消息需要被解析, 如果适用的话.那些代码会在DXUT提供的 MsgProc 回调函数中被处理. 在之前的指南里, 这段是空白因为没有消息需要被处理. 但是现在,我们要确保发送给资源管理程序和对话框的消息被适当地发送.<br>不需要专门的消息处理代码; 我们只需要对每个对话框调用MsgProcs来确保消息被处理了.这通过调用每个单独的类的相应的 MsgProc 函数来完成. 应该注意到这个函数提供了一个标记通报给框架，不需要更多的处理, 因此,可以退出.<br>&nbsp; &nbsp; LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; // Always allow dialog resource manager calls to handle global messages<br>&nbsp; &nbsp; &nbsp; &nbsp; // so GUI state is updated correctly<br>&nbsp; &nbsp; &nbsp; &nbsp; *pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );<br>&nbsp; &nbsp; &nbsp; &nbsp; if( *pbNoFurtherProcessing )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; if( g_D3DSettingsDlg.IsActive() )<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_D3DSettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; // Give the dialogs a chance to handle the message first<br>&nbsp; &nbsp; &nbsp; &nbsp; *pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );<br>&nbsp; &nbsp; &nbsp; &nbsp; if( *pbNoFurtherProcessing )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; *pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );<br>&nbsp; &nbsp; &nbsp; &nbsp; if( *pbNoFurtherProcessing )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; if( uMsg == WM_CHAR &amp;&amp; wParam == '1' )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DXUTToggleFullScreen();<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br>&nbsp; &nbsp; }<br>3D设置对话框<br>有一个专门的内置对话框用来控制D3DDevice的设置. DXUT提供的这个对话框就是CD3DSettingsDlg. 它的功能像一个自定义对话框,但是它会提供给用户所有的他们需要修改的设置选项.<br>&nbsp; &nbsp; CD3DSettingsDlg&nbsp; &nbsp; &nbsp; &nbsp; g_D3DSettingsDlg;&nbsp; &nbsp; &nbsp; // Device settings dialog<br>初始化就像其它对话框一样, 你可以调用初始化函数. 然而, 每次Direct3D 改变它的交换链或者设备,这个对话框必须被更新.因此, 它必须包含一个调用在OnD3D10CreateDevice 和OnD3D10ResizedSwapChain里, 相对应地命名, 来反映这些改变. 同样地,销毁对象的改变必须被通报, 因而, 需要在 OnD3D10DestroyDevice里调用.<br>&nbsp; &nbsp; g_D3DSettingsDlg.Init( &amp;g_DialogResourceManager );<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; V_RETURN( g_D3DSettingsDlg.OnD3D10CreateDevice( pd3dDevice ) );<br>&nbsp; &nbsp; V_RETURN( g_D3DSettingsDlg.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; g_D3DSettingsDlg.OnD3D10DestroyDevice();<br>在渲染的这一边, 因为对话框的出现可以被改变,它通过一个叫 IsActive()的标记来转换. 如果这个标记被设成false, 那么这个面板将不会被渲染.这个面板的改变是受上面说过的HUD对话框处理的. 标记The IDC_CHANGEDEVICE与HUD 控件相关, 就像上面提到的那样.<br>&nbsp; &nbsp; if( g_D3DSettingsDlg.IsActive() )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; g_D3DSettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam );<br>&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br>&nbsp; &nbsp; }<br>一旦这些初始步骤都完成了, 你就可以在你的程序中加入这个对话框. 试着编译这个指南并与更改设置的面板进行交互来观察它的效果. 真正的D3DDevice 或交换链的重构在DXUT内部完成.<br>文本渲染<br>一个程序不会有趣如果用户不知道干什么. 所以就DXUT包含了一个工具类用于在屏幕上绘制2D 文本, 用来给用户反馈. 这个类, CDXUTD3D10TextHelper, 允许你在屏幕的任意位置绘制一行行的文本, 并有简单的字符串输入. 开始之前, 我们要实例化这个类. 既然文本渲染与大多数初始化过程独立, 在这个指南里我们让大部分代码在RenderText10里.<br>&nbsp; &nbsp; CDXUTD3D10TextHelper txtHelper( g_pFont, g_pSprite, 15 );<br>初始化<br>我们传入的第一个参数是我们要绘制的字体. 字体的类型是D3DX提供的ID3DXFont. 要初始化这个字体, 你调用D3DX10CreateFont, 并且你要传入设备, 高度, 宽度, 重量, mip层次 (一般取 1), 斜体, 字符集, 精度, 质量, 倾斜度和家族, 字体名称, 还有你的对象的指针. 虽然它看起来像很多字符, 只有开始的4个和最后的2个真正有意义.<br>&nbsp; &nbsp; V_RETURN( D3DX10CreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L"Arial", &amp;g_pFont ) );<br>第2个参数需要我们初始化一个ID3DXSprite 类. 要做这个的话, 我们可以调用 D3DX10CreateSprite (notice the trend here?). 这个函数只需要设备和对象的指针做为参数.<br>&nbsp; &nbsp; // Initialize the sprite<br>&nbsp; &nbsp; V_RETURN( D3DX10CreateSprite( pd3dDevice, &amp;g_pSprite ) );<br>当然, 像其它对象一样, 字体和精灵在我们完成时必须被销毁. 这可以用常见的 SAFE_RELEASE 宏完成.<br>&nbsp; &nbsp; SAFE_RELEASE( g_pFont );<br>&nbsp; &nbsp; SAFE_RELEASE( g_pSprite );<br>渲染<br>在这个示例里包含的文本里有渲染的统计信息. 另外, 还有一个区域显示怎样用鼠标操作模型.<br>渲染必须在OnD3D10FrameRender里调用, 而且在这个指南里, 它是在帧渲染调用里调用RenderText10来完成的.<br>第一个区域一直在绘制, 因此, 它最先完成. 第一个文本渲染调用是Begin(). 它通知引擎我要开始输出文本到屏幕. 在那之后, 我们设置好&#8220;指针&#8221;的位置, 文本的颜色, 我们就准备绘制了.<br>输出一个字符串文本要调用DrawTextLine来完成. 你传入字符串, 它就会在当前位置输出. 它在文本书写的同时增加指针, 因此, 如果q包含了一个\n, 它会自动移动指针到下一行.<br>&nbsp; &nbsp; // Output statistics<br>&nbsp; &nbsp; txtHelper.Begin();<br>&nbsp; &nbsp; txtHelper.SetInsertionPos( 2, 0 );<br>&nbsp; &nbsp; txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 0.0f, 1.0f ) );<br>&nbsp; &nbsp; txtHelper.DrawTextLine( DXUTGetFrameStats() );<br>&nbsp; &nbsp; txtHelper.DrawTextLine( DXUTGetDeviceStats() );<br>还有另一个方法来输出文本, 就好似通常使用的printf. 你用特殊的字符来格式化字符串, 然后插入变量到字符串里. 这通过DrawFormattedTextLine来实现.<br>&nbsp; &nbsp; txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );<br>&nbsp; &nbsp; txtHelper.DrawFormattedTextLine( L"fTime: %0.1f&nbsp; sin(fTime): %0.4f", fTime, sin(fTime) );<br>既然帮助绘制用一种相似的方式, 所以不需要涵盖那部分代码了. 一定要注意你能在任何时候通过调用SetInsertionPos来重新设置指针的位置.<br>最后, 当你对文本输出满意后, 调用 End() 来通知引擎你完成了. <br>Feedback? Please provide us with your comments on this topic.<br>For more help, visit the DirectX Developer Center<br>&#169; 2005 Microsoft Corporation. All rights reserved. </div>
<img src ="http://www.cppblog.com/jack-wang/aggbug/70964.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jack-wang/" target="_blank">小王</a> 2009-01-02 03:36 <a href="http://www.cppblog.com/jack-wang/archive/2009/01/02/70964.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>