﻿<?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>IT博客-小祥的BLOG-随笔分类-D3D</title><link>http://www.cnitblog.com/xfxsworld/category/6521.html</link><description>游戏开发</description><language>zh-cn</language><lastBuildDate>Sat, 01 Oct 2011 01:24:10 GMT</lastBuildDate><pubDate>Sat, 01 Oct 2011 01:24:10 GMT</pubDate><ttl>60</ttl><item><title>Alpha混合</title><link>http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36327.html</link><dc:creator>小祥</dc:creator><author>小祥</author><pubDate>Thu, 15 Nov 2007 11:40:00 GMT</pubDate><guid>http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36327.html</guid><wfw:comment>http://www.cnitblog.com/xfxsworld/comments/36327.html</wfw:comment><comments>http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36327.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/xfxsworld/comments/commentRss/36327.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/xfxsworld/services/trackbacks/36327.html</trackback:ping><description><![CDATA[
		<div>
				<font face="Verdana">Direct3D计算Alpha混合的颜色公式：</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana" color="#ff0000">Color = ( SrcRGB * SrcK ) + ( DestRGB * DestK )</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana" color="#ff0000">
				</font> </div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana" color="#000000">SrcRGB表示源颜色值，即将要绘制的颜色值。SrcK表示源混合系数，通常赋值为D3DBLEND_SRCALPHA，即当前绘制像素的Alpha值</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">DestRGB表示目标颜色值，即当前缓冲区中的颜色值。DestK表示目标系数，通常赋值为D3DBLEND_INVSRCALPHA，即1减去当前绘制像素的Alpha值</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">
				</font> </div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">则Direct3D计算Alpha混合的颜色公式可表示为</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana" color="#ff0000">Color = ( SrcRGB * SrcAlpha ) + ( DestRGB * ( 1 - SrcAlpha ) )</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">
				</font> </div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">混合步骤</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">
				</font> </div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">Alpha混合默认关闭，所以首先需要开启它</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">Device -&gt; SetRenderState( D3DRS_ALPHABLENDENABLE, true );</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">
				</font> </div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">然后设置Alpha混合系数</font>
		</div>
		<div>
				<font style="BACKGROUND-COLOR: #fffafa" face="Verdana">Device -&gt; SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );</font>
		</div>
		<div>
				<font face="Verdana">Device -&gt; SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); </font>
		</div>
		<div>
				<font face="Verdana">
				</font> </div>
		<div>
				<font face="Verdana">还要指定资源(材质或Alpha通道)</font>
		</div>
		<div>
				<font face="Verdana">Alpha通道可用DirectX自带的纹理工具创建，为DDS文件</font>
		</div>
		<div>
				<font face="Verdana">
				</font> </div>
		<div>
				<font face="Verdana">DEMO演示图片:<br /><img height="476" alt="alphablend.jpg" src="http://www.cnitblog.com/images/cnitblog_com/xfxsworld/alphablend.jpg" width="630" border="0" /></font>
		</div>
<img src ="http://www.cnitblog.com/xfxsworld/aggbug/36327.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/xfxsworld/" target="_blank">小祥</a> 2007-11-15 19:40 <a href="http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36327.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>地形高度算法小结</title><link>http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36325.html</link><dc:creator>小祥</dc:creator><author>小祥</author><pubDate>Thu, 15 Nov 2007 11:26:00 GMT</pubDate><guid>http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36325.html</guid><wfw:comment>http://www.cnitblog.com/xfxsworld/comments/36325.html</wfw:comment><comments>http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36325.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/xfxsworld/comments/commentRss/36325.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/xfxsworld/services/trackbacks/36325.html</trackback:ping><description><![CDATA[
		<div>
				<font size="2">地形一般是用网格再从高度图里读取每个顶点的高度来生成。若进一步，想实现摄像机在地形上行走的效果，就需要算出地形上任意一点的高度。总结了3个方法：<br /> <br />一：<br />《Introduction to 3D Game Programming With Directx 9.0》这本书里介绍的，利用向量来算。<br /><img height="251" alt="11.jpg" src="http://www.cnitblog.com/images/cnitblog_com/xfxsworld/11.jpg" width="458" border="0" /><br /> </font>
		</div>
		<div>
				<font size="2">
						<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">
								<span style="COLOR: #008080"> 1</span>
								<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #0000ff">float</span>
								<span style="COLOR: #000000"> Terrain::GetHeight(</span>
								<span style="COLOR: #0000ff">float</span>
								<span style="COLOR: #000000"> x, </span>
								<span style="COLOR: #0000ff">float</span>
								<span style="COLOR: #000000"> z)<br /></span>
								<span style="COLOR: #008080"> 2</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_43_2225_Open_Image" onclick="this.style.display='none'; Codehighlighter1_43_2225_Open_Text.style.display='none'; Codehighlighter1_43_2225_Closed_Image.style.display='inline'; Codehighlighter1_43_2225_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
										<img id="Codehighlighter1_43_2225_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_43_2225_Closed_Text.style.display='none'; Codehighlighter1_43_2225_Open_Image.style.display='inline'; Codehighlighter1_43_2225_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
								</span>
								<span id="Codehighlighter1_43_2225_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.cnitblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_43_2225_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080"> 3</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> Translate on xz-plane by the transformation that takes<br /></span>
										<span style="COLOR: #008080"> 4</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> the terrain START point to the origin.</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080"> 5</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000"> x </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> ((</span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000">)_width </span>
										<span style="COLOR: #000000">/</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">2.0f</span>
										<span style="COLOR: #000000">) </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> x;<br /></span>
										<span style="COLOR: #008080"> 6</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> z </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> ((</span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000">)_depth </span>
										<span style="COLOR: #000000">/</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">2.0f</span>
										<span style="COLOR: #000000">) </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> z;<br /></span>
										<span style="COLOR: #008080"> 7</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> Scale down by the transformation that makes the <br /></span>
										<span style="COLOR: #008080"> 8</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> cellspacing equal to one.  This is given by <br /></span>
										<span style="COLOR: #008080"> 9</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> 1 / cellspacing since; cellspacing * 1 / cellspacing = 1.</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">10</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000"> x </span>
										<span style="COLOR: #000000">/=</span>
										<span style="COLOR: #000000"> (</span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000">)_CellSpacing;<br /></span>
										<span style="COLOR: #008080">11</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> z </span>
										<span style="COLOR: #000000">/=</span>
										<span style="COLOR: #000000"> (</span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000">)_CellSpacing;<br /></span>
										<span style="COLOR: #008080">12</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> From now on, we will interpret our positive z-axis as<br /></span>
										<span style="COLOR: #008080">13</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> going in the 'down' direction, rather than the 'up' direction.<br /></span>
										<span style="COLOR: #008080">14</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> This allows to extract the row and column simply by 'flooring'<br /></span>
										<span style="COLOR: #008080">15</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> x and z:</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">16</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000"> col </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> ::floorf(x);<br /></span>
										<span style="COLOR: #008080">17</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000"> row </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> ::floorf(z);<br /></span>
										<span style="COLOR: #008080">18</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> get the heights of the quad we're in:<br /></span>
										<span style="COLOR: #008080">19</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> <br /></span>
										<span style="COLOR: #008080">20</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">  A   B<br /></span>
										<span style="COLOR: #008080">21</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">  *---*<br /></span>
										<span style="COLOR: #008080">22</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">    | / |<br /></span>
										<span style="COLOR: #008080">23</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">  *---*  <br /></span>
										<span style="COLOR: #008080">24</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">  C   D</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">25</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000"> A </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> GetHeightMapEntry(row,   col);<br /></span>
										<span style="COLOR: #008080">26</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000"> B </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> GetHeightMapEntry(row,   col</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">);<br /></span>
										<span style="COLOR: #008080">27</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000"> C </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> GetHeightMapEntry(row</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">, col);<br /></span>
										<span style="COLOR: #008080">28</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000"> D </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> GetHeightMapEntry(row</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">, col</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">);<br /></span>
										<span style="COLOR: #008080">29</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">30</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> Find the triangle we are in:<br /></span>
										<span style="COLOR: #008080">31</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">32</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> Translate by the transformation that takes the upper-left<br /></span>
										<span style="COLOR: #008080">33</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> corner of the cell we are in to the origin.  Recall that our <br /></span>
										<span style="COLOR: #008080">34</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> cellspacing was nomalized to 1.  Thus we have a unit square<br /></span>
										<span style="COLOR: #008080">35</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> at the origin of our +x -&gt; 'right' and +z -&gt; 'down' system.</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">36</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000"> dx </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> x </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> col;<br /></span>
										<span style="COLOR: #008080">37</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000"> dz </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> z </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> row;<br /></span>
										<span style="COLOR: #008080">38</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> Note the below compuations of u and v are unneccessary, we really<br /></span>
										<span style="COLOR: #008080">39</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> only need the height, but we compute the entire vector to emphasis<br /></span>
										<span style="COLOR: #008080">40</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> the books discussion.</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">41</span>
										<span style="COLOR: #008000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">float</span>
										<span style="COLOR: #000000"> height </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0.0f</span>
										<span style="COLOR: #000000">;<br /></span>
										<span style="COLOR: #008080">42</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(dz </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1.0f</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> dx)  </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> upper triangle ABC</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">43</span>
										<span style="COLOR: #008000">
												<img id="Codehighlighter1_1554_1858_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1554_1858_Open_Text.style.display='none'; Codehighlighter1_1554_1858_Closed_Image.style.display='inline'; Codehighlighter1_1554_1858_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_1554_1858_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1554_1858_Closed_Text.style.display='none'; Codehighlighter1_1554_1858_Open_Image.style.display='inline'; Codehighlighter1_1554_1858_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000"> </span>
										<span id="Codehighlighter1_1554_1858_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.cnitblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_1554_1858_Open_Text">
												<span style="COLOR: #000000">{<br /></span>
												<span style="COLOR: #008080">44</span>
												<span style="COLOR: #000000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
												<span style="COLOR: #0000ff">float</span>
												<span style="COLOR: #000000"> uy </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> B </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000"> A; </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> A-&gt;B</span>
												<span style="COLOR: #008000">
														<br />
												</span>
												<span style="COLOR: #008080">45</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="COLOR: #000000">  </span>
												<span style="COLOR: #0000ff">float</span>
												<span style="COLOR: #000000"> vy </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> C </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000"> A; </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> A-&gt;C<br /></span>
												<span style="COLOR: #008080">46</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> Linearly interpolate on each vector.  The height is the vertex<br /></span>
												<span style="COLOR: #008080">47</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> height the vectors u and v originate from {A}, plus the heights<br /></span>
												<span style="COLOR: #008080">48</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> found by interpolating on each vector u and v.</span>
												<span style="COLOR: #008000">
														<br />
												</span>
												<span style="COLOR: #008080">49</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="COLOR: #000000">  height </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> A </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> Lerp(</span>
												<span style="COLOR: #000000">0.0f</span>
												<span style="COLOR: #000000">, uy, dx) </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> Lerp(</span>
												<span style="COLOR: #000000">0.0f</span>
												<span style="COLOR: #000000">, vy, dz);<br /></span>
												<span style="COLOR: #008080">50</span>
												<span style="COLOR: #000000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
										</span>
										<span style="COLOR: #008080">51</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #0000ff">else</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> lower triangle DCB</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">52</span>
										<span style="COLOR: #008000">
												<img id="Codehighlighter1_1889_2207_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1889_2207_Open_Text.style.display='none'; Codehighlighter1_1889_2207_Closed_Image.style.display='inline'; Codehighlighter1_1889_2207_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_1889_2207_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1889_2207_Closed_Text.style.display='none'; Codehighlighter1_1889_2207_Open_Image.style.display='inline'; Codehighlighter1_1889_2207_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000"> </span>
										<span id="Codehighlighter1_1889_2207_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.cnitblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_1889_2207_Open_Text">
												<span style="COLOR: #000000">{<br /></span>
												<span style="COLOR: #008080">53</span>
												<span style="COLOR: #000000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
												<span style="COLOR: #0000ff">float</span>
												<span style="COLOR: #000000"> uy </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> C </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000"> D; </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> D-&gt;C</span>
												<span style="COLOR: #008000">
														<br />
												</span>
												<span style="COLOR: #008080">54</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="COLOR: #000000">  </span>
												<span style="COLOR: #0000ff">float</span>
												<span style="COLOR: #000000"> vy </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> B </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000"> D; </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> D-&gt;B<br /></span>
												<span style="COLOR: #008080">55</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> Linearly interpolate on each vector.  The height is the vertex<br /></span>
												<span style="COLOR: #008080">56</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> height the vectors u and v originate from {D}, plus the heights<br /></span>
												<span style="COLOR: #008080">57</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> found by interpolating on each vector u and v.</span>
												<span style="COLOR: #008000">
														<br />
												</span>
												<span style="COLOR: #008080">58</span>
												<span style="COLOR: #008000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="COLOR: #000000">  height </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> D </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> Lerp(</span>
												<span style="COLOR: #000000">0.0f</span>
												<span style="COLOR: #000000">, uy, </span>
												<span style="COLOR: #000000">1.0f</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000"> dx) </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> Lerp(</span>
												<span style="COLOR: #000000">0.0f</span>
												<span style="COLOR: #000000">, vy, </span>
												<span style="COLOR: #000000">1.0f</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000"> dz);<br /></span>
												<span style="COLOR: #008080">59</span>
												<span style="COLOR: #000000">
														<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
										</span>
										<span style="COLOR: #008080">60</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
										<span style="COLOR: #0000ff">return</span>
										<span style="COLOR: #000000"> height;<br /></span>
										<span style="COLOR: #008080">61</span>
										<span style="COLOR: #000000">
												<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">62</span>
								<span style="COLOR: #000000">
										<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
								</span>
						</div> <br />用到的2个函数<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"><span style="COLOR: #008080">1</span><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> Terrain::Lerp(</span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> a, </span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> b, </span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> t)     </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">一个插值函数</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">2</span><span style="COLOR: #008000"><img id="Codehighlighter1_60_91_Open_Image" onclick="this.style.display='none'; Codehighlighter1_60_91_Open_Text.style.display='none'; Codehighlighter1_60_91_Closed_Image.style.display='inline'; Codehighlighter1_60_91_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_60_91_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_60_91_Closed_Text.style.display='none'; Codehighlighter1_60_91_Open_Image.style.display='inline'; Codehighlighter1_60_91_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_60_91_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.cnitblog.com/images/dot.gif" /></span><span id="Codehighlighter1_60_91_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">3</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (a </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> (a</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">t) </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> (b</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">t));<br /></span><span style="COLOR: #008080">4</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">5</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">6</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> Terrain::GetHeightMapEntry(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> row, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> col)         </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">读取高度函数</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">7</span><span style="COLOR: #008000"><img id="Codehighlighter1_160_235_Open_Image" onclick="this.style.display='none'; Codehighlighter1_160_235_Open_Text.style.display='none'; Codehighlighter1_160_235_Closed_Image.style.display='inline'; Codehighlighter1_160_235_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_160_235_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_160_235_Closed_Text.style.display='none'; Codehighlighter1_160_235_Open_Image.style.display='inline'; Codehighlighter1_160_235_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_160_235_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.cnitblog.com/images/dot.gif" /></span><span id="Codehighlighter1_160_235_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">8</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> _heightmap[row </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> _numVertsPerRow </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> col];   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 高度图数据存在_heightmap里</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">9</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /></span><span style="COLOR: #000000">}</span></span></div><br /> <br />二：<br />先计算出摄像机所在三角形的平面方程，然后带入摄像机的X，Z坐标，即可得高度Y<br />具体实现过程见<a href="http://creatorchen1984.spaces.live.com/">http://creatorchen1984.spaces.live.com/</a> 《获取地形上某一点高度》，写的十分详细<br /> <br />三：<br />网上找的一个方法<br />假设你的地形为terrain[][];用下面的函数求出地形上点(x,z);的y值,将人物的高度加上这个y值即可.<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"><span style="COLOR: #008080"> 1</span><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> GetHeight(GLfloat x, GLfloat z)<br /></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #000000"><img id="Codehighlighter1_38_287_Open_Image" onclick="this.style.display='none'; Codehighlighter1_38_287_Open_Text.style.display='none'; Codehighlighter1_38_287_Closed_Image.style.display='inline'; Codehighlighter1_38_287_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_38_287_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_38_287_Closed_Text.style.display='none'; Codehighlighter1_38_287_Open_Image.style.display='inline'; Codehighlighter1_38_287_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_38_287_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.cnitblog.com/images/dot.gif" /></span><span id="Codehighlighter1_38_287_Open_Text"><span style="COLOR: #000000">{ <br /></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> h</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> Xb,Yb;<br /></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> Xa,Ya;<br /></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />Xa</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)x;<br /></span><span style="COLOR: #008080"> 7</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />Ya</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)z;<br /></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />Xb</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">Xa;<br /></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />Yb</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">z</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">Ya;<br /></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">terrain[Xa][Ya].y;<br /></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> b</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">terrain[Xa</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][Ya].y;<br /></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">terrain[Xa][Ya</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">].y;<br /></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000"> d</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">terrain[Xa</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][Ya</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">].y;<br /></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />h</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">Xb)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">Xb)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">Yb)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">(c</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">Xb)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">Xb)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">Yb;<br /></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> h;<br /></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"> <br /></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div></font>
		</div>
<img src ="http://www.cnitblog.com/xfxsworld/aggbug/36325.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/xfxsworld/" target="_blank">小祥</a> 2007-11-15 19:26 <a href="http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36325.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DirectX下 Viewing Frustum 的详细实现</title><link>http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36321.html</link><dc:creator>小祥</dc:creator><author>小祥</author><pubDate>Thu, 15 Nov 2007 10:40:00 GMT</pubDate><guid>http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36321.html</guid><wfw:comment>http://www.cnitblog.com/xfxsworld/comments/36321.html</wfw:comment><comments>http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36321.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/xfxsworld/comments/commentRss/36321.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/xfxsworld/services/trackbacks/36321.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 本文大部分内容翻译自Gil Gribb和Klaus Hartmann合写的《Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix》这篇文章，有兴趣的朋友可以搜索看下原文，里面DirectX下和OpenGL下的实现过程都说的很清楚，这里只说DirectX部分。 这里介绍的算法，可以直接从世界、观...&nbsp;&nbsp;<a href='http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36321.html'>阅读全文</a><img src ="http://www.cnitblog.com/xfxsworld/aggbug/36321.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/xfxsworld/" target="_blank">小祥</a> 2007-11-15 18:40 <a href="http://www.cnitblog.com/xfxsworld/archive/2007/11/15/36321.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>