﻿<?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++博客-牵着老婆满街逛-随笔分类-C++</title><link>http://www.cppblog.com/tx7do/category/2349.html</link><description>危机感是一种强大前进的动力！&lt;/br&gt;
GMail/GTalk: yanglinbo#google.com;&lt;/br&gt;
MSN/Email: tx7do#yahoo.com.cn;&lt;/br&gt;
QQ: 3 0 3 3 9 6 9 2 0 .</description><language>zh-cn</language><lastBuildDate>Mon, 19 May 2008 12:39:47 GMT</lastBuildDate><pubDate>Mon, 19 May 2008 12:39:47 GMT</pubDate><ttl>60</ttl><item><title>小神之Newton物理引擎教程(一) Newton物理引擎教程</title><link>http://www.cppblog.com/tx7do/archive/2007/01/25/17982.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Thu, 25 Jan 2007 07:49:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2007/01/25/17982.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/17982.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2007/01/25/17982.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/17982.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/17982.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42.75pt; TEXT-INDENT: -42.75pt; mso-list: l1 level1 lfo1; tab-stops: list 42.75pt">
				<span lang="EN-US" style="FONT-SIZE: 14pt; mso-bidi-font-family: 宋体">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">第一节</font>
						</span>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 14pt; FONT-FAMILY: Arial">Getting started</span>
				<span lang="EN-US" style="FONT-SIZE: 14pt">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个例程将告诉你如何把</span>
						<span lang="EN-US">
								<font face="Times New Roman">newton</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">物理引擎和你的图形引擎结合起来。</span>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果你没有解过</span>
						<span lang="EN-US">
								<font face="Times New Roman">SDK</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">包，先解开包。</span>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">打开</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt">
						<font face="Times New Roman">Visual studio</font>
				</span>
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">找到包里的</span>
				<b>
						<span lang="EN-US" style="FONT-SIZE: 12pt">
								<font face="Times New Roman">Tutorials.dsw</font>
						</span>
				</b>
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">后双击。</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-weight: bold">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">选择子项目</span>
				<b>
						<span lang="EN-US" style="FONT-SIZE: 12pt">
								<font face="Times New Roman">Tutorial 1 getting started</font>
						</span>
				</b>
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">并使它活动起来。</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-weight: bold">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">选择</span>
				<b>
						<span lang="EN-US" style="FONT-SIZE: 12pt">
								<font face="Times New Roman">Tutorial.cpp</font>
						</span>
				</b>
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">文件并双击在编辑框中打开。</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-weight: bold">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">在文件的开始你将发现</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-weight: bold">
						<font face="Times New Roman">include</font>
				</span>
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">部分。</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-weight: bold">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">看下面几行（注意黑体）：</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-weight: bold">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<b>
								<i>
										<span lang="EN-US" style="FONT-SIZE: 12pt">
												<font face="Times New Roman">#include “newton.h”<br /></font>
										</span>
								</i>
						</b>
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">#include "tutorial.h"<br />#include "HiResTimer.h"<br />#include "RenderPrimitive.h"<br />#include "Newton.h"</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">找到文件主要函数。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先初始化图形引擎。在这个案例中我们已经把</span>
						<span lang="EN-US">
								<font face="Times New Roman">opengl</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的初始化压成一个简单的函数。它可以完成你的引擎中主要系统的初始化。</span>
				</font>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// Initialize opengl <br />InitOpenGl (argc, argv, "<city w:st="on"><place w:st="on">Newton</place></city>Getting Started", DrawScene, NULL, Keyboard);</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">接下来你将看到场景初始化的的相关调用。</font>
				</span>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// Create the physics scene. This represents your engine scene initialization<br />InitScene();</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">最后是</span>
						<span lang="EN-US">
								<font face="Times New Roman">opengl</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的主体循环调用，它描述的是你的引擎主循环。</span>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">现在找到函数</span>
						<b>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">InitScene</font>
								</span>
						</b>
				</font>
				<b>
						<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</span>
				</b>
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">物理引擎的初始化就在那里。</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-weight: bold">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">在这个例程中，我们将实现一个简单的物理场景：一个刚体球悬浮在真空中。</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-weight: bold">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-weight: bold">我们将看到：</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-weight: bold">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// Create the newton world<br />nWorld = NewtonCreate (NULL, NULL);</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span lang="EN-US">
								<font face="Times New Roman">//</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">译者注：实际上这之前还需要声明</span>
						<span lang="EN-US">
								<font face="Times New Roman">nWorld</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，以下许多地方类似</span>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">它将为</span>
						<span lang="EN-US">
								<font face="Times New Roman">nowton </font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">世界创建一个句柄，并初始化所有内部结构。这里我们先忽视两个参数，在下个例程中我们将对之详细说明。我们保持这个指向</span>
						<span lang="EN-US">
								<font face="Times New Roman">nowton</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">世界的句柄为全程变量。</span>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但是它（</span>
						<span lang="EN-US">
								<font face="Times New Roman">nowton</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">世界）不可能脱离</span>
						<span lang="EN-US">
								<font face="Times New Roman">opengl</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">循环，所以我们要设定一个事件去终止</span>
						<span lang="EN-US">
								<font face="Times New Roman">nowton</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">世界和我们已经分配的所有资源。这就是</span>
						<span lang="EN-US" style="FONT-SIZE: 12pt">
								<font face="Times New Roman">onexit (Cleanup)</font>
						</span>
				</font>
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所要做的。</span>
				<span lang="EN-US" style="FONT-SIZE: 12pt">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接下来我们要创建一个刚体，在这之前我们要创建它的几何碰撞。（刚体每时每刻都必须有几何碰撞）</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">所以我们根据图形箱子大小去创建一个碰撞。</font>
				</span>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// Create the collision shape<br />collision = NewtonCreateBox (nWorld, box.m_x * <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="2" unitname="F">2.0f</chmetcnv>, box.m_y * <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="2" unitname="F">2.0f</chmetcnv>, box.m_z * <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="2" unitname="F">2.0f</chmetcnv>, NULL); </font>
								</span>
						</i>
				</p>
		</div>
		<p class="western" style="MARGIN: auto 0cm 0pt">
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第一个参数是</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt">
						<font face="Times New Roman">Newton world</font>
				</span>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，接下来的是箱子大小，最后一个参数是用来设置从源刚体而得到的几何碰撞中偏转转换矩阵。当使用</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt">
						<font face="Times New Roman">Null</font>
				</span>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时，这个箱子会被源物体替代。现在我们创建刚体并保存为一个全局变量。</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt">
						<p> </p>
				</span>
		</p>
		<p>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// Create the ridid body<br />ribidBodyBox = NewtonCreateBody (nWorld, collision);</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当你使用完碰撞对象后你要释放它，碰撞对象在</span>
						<span lang="EN-US">
								<font face="Times New Roman">newton</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里是唯一一个使用</span>
						<span lang="EN-US">
								<font face="Times New Roman">reference</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">数的对象，这是有必要的因为其他刚体可以分享几何碰撞。取个例子来说，你可以创建很多个同样大小的箱子，你可以使用同一个几何碰撞。</span>
				</font>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// Get rid of the collision<br />NewtonReleaseCollision (nWorld, collision); 
<p> </p></font>
								</span>
						</i>
				</p>
				<p>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当</span>
						<span lang="EN-US">
								<font face="Times New Roman">newton</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">创建一个刚体，质量设置为无限以保持这个刚体呈静态。我们需要去告诉</span>
						<span lang="EN-US">
								<font face="Times New Roman">newton</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个物体是动态的，就调用下面这个</span>
				</font>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// set the body mass and inertia<br />NewtonBodySetMassMatrix (ribidBodyBox, <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1.0f</chmetcnv>, <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1.0f</chmetcnv>, <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1.0f</chmetcnv>, <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1.0f</chmetcnv>);</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">别去考虑质量与惯性，他们将会在例程</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
								<font face="Times New Roman">the Dealing with Mass and Inertia</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">中讨论。</span>
						<span lang="EN-US" style="mso-bidi-font-size: 10.5pt">
								<p> </p>
						</span>
				</font>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们同样需要在这个世界中物体的位置。</span>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<span lang="EN-US" style="FONT-SIZE: 12pt">
								<font face="Times New Roman">/<i>/ Set the transformation matrix</i></font>
						</span>
						<i>
								<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置变换矩阵</span>
						</i>
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<br />
										<font face="Times New Roman">dMatrix matrix (box.GetMatrix());<br />matrix.m_posit.m_x = <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="0" unitname="F">0.0f</chmetcnv>;<br />matrix.m_posit.m_y = <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1.0f</chmetcnv>;<br />matrix.m_posit.m_z = <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="0" unitname="F">0.0f</chmetcnv>;<br />NewtonBodySetMatrix (ribidBodyBox, &amp;matrix[0][0]);</font>
								</span>
						</i>
				</p>
		</div>
		<p class="western" style="MARGIN: auto 0cm 0pt">
				<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里没有应力和应变应用在这个物体上，我们仅仅是应用了最初的角速度</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="2">。</font>
				</span>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 0cm 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// Animate the body by setting the angular velocity</font>
								</span>
						</i>
						<i>
								<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置角速度使物体动起来</span>
						</i>
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<br />
										<font face="Times New Roman">dVector omega (<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1.0f</chmetcnv>, <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1.0f</chmetcnv>, <chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1.0f</chmetcnv>);<br />NewtonBodySetOmega (ribidBodyBox, &amp;omega[0]);</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span lang="EN-US">
								<font face="Times New Roman">//</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里的</span>
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">NewtonBodySetOmega</font>
								</span>
						</i>
				</font>
				<i>
						<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的</span>
				</i>
				<i>
						<span lang="EN-US" style="FONT-SIZE: 12pt">
								<font face="Times New Roman">Omega</font>
						</span>
				</i>
				<i>
						<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其实是小写希腊字母最后一个——</span>
				</i>
				<i>
						<span lang="EN-US" style="FONT-SIZE: 12pt">
								<font face="Times New Roman">ω</font>
						</span>
				</i>
				<i>
						<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，即物理中的角速度。</span>
				</i>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">这是所有初始化，现在是主要的仿真循环。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">每一帧在</span>
						<span lang="EN-US">
								<font face="Times New Roman">OPENGL</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或者你的引擎中都将在主要仿真循环中创建一个回调。在这个例程中，它是函数</span>
						<b>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">DrawScene</font>
								</span>
						</b>
				</font>
				<b>
						<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span>
				</b>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">注意我们需要取得从最后一次更新到现在的时间。它使用下面这个函数。</font>
				</span>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// get the time step<br />timeStep = timer.GetElapsedSeconds();</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接下来，我们调用</span>
						<span lang="EN-US">
								<font face="Times New Roman">NewtonUpdate</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来用时间量推动这个世界。</span>
				</font>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// update the <place w:st="on"><city w:st="on">Newton</city></place> physics world<br />NewtonUpdate (nWorld, timeStep);</font>
								</span>
						</i>
				</p>
		</div>
		<p class="western" style="MARGIN: auto 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="2">现在我们需要找到在世界更新的过程中位置改变的物体变换矩阵，在这个例子中我们只有一个物体。</font>
				</span>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// get the matrix from the rigid body<br />dMatrix matrix;<br />NewtonBodyGetMatrix(ribidBodyBox, &amp;matrix[0][0]);</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">现在我们需要去应用这些转换到图形物体中。</font>
				</span>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// Set the matrix of the visual body<br />box.SetMatrix (matrix);</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">最后我们渲染场景。</font>
				</span>
		</p>
		<div style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 1pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 1pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 1pt; BORDER-LEFT: black 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: black 1pt solid; mso-element: para-border-div; mso-border-alt: solid black .75pt">
				<p class="western" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 0cm; MARGIN: auto 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid black .75pt; mso-padding-alt: 1.0pt 1.0pt 1.0pt 1.0pt">
						<i>
								<span lang="EN-US" style="FONT-SIZE: 12pt">
										<font face="Times New Roman">// Render the object<br />glPushMatrix();<br />box.Render();<br />glPopMatrix();</font>
								</span>
						</i>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">这些都包含在主循环中。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">最后的事情就是终止应用程序，我们用点击关闭窗体按钮或者按</span>
						<span lang="EN-US">
								<font face="Times New Roman">ESCAPE</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">键来终止。每个案例都是用</span>
						<span lang="EN-US">
								<font face="Times New Roman">exit(0)</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个函数将会调用所有终止程序并次序颠倒的运行。在我们的案例中我们仅仅是使用</span>
						<span lang="EN-US">
								<font face="Times New Roman">cleanup</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数去销毁</span>
						<span lang="EN-US">
								<font face="Times New Roman">the Newton world</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<font size="3">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">操作这个例程用</span>
						<span lang="EN-US">
								<font face="Times New Roman">WSAD</font>
						</span>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">键。</span>
				</font>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">改变运动趋势按鼠标并移动鼠标。</font>
				</span>
		</p>
		<div style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; PADDING-BOTTOM: 1pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-bottom-alt: solid windowtext .75pt">
				<p class="MsoNormal" style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-padding-alt: 0cm 0cm 1.0pt 0cm; mso-border-bottom-alt: solid windowtext .75pt">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
								<font size="3">例程结束。</font>
						</span>
				</p>
		</div>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">从这个例程中我们可以看出，物理引擎的基本操作步骤。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">
										<font size="3">1、</font>
										<span style="FONT: 7pt 'Times New Roman'">  </span>
								</font>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">初始化物理引擎。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">
										<font size="3">2、</font>
										<span style="FONT: 7pt 'Times New Roman'">  </span>
								</font>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">取得物体的几何碰撞。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">
										<font size="3">3、</font>
										<span style="FONT: 7pt 'Times New Roman'">  </span>
								</font>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">根据几何碰撞创建刚体。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">
										<font size="3">4、</font>
										<span style="FONT: 7pt 'Times New Roman'">  </span>
								</font>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">释放几何碰撞（很多人会忘记，但很重要）</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">
										<font size="3">5、</font>
										<span style="FONT: 7pt 'Times New Roman'">  </span>
								</font>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">设置变换矩阵。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">
										<font size="3">6、</font>
										<span style="FONT: 7pt 'Times New Roman'">  </span>
								</font>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">更新物理引擎。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">
										<font size="3">7、</font>
										<span style="FONT: 7pt 'Times New Roman'">  </span>
								</font>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">取得变换矩阵。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">
										<font size="3">8、</font>
										<span style="FONT: 7pt 'Times New Roman'">  </span>
								</font>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">根据取得的变换矩阵设置绘制物体当前状态。</font>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">
								<font face="Times New Roman">
										<font size="3">9、</font>
										<span style="FONT: 7pt 'Times New Roman'">  </span>
								</font>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
						<font size="3">释放物理引擎。</font>
				</span>
		</p>
<img src ="http://www.cppblog.com/tx7do/aggbug/17982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2007-01-25 15:49 <a href="http://www.cppblog.com/tx7do/archive/2007/01/25/17982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>分析Linux操作系统内核各种方法浅谈</title><link>http://www.cppblog.com/tx7do/archive/2007/01/07/17408.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sun, 07 Jan 2007 14:34:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2007/01/07/17408.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/17408.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2007/01/07/17408.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/17408.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/17408.html</trackback:ping><description><![CDATA[ 
<p style="TEXT-INDENT: 2em">Linux的最大的好处之一就是它的源码公开。同时，公开的核心源码也吸引着无数的电脑爱好者和程序员；他们把解读和分析Linux的核心源码作为自己的最大兴趣，把修改Linux源码和改造Linux系统作为自己对计算机技术追求的最大目标。 </p><p style="TEXT-INDENT: 2em">Linux内核源码是很具吸引力的，特别是当你弄懂了一个分析了好久都没搞懂的问题；或者是被你修改过了的内核，顺利通过编译，一切运行正常的时候。那种成就感真是油然而生！而且，对内核的分析，除了出自对技术的狂热追求之外，这种令人生畏的劳动所带来的回报也是非常令人着迷的，这也正是它拥有众多追随者的主要原因： </p><p style="TEXT-INDENT: 2em">首先，你可以从中学到很多的计算机的底层知识，如后面将讲到的系统的引导和硬件提供的中断机制等；其它，象虚拟存储的实现机制，多任务机制，系统保护机制等等，这些都是非都源码不能体会的。 </p><p style="TEXT-INDENT: 2em">同时，你还将从操作系统的整体结构中，体会整体设计在软件设计中的份量和作用，以及一些宏观设计的方法和技巧：Linux的内核为上层应用提供一个与具体硬件不相关的平台；同时在内核内部，它又把代码分为与体系结构和硬件相关的部分，和可移植的部分；再例如，Linux虽然不是微内核的，但他把大部分的设备驱动处理成相对独立的内核模块，这样减小了内核运行的开销，增强了内核代码的模块独立性。 </p><p style="TEXT-INDENT: 2em">而且你还能从对内核源码的分析中，体会到它在解决某个具体细节问题时，方法的巧妙：如后面将分析到了的Linux通过Botoom_half机制来加快系统对中断的处理。 </p><p style="TEXT-INDENT: 2em">最重要的是：在源码的分析过程中，你将会被一点一点地、潜移默化地专业化。一个专业的程序员，总是把代码的清晰性，兼容性，可移植性放在很重要的位置。他们总是通过定义大量的宏，来增强代码的清晰度和可读性，而又不增加编译后的代码长度和代码的运行效率；他们总是在编码的同时，就考虑到了以后的代码维护和升级。 甚至，只要分析百分之一的代码后，你就会深刻地体会到，什么样的代码才是一个专业的程序员写的，什么样的代码是一个业余爱好者写的。而这一点是任何没有真正分析过标准代码的人都无法体会到的。 </p><p style="TEXT-INDENT: 2em">然而，由于内核代码的冗长，和内核体系结构的庞杂，所以分析内核也是一个很艰难，很需要毅力的事；在缺乏指导和交流的情况下，尤其如此。只有方法正确，才能事半功倍。正是基于这种考虑，作者希望通过此文能给大家一些借鉴和启迪。 </p><p style="TEXT-INDENT: 2em">由于本人所进行的分析都是基于2.2.5版本的内核；所以，如果没有特别说明，以下分析都是基于i386单处理器的2.2.5版本的Linux内核。所有源文件均是相对于目录/usr/src/linux的。 </p><p style="TEXT-INDENT: 2em"><b>方法之一：从何入手 </b></p><p style="TEXT-INDENT: 2em">要分析Linux内核源码，首先必须找到各个模块的位置，也即要弄懂源码的文件组织形式。虽然对于有经验的高手而言，这个不是很难；但对于很多初级的Linux爱好者，和那些对源码分析很有兴趣但接触不多的人来说，这还是很有必要的。 </p><p style="TEXT-INDENT: 2em">1、Linux核心源程序通常都安装在/usr/src/linux下，而且它有一个非常简单的编号约定：任何偶数的核心（的二个数为偶数，例如2.0.30）都是一个稳定地发行的核心，而任何奇数的核心（例如2.1.42）都是一个开发中的核心。 </p><p style="TEXT-INDENT: 2em">2、核心源程序的文件按树形结构进行组织，在源程序树的最上层，即目录/usr/src/linux下有这样一些目录和文件： </p><p style="TEXT-INDENT: 2em">● COPYING: GPL版权申明。对具有GPL版权的源代码改动而形成的程序，或使用GPL工具产生的程序，具有使用GPL发表的义务，如公开源代码。 </p><p style="TEXT-INDENT: 2em">● CREDITS: 光荣榜。对Linux做出过很大贡献的一些人的信息。 </p><p style="TEXT-INDENT: 2em">● MAINTAINERS: 维护人员列表，对当前版本的内核各部分都有谁负责。 </p><p style="TEXT-INDENT: 2em">● Makefile: 第一个Makefile文件。用来组织内核的各模块，记录了个模块间的相互这间的联系和依托关系，编译时使用。仔细阅读各子目录下的Makefile文件对弄清各个文件这间的联系和依托关系很有帮助。 </p><p style="TEXT-INDENT: 2em">● ReadMe: 核心及其编译配置方法简单介绍。 </p><p style="TEXT-INDENT: 2em">● Rules.make: 各种Makefilemake所使用的一些共同规则。 </p><p style="TEXT-INDENT: 2em">● REPORTING-BUGS:有关报告Bug 的一些内容。 </p><p style="TEXT-INDENT: 2em">● Arch/ ：arch子目录包括了所有和体系结构相关的核心代码。它的每一个子目录都代表一种支持的体系结构，例如i386就是关于intel cpu及与之相兼容体系结构的子目录。PC机一般都基于此目录。 </p><p style="TEXT-INDENT: 2em">● Include/: include子目录包括编译核心所需要的大部分头文件。与平台无关的头文件在 include/linux子目录下，与 intel cpu相关的头文件在include/asm-i386子目录下,而include/scsi目录则是有关scsi设备的头文件目录。 </p><p style="TEXT-INDENT: 2em">● Init/： 这个目录包含核心的初始化代码(注：不是系统的引导代码)，包含两个文件main.c和Version.c，这是研究核心如何工作的好的起点之一。 <br /><br /></p><p></p><p style="TEXT-INDENT: 2em">● Mm/：这个目录包括所有独立于 cpu 体系结构的内存管理代码，如页式存储管理内存的分配和释放等。而和体系结构相关的内存管理代码则位于arch/*/mm/，例如arch/i386/mm/Fault.c。 </p><p style="TEXT-INDENT: 2em">● Kernel/：主要的核心代码，此目录下的文件实现了大多数linux系统的内核函数，其中最重要的文件当属sched.c。同样，和体系结构相关的代码在arch/*/kernel中。 </p><p style="TEXT-INDENT: 2em">● Drivers/： 放置系统所有的设备驱动程序。每种驱动程序又各占用一个子目录：如，/block 下为块设备驱动程序，比如ide（ide.c）。如果你希望查看所有可能包含文件系统的设备是如何初始化的，你可以看drivers/block/genhd.c中的device_setup()。它不仅初始化硬盘，也初始化网络，因为安装nfs文件系统的时候需要网络。 </p><p style="TEXT-INDENT: 2em">● Documentation/: 文档目录,没有内核代码，只是一套有用的文档，可惜都是English的，看看应该有用的哦。 </p><p style="TEXT-INDENT: 2em">● Fs/: 所有的文件系统代码和各种类型的文件操作代码，它的每一个子目录支持一个文件系统, 例如fat和ext2。 </p><p style="TEXT-INDENT: 2em">● Ipc/: 这个目录包含核心的进程间通讯的代码。 </p><p style="TEXT-INDENT: 2em">● Lib/: 放置核心的库代码。 </p><p style="TEXT-INDENT: 2em">● Net/: 核心与网络相关的代码。 </p><p style="TEXT-INDENT: 2em">● Modules/: 模块文件目录，是个空目录，用于存放编译时产生的模块目标文件。 </p><p style="TEXT-INDENT: 2em">● Scripts/: 描述文件，脚本，用于对核心的配置。 </p><p style="TEXT-INDENT: 2em">一般，在每个子目录下，都有一个 Makefile 和一个Readme 文件，仔细阅读这两个文件，对内核源码的理解很有用。 </p><p style="TEXT-INDENT: 2em">对Linux内核源码的分析，有几个很好的入口点：一个就是系统的引导和初始化，即从机器加电到系统核心的运行；另外一个就是系统调用，系统调用是用户程序或操作调用核心所提供的功能的接口。对于那些对硬件比较熟悉的爱好者，从系统的引导入手进行分析，可能来的容易一些；而从系统调用下口，则可能更合适于那些在dos或Uinx、Linux下有过C编程经验的高手。这两点，在后面还将介绍到。 </p><p style="TEXT-INDENT: 2em"><b>方法之二：以程序流程为线索，一线串珠</b></p><p style="TEXT-INDENT: 2em">从表面上看，Linux的源码就象一团扎乱无章的乱麻，其实它是一个组织得有条有理的蛛网。要把整个结构分析清楚，除了找出线头，还得理顺各个部分之间的关系，有条不紊的一点一点的分析。 </p><p style="TEXT-INDENT: 2em">所谓以程序流程为线索、一线串珠，就是指根据程序的执行流程，把程序执行过程所涉及到的代码分析清楚。这种方法最典型的应用有两个：一是系统的初始化过程；二是应用程序的执行流程：从程序的装载，到运行，一直到程序的退出。 </p><p style="TEXT-INDENT: 2em">为了简便起见，遵从循序渐进的原理，现就系统的初始化过程来具体的介绍这种方法。系统的初始化流程包括：系统引导，实模式下的初始化，保护模式下的初始化共三个部分。下面将一一介绍。 </p><p style="TEXT-INDENT: 2em">Linux系统的常见引导方式有两种：Lilo引导和Loadin引导；同时linux内核也自带了一个bootsect-loader。由于它只能实现linux的引导，不像前两个那样具有很大的灵活性（lilo可实现多重引导、loadin可在dos下引导linux）,所以在普通应用场合实际上很少使用bootsect-loader。当然，bootsect-loader也具有它自己的优点：短小没有多余的代码、附带在内核源码中、是内核源码的有机组成部分，等等。 </p><p style="TEXT-INDENT: 2em">bootsect-loader在内和源码中对应的程序是 /Arch/i386/boot/bootsect.S 。下面将主要是针对此文件进行的分析。 </p><p style="TEXT-INDENT: 2em">几个相关文件： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />　　
　　&lt;1&gt; /Arch/i386/boot/bootsect.S 
　　
　　&lt;2&gt; /include/linux/config.h 
　　
　　&lt;3&gt; /include/asm/boot.h 
　　
　　&lt;4&gt; /include/linux/autoconf.h/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">　　 </p><p style="TEXT-INDENT: 2em">引导过程分析： </p><p style="TEXT-INDENT: 2em">对于Intel x86 PC , 开启电源后, 机器就会开始执行ROM BIOS的一系列系统测试动作，包括检查RAM，keyboard，显示器，软硬磁盘等等。执行完bios的系统测试之后，紧接着控制权会转移给ROM中的启动程序(ROM bootstrap routine)；这个程序会将磁盘上的第0轨第0扇区（叫boot sector或MBR ，系统的引导程序就放在此处）读入内存中，并放到自0x07C0:0x0000开始的512个字节处；然后处理机将跳到此处开始执行这一引导程序；也即装入MBR中的引导程序后， CS:IP = 0x07C0:0x0000 。加电后处理机运行在与8086相兼容的实模式下。 </p><p style="TEXT-INDENT: 2em">如果要用bootsect-loader进行系统引导，则必须把bootsect.S编译连接后对应的二进制代码置于MBR； 当ROM BIOS 把bootsect.S编译连接后对应的二进制代码装入内存后，机器的控制权就完全转交给bootsect； 也就是说，bootsect将是第一个被读入内存中并执行的程序。 </p></center><img src ="http://www.cppblog.com/tx7do/aggbug/17408.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2007-01-07 22:34 <a href="http://www.cppblog.com/tx7do/archive/2007/01/07/17408.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux操作系统中控制台下的截图攻略</title><link>http://www.cppblog.com/tx7do/archive/2007/01/07/17409.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sun, 07 Jan 2007 14:34:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2007/01/07/17409.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/17409.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2007/01/07/17409.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/17409.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/17409.html</trackback:ping><description><![CDATA[ 
<p style="TEXT-INDENT: 2em">Linux越来越受到人们的关注，使用的人也越来越多。Linux用户可以通过网络交流使用经验、介绍好的软件。在交流中，人们经常互相在网上贴张屏幕截图，使得相互之间的交流变得更加直接、容易。这里我介绍一些Linux下的抓图软件和使用方法，希望能让大家更灵活地应用Linux。 </p><p style="TEXT-INDENT: 2em"><b>控制台下的截图</b></p><p style="TEXT-INDENT: 2em">1.在控制台(Console)下如果只想要获得文字的输出，例如命令的帮助信息，可以直接使用管道命令，将输出内容保存到指定的文件当中。 </p><p style="TEXT-INDENT: 2em">2.可以用setterm程序来获得控制台下的屏幕截图。命令格式为：setterm -dump 1 </p><p style="TEXT-INDENT: 2em">上面命令中，1指第一个虚拟控制台，如要获得第二个虚拟控制台的内容，应改为2，依此类推。关于setterm的具体用法可以参考它的man信息。 </p><p style="TEXT-INDENT: 2em">3.使用控制台下的屏幕截图软件snapscreenshot，下载地址为 http://bisqwit.iki.fi/source/snapscreenshot.html。使用这个软件可以获取控制台屏幕，并输出一个tga格式的图像文件。如果想获得其它格式的图像文件，可以用图像转换程序(如convert)将它转换成其它格式的文件。截图效果请见图1。 </p><p style="TEXT-INDENT: 2em"></p><center><img style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; BORDER-BOTTOM: black 1px solid" src="http://linux.ccidnet.com/col/attachment/2006/12/961441.gif" /></center><p style="TEXT-INDENT: 2em"></p><center>图1 用snapscreenshot在控制台抓取的图片 </center><p style="TEXT-INDENT: 2em">snapscreenshot的安装与卸载： </p><p style="TEXT-INDENT: 2em">◆安装 先将下载的软件包解开，然后进入这个目录，执行以下命令即可： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />#./configure； 
    #make install/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">◆卸载 </p><p style="TEXT-INDENT: 2em">#make uninstall </p><p style="TEXT-INDENT: 2em">◆使用方法 </p><p style="TEXT-INDENT: 2em">如果想获得帮助使用下面命令： </p><p style="TEXT-INDENT: 2em">#snapscreenshot --help </p><p style="TEXT-INDENT: 2em">截取图像可以使用如下命令： </p><p style="TEXT-INDENT: 2em">#snapscreenshot &gt;snap.tga </p><p style="TEXT-INDENT: 2em">上面代码表示按默认方式截取图片。 </p><p style="TEXT-INDENT: 2em">#snapscreenshot -c6 -x3 &gt;snap.tga </p><p style="TEXT-INDENT: 2em">上面这个命令表明自己指定参数来获得图片。 </p><p style="TEXT-INDENT: 2em">#./examplerun </p><p style="TEXT-INDENT: 2em">上面这个命令表示用本软件自带的脚本来获得图片。 </p><p style="TEXT-INDENT: 2em">如果想直接得到自己想要的图像格式，可以结合管道命令来使用，例如： #snapscreenshot|tgatopnm|pnmtojpeg&gt;myscreen.jpeg </p><p style="TEXT-INDENT: 2em">关于snapscreenshot的详细情况请参阅帮助信息及readme文件。 <br /></p><p style="TEXT-INDENT: 2em"><b>X-Window环境下截图 </b></p><p style="TEXT-INDENT: 2em">1.用X-Window中的截图工具 xwd与xwud是X-Window中自带的截图工具。xwd是一个非常传统的屏幕截图软件，它可以截取程序窗口和全屏图像。xwud是X11图形工具客户程序，可以用它来显示由xwd程序创建的图形文件。这两个程序包含在X-Window的标准发布版中。截取图像的方法如下: #xwd &gt; myscreen.xwd 查看图像使用如下命令： #xwud -in myscreen.xwd 实际使用中，可以用xwd结合其它图形转换程序直接获得想要的输出文件。例如： xwd -frame|xwdtopnm|pnmtojpeg&gt;myscreen.jpeg 如果直接写成script,则使用更加方便。例如我的脚本myscreen的文件内容为： #/bin/bash sleep 5 xwd -screen -root|xwdtopnm|pnmtopng&gt; myscreen.png </p><p style="TEXT-INDENT: 2em">2.用GNOME中的软件截图 </p><p style="TEXT-INDENT: 2em">在GNOME 1.4中的选单里，有小程序→公用程序→ScreenShooter。这个程序非常好用,可以对整个桌面和单个窗口和桌面区域进行截图，图片默认保存在你登录的目录下。例如用root登录，图片就保存在/root下,保存格式为jpg。但是，在Red Hat 8.0的GNOME选单中这个程序消失了，不过可以直接运行gnome-panel-screenshot进行截图。 </p><p style="TEXT-INDENT: 2em">3.用KDE中的软件来截图 </p><p style="TEXT-INDENT: 2em"></p><center><img style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; BORDER-BOTTOM: black 1px solid" src="http://www.xxlinux.com/linux/d/file/article/accidence/technique/2006-12-20/25c335529cbe01a8cc6ef9af76bfb116.gif" /></center><p style="TEXT-INDENT: 2em"></p><center>图2 Ksnapshot软件的界面 </center><p style="TEXT-INDENT: 2em">在KDE中包含了一个很好用的截图软件Ksnapshot。这个软件的使用比较直观，其界面如图2。只要在“Delay”框里填上延迟时间，在“Filename”栏里填上要保存的文件名和路径，然后用鼠标点“Grab”按钮就可以进行抓图了。 </p><p style="TEXT-INDENT: 2em">点击“Grab”按钮后，Ksnapshot软件的窗口自动最小化到任务栏，同时鼠标变成“十”字状。这时移动鼠标到其它运行着的程序窗口点一下，就会抓取这个程序的窗口图像；如果是在桌面空白的地方点击，则会抓取到整个屏幕的图像。抓完图后，Ksnapshot的窗口又会弹出来，这时点击“保存（Save）”就将抓取的图像保存到指定位置。 </p><p style="TEXT-INDENT: 2em">4.使用快捷键 </p><p style="TEXT-INDENT: 2em">在Red Hat 8.0的默认配置下，“Alt+PrintScreen”为窗口截图，“PrintScreen”为桌面截图。 </p><p style="TEXT-INDENT: 2em"><b>使用其它软件截图 </b></p><p style="TEXT-INDENT: 2em">1.ImageMagick </p><p style="TEXT-INDENT: 2em">ImageMagick是一个通过命令行执行的图像处理程序软件包，提供了一个完整的抓图、显示、简单编辑处理的解决方案。其中display可以显示图片和进行简单的图像编辑处理，如缩放、转换质量、绘图、简单虑镜等；convert用来转换图像格式；import可以用来屏幕抓图。当使用import程序进行抓图时，可以将图片直接保存成想要的格式。 </p><p style="TEXT-INDENT: 2em">抓图方法如下： </p><p style="TEXT-INDENT: 2em">#import -window root myscreen.jpeg </p><p style="TEXT-INDENT: 2em">上述命令表示捕捉全屏。 </p><p style="TEXT-INDENT: 2em">#import mywindows.jpeg </p><p style="TEXT-INDENT: 2em">上面这个命令是捕捉窗口，这时光标会变成“十”状，在某个窗口按下去这个窗口内容就被存入文件。详细情况请看man信息。 </p><p style="TEXT-INDENT: 2em">2.GIMP </p><p style="TEXT-INDENT: 2em"></p><center><img style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; BORDER-BOTTOM: black 1px solid" src="http://www.xxlinux.com/linux/d/file/article/accidence/technique/2006-12-20/0f75f291c183c4397d07ae4007249b7f.gif" /></center><p style="TEXT-INDENT: 2em">ImageMagick这个软件包对于一般的图像处理来说已经足够了，如果你还需要一个功能更加强大的软件，那就用GIMP。GIMP也是一个自由软件，它几乎可以和Photoshop相媲美，被认为是Linux下的Photoshop。 </p><p style="TEXT-INDENT: 2em">要用GIMP截取屏幕图像，可做如下操作：文件（File）→获取（ Acquire）→ Screen Shot…… 。然后在弹出来的窗口中选择“single window”，就可以抓取程序窗口图像；选择“whole windows”抓取全屏图像。图3为使用GIMP抓的图。 </p><p style="TEXT-INDENT: 2em">用GIMP截取出来的图像存什么格式都可以，并且可以马上进行处理，获得自己满意的效果。</p></center><img src ="http://www.cppblog.com/tx7do/aggbug/17409.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2007-01-07 22:34 <a href="http://www.cppblog.com/tx7do/archive/2007/01/07/17409.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>i++,i--的前置,后置++i,--i的详细解释</title><link>http://www.cppblog.com/tx7do/archive/2007/01/07/17407.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sun, 07 Jan 2007 14:06:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2007/01/07/17407.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/17407.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2007/01/07/17407.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/17407.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/17407.html</trackback:ping><description><![CDATA[ 对i++,i--,++i,--i的易解,在此举一例子详解: 
<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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">main( ) <br /><img id="Codehighlighter1_9_326_Open_Image" onclick="this.style.display='none'; Codehighlighter1_9_326_Open_Text.style.display='none'; Codehighlighter1_9_326_Closed_Image.style.display='inline'; Codehighlighter1_9_326_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_9_326_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_9_326_Closed_Text.style.display='none'; Codehighlighter1_9_326_Open_Image.style.display='inline'; Codehighlighter1_9_326_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_9_326_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 src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_9_326_Open_Text"><span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> x,y,z; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;z</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">++-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img id="Codehighlighter1_74_118_Open_Image" onclick="this.style.display='none'; Codehighlighter1_74_118_Open_Text.style.display='none'; Codehighlighter1_74_118_Closed_Image.style.display='inline'; Codehighlighter1_74_118_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_74_118_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_74_118_Closed_Text.style.display='none'; Codehighlighter1_74_118_Open_Image.style.display='inline'; Codehighlighter1_74_118_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\t%d\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,x,y); </span><span id="Codehighlighter1_74_118_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_74_118_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">x=3,y=1,后置++,先把x赋值给y,再做运算,而x的值无论是前还是后置都加1</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />y</span><span style="COLOR: #000000">=++</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img id="Codehighlighter1_156_203_Open_Image" onclick="this.style.display='none'; Codehighlighter1_156_203_Open_Text.style.display='none'; Codehighlighter1_156_203_Closed_Image.style.display='inline'; Codehighlighter1_156_203_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_156_203_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_156_203_Closed_Text.style.display='none'; Codehighlighter1_156_203_Open_Image.style.display='inline'; Codehighlighter1_156_203_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\t%d\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,x,y);</span><span id="Codehighlighter1_156_203_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_156_203_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">x=4,y=3,前置++,先把x加1后赋值给y,然后做运算(此行x初值是上行的终值=3)</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">z</span><span style="COLOR: #000000">--+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img id="Codehighlighter1_242_258_Open_Image" onclick="this.style.display='none'; Codehighlighter1_242_258_Open_Text.style.display='none'; Codehighlighter1_242_258_Closed_Image.style.display='inline'; Codehighlighter1_242_258_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_242_258_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_242_258_Closed_Text.style.display='none'; Codehighlighter1_242_258_Open_Image.style.display='inline'; Codehighlighter1_242_258_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\t%d\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,z,y); </span><span id="Codehighlighter1_242_258_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_242_258_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">z=2,y=4,同上理可知</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />y</span><span style="COLOR: #000000">=--</span><span style="COLOR: #000000">z</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img id="Codehighlighter1_297_312_Open_Image" onclick="this.style.display='none'; Codehighlighter1_297_312_Open_Text.style.display='none'; Codehighlighter1_297_312_Closed_Image.style.display='inline'; Codehighlighter1_297_312_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_297_312_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_297_312_Closed_Text.style.display='none'; Codehighlighter1_297_312_Open_Image.style.display='inline'; Codehighlighter1_297_312_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\t%d\t</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,z,y); </span><span id="Codehighlighter1_297_312_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_297_312_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">z=1,y=2,同理可证</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />getch(); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"> </span></div><img src ="http://www.cppblog.com/tx7do/aggbug/17407.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2007-01-07 22:06 <a href="http://www.cppblog.com/tx7do/archive/2007/01/07/17407.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Debian/Ubuntu Linux下内核编程者必备</title><link>http://www.cppblog.com/tx7do/archive/2007/01/07/17406.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sun, 07 Jan 2007 13:56:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2007/01/07/17406.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/17406.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2007/01/07/17406.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/17406.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/17406.html</trackback:ping><description><![CDATA[ 
<p style="TEXT-INDENT: 2em">如果你想要升级你的Debian/Ubuntu Linux内核，或者你希望为内核开发新的模块，或者您要为某个硬件写新的驱动程序……这一切都涉及到Debian/Ubuntu Linux内核编程。 </p><p style="TEXT-INDENT: 2em">作为一个内核编程者，有那么几个软件是你必须要有的，看作是你进行内核编程的几件法宝吧，下面我一一列举出来： </p><p style="TEXT-INDENT: 2em"><b>1、gcc</b></p><p style="TEXT-INDENT: 2em">大名鼎鼎的gcc我想没有人不知道的吧？它是任何编程者必然要先安装的一个武器了。不过一般如果你是安装的Debian系统，应该已经默认安装了的。要是Ubuntu你就安装一下吧，安装方法嘛，就是输入： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />apt-get install gcc/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em"><b>2、make</b></p><p style="TEXT-INDENT: 2em">如果你实实在在地写过有用的程序，你一定输入过make clean、make、make install等命令的，make是一个源代码维护工具，它能自动检测出需要重新编译的源文件并根据你设定的编译规则去重新编译程序。这里也不多说，如果不了解的朋友就google一下吧。不过一般如果你是安装的Debian系统，应该已经默认安装了的。要是Ubuntu你就安装一下吧，安装方法一样，输入： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />apt-get install make/PRE&gt;</pre></td></tr></tbody></table></center><p style="TEXT-INDENT: 2em"><b>3、kernel-source</b></p><p style="TEXT-INDENT: 2em">从这个包的名称上已经知道了，这是内核源码包。你可以apt-cache search kernel-source搜索到内核源代码包，并用uname -r命令查看到当前系统内核版本，然后用apt-get install kernel-source-xxxx来安装和你内核版本一致的内核源代码包。 </p><p style="TEXT-INDENT: 2em">但我并不建议你这样做，因为大多数发行版的Linux的内核源代码包并不是和你从kernel.org上下载来的完全一致，应该是经过发行者们修改优化过的包，虽然发行版的制作者们花了心血在上面，但对我们编程者来说这并不是件好事，因为大多发行版的源代码包缺少某些必要的头文件和某些有用的脚本程序，这会导致我们在编写内核模块时遇到麻烦，比如编译时可能会报错说某个头文件找不到，又可能报错说某个脚本程序不存在啦。 </p><p style="TEXT-INDENT: 2em">如果你直接去kernel.org上下载一个新的内核来编译升级你的内核，并在此基础上进行内核编程可能会省事一些，至少我后面讲到的这些包你都可以不用安装了，把KERNEL_DIR变量设置为你内核源代码包的位置就够了。 </p><p style="TEXT-INDENT: 2em">在这里还是以Debian 3.1、内核2.6.8-2-386为基础来教大家准备内核编程环境吧。那么你依次用这几个命令来安装kernel-source包吧。 </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />apt-cache search kernel-source
uname -r/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">apt-get install kernel-source-xxxx </p><p style="TEXT-INDENT: 2em">注：如果你不想重新编译内核，内核源代码包kernel-source是完全可以不下载来的。 </p><p style="TEXT-INDENT: 2em"><b>4、kernel-headers</b></p><p style="TEXT-INDENT: 2em">这是内核源代码头文件包，不管你是要进行内核模块开发还是进行驱动程序开发，这个包都是必须要安装的。因为作为一个内核模块编写者，通常会调用内核里的一些东西，比如内核头文件，内核数据结构申明等。它里面包含了一些关键的内核头文件。否则在编译内核时会报类似下面的错误： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />HOSTCC  scripts/basic/fixdep
scripts/basic/fixdep.c:105:23: error: sys/types.h: 没有那个文件或目录/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">输入如下命令来安装吧： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />apt-cache search kernel-headers
uname -r
apt-get instakk kernel-headers-xxxx/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">注：在Ubuntu下，好象这个包的前面都加上了linux-，从而变成了linux-kernel-headers。 </p><p style="TEXT-INDENT: 2em">如果之前没有安装过kernel-kbuild包，安装此包的过程中会安装kernel-kbuild包，这个包在下面介绍。 </p><p style="TEXT-INDENT: 2em"><b>5、kernel-kbuild</b></p><p style="TEXT-INDENT: 2em">这个包是用来编译内核模块的，下载安装这个包后会发现在/usr/src目录下多了一个kernel-kbuild-xxxx开头的目录，下面只有scripts一个目录，显然这是用来编译内核模块的一些脚本程序。安装方法一样： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />apt-cache search kernel-kbuild
uname -r
apt-get install kernel-kbuild-xxxx/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">注：你也会发现，在上面安装kernel-headers包后，/usr/src/kernel-headers-xxxx目录下有个scripts目录，其实是到/usr/src/kernel-kbuild-xxxx目录下的scripts的一个链接。 </p><p style="TEXT-INDENT: 2em"><b>6、build-essential</b></p><p style="TEXT-INDENT: 2em">这个包包含一个在建立deb包过程中起关键作用的包的信息列表，如果你不想建立deb包你就不需要安装此表，如果需要生成deb包就最好安装一下这个包吧。安装方法： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />apt-get install build-essential/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em"><b>7、kernel-package</b></p><p style="TEXT-INDENT: 2em">如果你想把内核镜像做成一个deb包来用，那么必须用安装这个包了。也就是说只有安装了这个软件包你才能有make-kpkg命令可用。安装方法一样了： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />apt-get install kernel-package/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em"><b>8、initrd-tools</b></p><p style="TEXT-INDENT: 2em">如果你想制作启动过程的initrd镜像，则这个包是必不可少的。安装了这个包之后才有mkinitrd命令可用的。安装方法： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />apt-get instakk initrd-tools/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">最后来一个内核模块编程示例吧! </p><p style="TEXT-INDENT: 2em">假设你编写了一个内核模块程序，源代码如下： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />/* hello.c */
#include &lt;linux/init.h&gt;
#include &lt;linux/module.h&gt;
#include &lt;linux/kernel.h&gt;
static int hello_init(void)
{
    printk(KERN_ALERT "Hello, linux kernel module\n");
    return 0;
}
static void hello_exit(void)
{
    printk<br />(KERN_ALERT "Goodbye, I've created a linux kernel module sucessfully\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">你需要这此源程序编写一个makefile，内容如下： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />#Makefile for hello.c file
#
KERNEL_DIR:=/usr/src/linux
obj-m:=hello.o
default: 
 $(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
clean: 
 $(RM) .*.cmd *.mod.c *.o *.ko -r .tmp/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">注意：这里的KERNEL_DIR是指内核源代码头文件所在目录的上一级目录，通常就是指内核源代码目录。该目录一般包括有arch，drivers，fs，include，init，ipc，kernel，lib，mm，net，scripts，usr，sound，security等目录。 </p><p style="TEXT-INDENT: 2em">在本示例中，/usr/src/linux是一个链接，指向了/usr/src/kernel-headers-2.6.8-3目录。 </p><p style="TEXT-INDENT: 2em">编写好makefile后就可以输入make命令生成hello.ko内核模块了，然后你可以用： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />insmode hello.ko/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">命令来加入内核模块，然后用： </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr /><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="#000000" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code />rmmod hello/PRE&gt;</pre></td></tr></tbody></table>/CENTER&gt;
<p style="TEXT-INDENT: 2em">来删除内核模块。 </p><p style="TEXT-INDENT: 2em">当然，操作过程中，你可以用dmesg命令来查看运行结果。</p><a href="http://www.xxlinux.com/">Linux联盟</a>收集整理 </center></center></center></center></center></center></center></center></center></center></center></center><img src ="http://www.cppblog.com/tx7do/aggbug/17406.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2007-01-07 21:56 <a href="http://www.cppblog.com/tx7do/archive/2007/01/07/17406.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>基于Dialog程序,启动时不显示主窗口,只显示子窗口的实现</title><link>http://www.cppblog.com/tx7do/archive/2006/12/19/16634.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Tue, 19 Dec 2006 14:06:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/12/19/16634.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/16634.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/12/19/16634.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/16634.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/16634.html</trackback:ping><description><![CDATA[在项目中有如下的一个需求:<br />软件在网络启动状态下显示主窗口,而在单机状态下只显示其子对话框(我的是无模式的).<br />在网上找了一天,各种办法都似乎不太好,<br />不过晚上终于找到了一个不错的解决办法.<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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (theApp.m_bUnConnect)<br /><img id="Codehighlighter1_33_263_Open_Image" onclick="this.style.display='none'; Codehighlighter1_33_263_Open_Text.style.display='none'; Codehighlighter1_33_263_Closed_Image.style.display='inline'; Codehighlighter1_33_263_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_33_263_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_33_263_Closed_Text.style.display='none'; Codehighlighter1_33_263_Open_Image.style.display='inline'; Codehighlighter1_33_263_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />    </span><span id="Codehighlighter1_33_263_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 src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_33_263_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        CRecordDlg</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> dlg;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        CWnd</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> m_pCWnd </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dlg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> CRecordDlg(m_pCWnd);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dlg</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Create(IDD_DLG_RECORD,m_pCWnd);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dlg</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">ShowWindow(SW_SHOW); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">SetWindowPos(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">wndTop,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,NULL);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"> </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> if ()</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_287_325_Open_Image" onclick="this.style.display='none'; Codehighlighter1_287_325_Open_Text.style.display='none'; Codehighlighter1_287_325_Closed_Image.style.display='inline'; Codehighlighter1_287_325_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_287_325_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_287_325_Closed_Text.style.display='none'; Codehighlighter1_287_325_Open_Image.style.display='inline'; Codehighlighter1_287_325_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />    </span><span id="Codehighlighter1_287_325_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 src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_287_325_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       ShowWindow(SW_MAXIMIZE);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span></span></div>以上为我实现代码.<br />实现主窗口隐藏的是SetWindowPos(),从代码很容易理解出来,就是把主窗口的坐标设置为(0,0,0,0),也就是说把主窗口设置为一个点,并且点处于原点处.<br />其实是一种伪隐藏,可是它还是实现了隐藏,并且实现的效果相当不错,没有闪烁,也没有副作用(至少现在没有发现有).<br />不过要注意的是,无模式对话框关闭时候除了要DestroyWindow(),还需要PostQuitMessage(0);将主窗口给关闭掉,否则程序进程实际还在.<br /><br />嘿嘿,实在是很不错的解决方案,简单有效.<img src ="http://www.cppblog.com/tx7do/aggbug/16634.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-12-19 22:06 <a href="http://www.cppblog.com/tx7do/archive/2006/12/19/16634.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++/STL/VC资源链接(查找方便) </title><link>http://www.cppblog.com/tx7do/archive/2006/10/24/14102.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Tue, 24 Oct 2006 13:28:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/10/24/14102.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/14102.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/10/24/14102.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/14102.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/14102.html</trackback:ping><description><![CDATA[
		<p class="left_aligned">
				<b>Official resources</b>
				<br />
				<a href="http://msdn.microsoft.com/" target="_new">MSDN</a>
				<br />
				<a href="http://msdn.microsoft.com/visualc/" target="_new">Visual C++ Home</a>
				<br />
				<a href="http://msdn.microsoft.com/newsgroups/default.asp?url=/newsgroups/loadframes.asp?ICP=msdn&amp;sLCID=us&amp;NewsGroup=microsoft.public.vc.language" target="_new">microsoft.public.vc.language</a>
				<br />
				<br />
				<b>The Top</b>
				<br />
				<a href="http://www.codeguru.com/" target="_new">CodeGuru</a>
				<br />
				<a href="http://www.codeproject.com/cpp" target="_new">CodeProject</a>
				<br />
				<a href="http://www.developerfusion.com/c/186/" target="_new">DeveloperFusion.com</a>
				<br />
				<a href="http://www.cuj.com/" target="_new">C/C++ Users Journal</a>
				<br />
				<a href="http://www.rsdn.ru/" target="_new">RSDN</a> (RU)<br /><a href="http://www.firststeps.ru/" target="_new">First Steps</a> (RU)<br /><a href="http://www.sources.ru/" target="_new">Sources.ru</a> (RU)<br /><br /><b>Tricks, Tips, FAQs</b><br /><a href="http://www.research.att.com/~bs/bs_faq2.html" target="_new">Bjarne Stroustrup's C++ Style and Technique FAQ</a><br /><a href="http://www.codeguru.com/FAQS" target="_new">CodeGuru FAQ</a><br /><a href="http://www.parashift.com/c++-faq-lite" target="_new">C++ FAQ Lite</a> by Marshall Cline<br /><a href="http://www.codeproject.com/cpp/cppforumfaq.asp" target="_new">CodeProject Forum FAQ</a><br /><a href="http://www.codejock.com/developer/" target="_new">Codejock Free Source Code</a><br /><a href="http://www.mooremvp.freeserve.co.uk/" target="_new">Boob Moore's page (Win32, NT, MFC)</a><br /><a href="http://cui.unige.ch/OSG/people/Past/fuentes/Mfc/mfc.html" target="_new">Edelmiro Fuentes's page</a><br /><a href="http://www.sources.ru/cpp/cpp_vcpp_faq.shtml" target="_new">FAQ @ Sources.ru</a> (RU)<br /><a href="http://www.akzhan.midi.ru/devcorner/devcorner-home-rus.html" target="_new">Akzhan Site</a> (RU)<br /><br /><b>Forums, newsgroups</b><br /><a href="http://www.codeguru.com/cgi-bin/bbs/wt/wwwthreads.pl?action=list&amp;Board=vc" target="_new">CodeGuru Forum</a><br /><a href="http://msdn.microsoft.com/newsgroups/default.asp?url=/newsgroups/loadframes.asp?ICP=msdn&amp;sLCID=us&amp;NewsGroup=microsoft.public.vc.language" target="_new">microsoft.public.vc.language</a><br /><a href="http://groups.google.com/groups?group=comp.lang.c%2B%2B" target="_new">comp.lang.c++</a><br /><a href="http://www.rsdn.ru/forum" target="_new">RSDN Forum</a> (RU)<br /><br /><b>Libs, Add-ons, Add-ins</b><br /><a href="http://hicomponents.com/" target="_new">ImageEn</a> - Powerful imaging tool for Builder C++ and Delphi<br /><a href="http://www.boost.org/libs/libraries.htm" target="_new">Boost Libraries</a> #1 for C++!<br /><a href="http://sourceforge.net/projects/tinyxml" target="_new">TinyXML</a> - light yet powerful XML library. Forget about MSXML! :)<br /><a href="http://www.wholetomato.com/" target="_new">Whole Tomato Software:</a> Code syntax highlighting<br /><a href="http://www.compuware.com/products" target="_new">Compuware corporation:</a> BoundsChecker, SoftICE etc.<br /><a href="http://www.bdsoft.com/tools/stlfilt.html" target="_new">STL Error Decryptor</a><br /><a href="http://www.ucancode.net/" target="_new">UCanCode:</a> XD++ MFC Class Library for Diagrams<br /><a href="http://www.regxlib.com/" target="_new">Regular Expression Library</a><br /><br /><b>Disk File Systems</b><br /><a href="http://www.mtu-net.ru/pinetar/dm/comp_ntfs.htm" target="_new">NTFS</a> (RU)<br /><br /><b>Serial Communication</b><br /><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwbgen/html/msdn_serial.asp" target="_new">Serial Communications in Win32</a>, MSDN<br /><a href="http://www.codeproject.com/system/cserialport.asp" target="_new">CSerialPort - Serial Port Wrapper</a><br /><a href="http://www.sysinternals.com/ntw2k/freeware/portmon.shtml" target="_new">COM port monitor</a><br /><a href="http://www.happytown.ru/prog/practika/com_win32.html" target="_new">COM ports in Win32</a> (RU)<br /><br /><b>File formats</b><br /><a href="http://www.wotsit.org/" target="_new">WOT IS IT</a><br /><br /><b>Win32 and HTML Help Development</b><br /><a href="http://msdn.microsoft.com/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.asp" target="_new">Microsoft HTML Help Workshop</a><br /><a href="http://www.mvps.org/htmlhelpcenter" target="_new">HTML Help Center</a><br /><a href="http://www.htmlhelp.com/" target="_new">Web Design Group (HTMLHelp.com)</a><br /><a href="http://www.helpmaster.com/" target="_new">Helpmaster</a><br /><br /><b>Books and Tutorials</b><br /><a href="http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html" target="_new">Thinking in C++</a> 2nd Edition by Bruce Eckel<br /><a href="http://www.cprogramming.com/" target="_new">C++ programming</a><br /><a href="http://www.aul.fiu.edu/tech/visualc.html" target="_new">Resources on the Web</a><br /><a href="http://www.w3schools.com/" target="_new">W3Schools</a><br /><a href="http://www.softcraft.ru/" target="_new">SoftCraft</a> (RU)<br /><a href="http://freebooks.boom.ru/" target="_new">Free books to download</a> (RU)<br /><br /><b>Application Development Articles</b><br /><a href="http://www-106.ibm.com/developerworks/views/rational/articles.jsp" target="_new">IBM Rational Library</a><br /><br /><b>OTHER TOPICS</b><br /><br /><b>WIN NT/2K Registry Tips</b><br /><a href="http://www.jsiinc.com/reghack.htm" target="_new">JSI Inc.</a><br /><br /><b>Installers</b><br /><a href="http://www.jrsoftware.org/isinfo.php" target="_new">Inno Installer</a><br /><a href="http://nsis.sourceforge.net/home/" target="_new">Nullsoft Scriptable Install System</a><br /><br /><b>Data Recovery</b><br /><a href="http://www.vitaldata.ca/" target="_new">Data Recovery.</a> Montreal, QC, Canada<br /><br /><b>Link to Links</b><br /><a href="http://directory.google.com/Top/Computers/Programming/Languages/C%2B%2B/Visual_C%2B%2B/" target="_new">Google Directory links</a><br /><a href="http://www.scriptsearch.com/" target="_new">ScriptSearch.com</a><br /></p>
<img src ="http://www.cppblog.com/tx7do/aggbug/14102.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-10-24 21:28 <a href="http://www.cppblog.com/tx7do/archive/2006/10/24/14102.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Doxygen syntax coloring in Vim</title><link>http://www.cppblog.com/tx7do/archive/2006/10/20/13929.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Fri, 20 Oct 2006 15:31:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/10/20/13929.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/13929.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/10/20/13929.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/13929.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/13929.html</trackback:ping><description><![CDATA[Error convertoring HTML to XHTML: System.ArgumentException: The empty string '' is not a valid name.
   at System.Xml.XmlTextWriter.ValidateName(String name, Boolean NCName)
   at System.Xml.XmlTextWriter.InternalWriteProcessingInstruction(String name, String text)
   at System.Xml.XmlTextWriter.WriteProcessingInstruction(String name, String text)
   at System.Xml.XmlWriter.WriteNode(XmlReader reader, Boolean defattr)
   at FreeTextBoxControls.Support.Formatter.HtmlToXhtml(String input)<img src ="http://www.cppblog.com/tx7do/aggbug/13929.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-10-20 23:31 <a href="http://www.cppblog.com/tx7do/archive/2006/10/20/13929.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Doxygen 的使用简介</title><link>http://www.cppblog.com/tx7do/archive/2006/10/20/13927.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Fri, 20 Oct 2006 14:43:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/10/20/13927.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/13927.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/10/20/13927.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/13927.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/13927.html</trackback:ping><description><![CDATA[来源：<a href="http://www.vckbase.com/document/viewdoc/?id=1287">http://www.vckbase.com/document/viewdoc/?id=1287</a><br />作者：<a href="mailto:tohjs@163.com">hjs</a><p><a href="http://www.vckbase.com/code/downcode.asp?id=2527">下载Doxygen相关文件</a><br /><br />　　Doxygen 是一个类似 JavaDoc 的文档生成工具。有了它，C++爱好者就可以为自己的源代码很方便地生成美观实用的文档了。<br /><br /><b>为代码生成文档标注基础</b><br /><br />　　您可以使用JavaDoc风格，类似于由C风格的注释块：</p><pre>/**
* ... 文本 ...
*/</pre><p>此外您也可以使用Qt风格，如</p><pre>/*!
* ... 文本...
*/</pre><p>以上两种风格中间的*是可选的，也就是下面这样写也是可以的：</p><pre>/*!
... 文本...
*/</pre><p>第三种是使用至少两行C++"//"注释，如：</p><pre>///
/// ... 文本...
///</pre><p>或者</p><p>//!<br />//!...文本...<br />//!</p><p>有的程序员也许喜欢下面这种风格，有比较好的视觉效果：</p><pre>/////////////////////////////////////////////////
/// ... 文本...
/////////////////////////////////////////////////</pre><p>　　对于简单的描述信息，可能有几种情况。一种是在注释块的开头使用\brief命令，该命令一直到段落结束有效，所以详细描述信息从空一行后开始，如下例：</p><pre>/*! \brief 简洁的描述信息 description.
* 又一些简洁的描述信息。
*
* 详细描述信息从这里开始。
*/</pre><p>　　在配置文件中，如果JAVADOC_AUTOBRIEF设为YES，则Doxygen将使用JavaDoc风格的注释块，从简洁描述信息后的点空格. 开始为详细描述信息，例如：</p><pre>/** 简洁信息结尾是一个点号. 详细描述信息从
* 这里开始
*/</pre><p>该选项对C++风格的多行注释也是有效的：</p><pre>///简洁信息结尾是一个点号. 详细描述信息从
///这里开始</pre><p>或者： </p><pre>/// 简洁描述信息
/** 详细描述信息*/</pre><p>或者：</p><pre>//!简洁描述信息

//!详细描述信息从
//!这里开始</pre><p>　　此例中间空行用来分割简洁描述信息块和详细描述信息块。可见doxygen的文档标注使用格式是非常自由的。不过要注意下面格式是不合法的，因为doxygen只允许一块详细描述信息对应一块简洁描述信息：</p><pre>//!简洁描述信息
//! 详细描述信息
/*! 注意，又一详细描述信息!
*/</pre><pre>下例使用Qt风格的文档标注：
//! A test class. 
/*!
A more elaborate class description.
*/

class Test
{
  public:

    //! An enum.
    /*! More detailed enum description. */
    enum TEnum { 
                 TVal1, /*!&lt; Enum value TVal1. */  
                 TVal2, /*!&lt; Enum value TVal2. */  
                 TVal3  /*!&lt; Enum value TVal3. */  
               } 
         //! Enum pointer.
         /*! Details. */
         *enumPtr, 
         //! Enum variable.
         /*! Details. */
         enumVar;  
    
    //! A constructor.
    /*!
      A more elaborate description of the constructor.
    */
    Test();

    //! A destructor.
    /*!
      A more elaborate description of the destructor.
    */
   ~Test();
    
    //! A normal member taking two arguments and returning an integer value.
    /*!
      \param a an integer argument.
      \param s a constant character pointer.
      \return The test results
      \sa Test(), ~Test(), testMeToo() and publicVar()
    */
    int testMe(int a,const char *s);
       
    //! A pure virtual member.
    /*!
      \sa testMe()
      \param c1 the first argument.
      \param c2 the second argument.
    */
    virtual void testMeToo(char c1,char c2) = 0;
   
    //! A public variable.
    /*!
      Details.
    */
    int publicVar;
       
    //! A function variable.
    /*!
      Details.
    */
    int (*handler)(int a,int b);
};
</pre><p>　　Doxygen的文档标注是不是非常容易？当然还可以有更高级的应用，如标注列表、分组，甚至支持生成公式(Latex)。上面只编译了最简单的一些使用方法，更多内容请参考Doxygen的帮助文档doxygen_manual。<br /><br /><b>附带文档的说明：</b><br /><br />　　DoxygWizard是基于QT的简易图形用户界面，简化了Doxygen的使用。您可以在DoxygWizard里对需要生成的文档进行设置，可保存为"Doxyfile"，然后调用Doxygen生成文档。需要注意的是，文件路径不支持中文，所以尽可能使您的源代码和文档目录均为英文名。在"Doxyfile"文件同一目录请放置一个"mylogo"纯文本文件，内容可以是一些版权标识信息，这些信息将显示在生成文档页面的最下边，如果没有此"mylogo"文件，将生成默认的版权标识信息。<br />　　样式表文件Orignl_doxygen.css、green_doxygen.css、yellow_doxygen.css、Blue_doxygen.css，改文件名为doxygen.css后，拷贝到生成html文档的目录内可以改变文档显示的样式。<br />　　OUT PUT_LANGUAGE 可选项为Englisth(英文文档), Chinese(中文文档), En_Can_Cn(支持中文注释的英文文档)<br /><br /><b>相关网址：<br /></b><br />http://www.doxygen.org/download.html<br />您还需要下载graphviz dot画图：<br />http://www.research.att.com/sw/tools/graphviz/<br /><br /></p><img src ="http://www.cppblog.com/tx7do/aggbug/13927.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-10-20 22:43 <a href="http://www.cppblog.com/tx7do/archive/2006/10/20/13927.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Visual Studio .NET的Doxygen 插件，不错！</title><link>http://www.cppblog.com/tx7do/archive/2006/10/20/13926.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Fri, 20 Oct 2006 14:40:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/10/20/13926.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/13926.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/10/20/13926.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/13926.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/13926.html</trackback:ping><description><![CDATA[
		<a href="http://www.codeproject.com/macro/KingsTools.asp">http://www.codeproject.com/macro/KingsTools.asp</a>
		<br />
		<br />
		<ul class="download">
				<li>
						<a href="http://www.codeproject.com/macro/KingsTools/KingsTools.zip">Download Installer - 1847 Kb</a>
				</li>
				<li>
						<a href="http://www.codeproject.com/macro/KingsTools/KingsTools_src.zip">Download source - 47 Kb</a>
				</li>
		</ul>
		<p>
				<img height="223" alt="Kings Tools" src="http://www.codeproject.com/macro/KingsTools/menu.jpg" width="555" />
		</p>
		<p>
				<img height="48" alt="Kings Tools" src="http://www.codeproject.com/macro/KingsTools/toolbar.jpg" width="320" />
		</p>
		<h2>Introduction</h2>
		<p>As good as Visual Studio .NET is, I still miss some features in it. But MS knew that they couldn't fulfill every wish so they provided a way to write addins. That's what I've done. Sure, most of the functions in my Tools could also be done with macros, but I wanted them all packed together with an installer.</p>
		<h2>Tools</h2>
		<ul>
				<li>Run Doxygen 
</li>
				<li>Insert Doxygen comments 
</li>
				<li>Build Solution stats 
</li>
				<li>Dependency Graph 
</li>
				<li>Inheritance Graph 
</li>
				<li>Swap .h&lt;-&gt;.cpp 
</li>
				<li>Colorize 
</li>
				<li>} End of 
</li>
				<li>#region/#endregion for c++ 
</li>
				<li>Search the web </li>
		</ul>
		<h3>Run Doxygen</h3>
		<p>This command first pops up a dialog box in which you can configure the output Doxygen should produce. For those who don't know Doxygen: it's a free tool to generate source documentations. It can produce documentation in different formats like html and even windows help format! See <a href="http://www.doxygen.org/">http://www.doxygen.org/</a> for details. Since the dialog box doesn't offer all possible settings for doxygen, you can always edit the file Doxyfile.cfg manually which is created the first time you run it. All settings in that file override the settings you enter in the dialog box.</p>
		<p>
				<img height="430" alt="Doxygen configuration dialog" src="http://www.codeproject.com/macro/KingsTools/doxydialog.jpg" width="446" />
		</p>
		<p>If you set Doxygen to generate html output, the resulting <i>index.html</i> is opened inside the IDE. A winhelp output (<i>index.chm</i>) will be opened outside the IDE.</p>
		<p>The command available from the Tools menu builds the documentation for the whole solution. If you don't want that for example if you have several third party projects in your solution then you can build the documentation also for single projects. To do that the KingsTools add a command to the right click menu in the solution explorer.</p>
		<p>If you want to update Doxygen to a newer version (as soon as one is released) simply overwrite the <i>doxygen.exe</i> in the installation directory. The same applies to the <i>dot.exe</i>.</p>
		<p>TODO: find a way to integrate the generated windows help file into VS help.</p>
		<h3>Insert Doxygen comments</h3>
		<p>Doxygen needs comments that follow certain conventions to build documentation from. This part of the tools inserts them for you. Either from the right click menu in the code editor window or from the submenu under Tools-&gt;Kings Tools. Just place the caret over a method or class header. The inserted comment for a method or function would look like this:</p>
		<pre>
				<span class="cpp-comment">/**
 *
 * \param one
 * \param two
 * \param three
 * \return
 */</span>
BOOL myfunction(<span class="cpp-keyword">int</span> one, <span class="cpp-keyword">int</span> two, <span class="cpp-keyword">int</span> three);
</pre>
		<p>You now have to simply insert a description in the second comment line and descriptions for each parameter of the function/method. And of course a description of the return value.</p>
		<p>You can customize the function comments by editing the files "functionheadertop.txt", "functionparams.txt" and "functionheaderbottom.txt". Please read the comments inside those files on how to do that. If you don't want to change the function comments for all your projects then you can place any of those files into your project directory (that way it will be used for your project) or inside the folder of your source files (that way it will be used only for the files inside that specific folder).</p>
		<p>The inserted comment for a class looks like this:</p>
		<pre>
				<span class="cpp-comment">/**
 * \ingroup projectname
 *
 * \par requirements
 * win98 or later, win2k or later, win95 with IE4 or later, winNT4 with IE4 
 * or later
 *
 * \author user
 *
 * \par license
 * This code is absolutely free to use and modify. The code is provided 
 * "as is" with no expressed or implied warranty. The author accepts no 
 * liability if it causes any damage to your computer, causes your pet to 
 * fall ill, increases baldness or makes your car start emitting strange 
 * noises when you start it up. This code has no bugs, just undocumented 
 * features!
 *
 * \version 1.0
 * \date 06-2002
 * \todo
 * \bug
 * \warning
 *
 */</span>
				<span class="cpp-keyword">class</span> CRegBase
</pre>
		<p>The '\ingroup projectname' means that the class is inside the project 'projectname'. That statement helps Doxygen to group classes together. Insert the description of the class right after that statement. If you want to include pictures to illustrate the class, use '\image html "picture.jpg"'. For more helpful tags you can use please check out the Doxygen website. The '\par requirements' section you have to modify yourself to fit the truth of your class. It's not necessary for Doxygen, but I found it very useful to give that information inside a class documentation. The name after the '\author' tag is the currently logged in user. Maybe you want to change that too to include an email address.</p>
		<p>You can customize the class comments by editing the file "classheader.txt" Please read the comments inside that file on how to do that. If you don't want to change the class comments for all your projects then you can place that files into your project directory (that way it will be used for your project) or inside the folder of your source files (that way it will be used only for the files inside that specific folder).</p>
		<p>The last few tags should be self-explanatory. Under the line '\version' I usually insert short descriptions of what changed between versions.</p>
		<h3>Build Solution stats</h3>
		<p>This is a simple line counter. It counts all the lines of all files in your solution, grouped by projects. The generated html file with the counted lines (code, comments, empty) is then opened in the IDE. Since I haven't found a way to add a file directly to a solution and not to a project the file is just opened for view in the IDE.</p>
		<h3>Dependency and Inheritance graph</h3>
		<p>These two commands build graphs of the class relations in your solution. See my <a href="http://www.codeproject.com/macro/classdep.asp">previous article</a> about this. The difference to my old tool is that it now generates graphs for all projects in the solution and puts all the graphs in one single html page.</p>
		<h3>Swap .h&lt;-&gt;.cpp</h3>
		<p>This is something a simple macro could also do: it swaps between header and code files. For better accessibility it also is on the right click menu of the code editor. Really nothing special but it can be useful sometimes.</p>
		<h3>Colorize</h3>
		<p>This tool goes through all files of the current solution and looks for class, function and macronames. It then writes them to a <i>usertype.dat</i> file, makes the IDE to read that file and deletes it again. After you run this tool, all class, function and macronames of your solution appear colored in the code editor. Default color is the same color as normal keywords, but you can change that under Tools-&gt;Options, in the Options dialog select Environment-&gt;Fonts and Colors.</p>
		<p>If you don't want the colors anymore, just run the command 'disable coloring' and everything will be in normal colors again. I didn't want to overwrite some possible <i>usertype.dat</i> file already created by some user so the tool simply creates a temporary <i>usertype.dat</i> file instead. If you want to have the colors again the next time the IDE starts, you either have to rerun the command (doesn't take very long to execute) or change the code of the tool yourself.</p>
		<h3>} End of</h3>
		<p>Have you ever wrote a bunch of code which looked like this:</p>
		<p>
				<img height="82" alt="Braces without comments" src="http://www.codeproject.com/macro/KingsTools/brace_without.jpg" width="384" />
		</p>
		<p>Ok, I admit this isn't a very good style of programming, but sometimes it can't be avoided. And in those cases the code is horrible to read because you don't know which closing brace belongs to which opening statement without scrolling or using the macro 'Edit.GotoBrace' several times. This tool provides a function which inserts comments after the closing brace automatically. The code snippet above would look like this:</p>
		<p>
				<img height="82" alt="Braces with comments" src="http://www.codeproject.com/macro/KingsTools/brace_with.jpg" width="316" />
		</p>
		<p>Comments are only inserted for closing braces of <code><span class="cpp-keyword">if</span></code>, <code><span class="cpp-keyword">while</span></code>, <code><span class="cpp-keyword">for</span></code> and <code><span class="cpp-keyword">switch</span></code> statements.</p>
		<p>If you don't want to insert comments automatically while editing, you can turn off this function. If you just don't want those comments at specific places you have to move the caret either upwards (instead of downwards which happens if you press enter) or click with the mouse so that the caret doesn't go to the line below the closing brace. Comments are also not inserted when the opening brace is less than two lines above.</p>
		<h3>#region/#endregion for C++</h3>
		<p>VS.NET introduced to possibility to outline portions of text in the code editor. That's a very useful feature wthat helps navigating through big bunches of code. But the outlined sections are not saved between sessions. VB and C# provide keywords to outline sections. In VB its '#Region' and '#End Region', in C# its '#region' and '#endregion'. Only for C++ MS didn't provide such keywords (at least I haven't found them yet). With this tool you can now enable that feature for C++ too. To prevent compiler errors for those who have not installed this tool I used '//#region' and '//#endregion' as the keywords. With the comment lines before the compiler won't complain. Use those keywords like this:</p>
		<p>
				<img height="279" alt="outlined sections" src="http://www.codeproject.com/macro/KingsTools/region1.jpg" width="350" />
		</p>
		<p>Whenever you open a document with such keywords the tool will automatically create outlining sections. The section are also created when you type the '//#endregion' keyword and a matching '//#region' is found. As you can see, you can easily nest the sections. The code above would then look like this:</p>
		<p>
				<img height="218" alt="outlined sections" src="http://www.codeproject.com/macro/KingsTools/region2.jpg" width="345" />
		</p>
		<p>
				<img height="39" alt="outlined sections" src="http://www.codeproject.com/macro/KingsTools/region3.jpg" width="290" />
		</p>
		<p>This function can't be deactivated. If you don't want it, simply don't use those keywords :)</p>
		<h3>Search the web</h3>
		<p>These two small addons perform a simple web site search either in the google groups or on CP. Select a piece of text in the code editor, right click to pop up the menu and then select where to search for the selected text. That's all. The search results will be opened inside VS.NET.</p>
		<p>
				<img height="79" alt="right click menu" src="http://www.codeproject.com/macro/KingsTools/rightclick.jpg" width="507" />
		</p>
		<h2>Install</h2>
		<p>To install the tools, just double-click the *.msi file and follow the instructions. If the tools are not automatically activated the next time you start the IDE, then please activate them under Tools-&gt;Add-In Manager. Make sure you select both the addin and the box 'startup'.</p>
		<p>All additional files needed for the tools are also packed in the installer, including Doxygen and the dot files. So you don't have to grab them separately from the web.</p>
		<h2>Source</h2>
		<p>Full source code is provided with these tools. The addin is written in VB.NET cause first there was just one simple tool that I wanted immediately - and VB is good enough for that. Then the tool grew and I added more functions. So the code is surely not the best example for good programming (no plan, no structure -&gt; chaos). But maybe it might still be of interest for those 