取自《Focus On 3D Terrain Programming》中的一段:
 bool CTERRAIN::MakeTerrainFault( int iSize, int iIterations, int iMinDelta, int iMaxDelta, float fFilter )
{
......
.............
for( iCurrentIteration=; iCurrentIteration<iIterations; iCurrentIteration++ )
{
//calculate the height range (linear interpolation from iMaxDelta to iMinDelta) for this fault-pass
iHeight= iMaxDelta - ( ( iMaxDelta-iMinDelta )*iCurrentIteration )/iIterations; //pick two points at random from the entire height map
iRandX1= rand( )%m_iSize;
iRandZ1= rand( )%m_iSize; //check to make sure that the points are not the same
do
{
iRandX2= rand( )%m_iSize;
iRandZ2= rand( )%m_iSize;
} while ( iRandX2==iRandX1 && iRandZ2==iRandZ1 ); //iDirX1, iDirZ1 is a vector going the same direction as the line
iDirX1= iRandX2-iRandX1;
iDirZ1= iRandZ2-iRandZ1; for( z=; z<m_iSize; z++ )
{
for( x=; x<m_iSize; x++ )
{
//iDirX2, iDirZ2 is a vector from iRandX1, iRandZ1 to the current point (in the loop)
iDirX2= x-iRandX1;
iDirZ2= z-iRandZ1; //if the result of ( iDirX2*iDirZ1 - iDirX1*iDirZ2 ) is "up" (above 0),
//then raise this point by iHeight
if( ( iDirX2*iDirZ1 - iDirX1*iDirZ2 )> )
fTempBuffer[( z*m_iSize )+x]+= ( float )iHeight;
}
}
//erode terrain
FilterHeightField( fTempBuffer, fFilter );
}
.......
..............
return true;
}

===================

代码的核心内容就是实现一个fault formation算法,算法是一个简单的数学模型,所以只要按照在纸上画个图就明白了。随笔的重点只是一行代码:
iDirX2*iDirZ1 - iDirX1*iDirZ2>0
这行代码参考的是二维向量共线定理:若设a=(x1,y1),b=(x2,y2),则有x1y2=x2y1。即与平行概念相同x1y2 - x2y1=0
另外,iMinDelta和iMaxDelta确实不符合我们的习惯,我们一般都习惯iMinValue和iMaxValue这样

《Focus On 3D Terrain Programming》中一段代码的注释二的更多相关文章

  1. 《Focus On 3D Terrain Programming》中一段代码的注释三

    取自<Focus On 3D Terrain Programming>中的一段: //--------------------------------------------------- ...

  2. 《Focus On 3D Terrain Programming》中一段代码的注释一

    取自<Focus On 3D Terrain Programming>中的一段: //--------------------------------------------------- ...

  3. 【鸡渣饲料系列】《Introdution to 3D Game Programming With DirectX11》 代码转移至vs2015

    <Introdution to 3D Game Programming With DirectX11>我是从这本书学习的directx,被称为“龙书”dx11版,由于是通过这本书学习的所以 ...

  4. bootstrap 中这段代码 使bundles 失败

    _:-ms-fullscreen, :root input[type="date"], _:-ms-fullscreen, :root input[type="time& ...

  5. SQL SERVER中如何查找存储过程中一段代码

    select b.name ,a.text from syscomments a,sysobjects b where and object_id(b.name)=a.id and b.xtype i ...

  6. phpstorm 代码注释后,撤销某段代码的注释的,快捷键是什么?

    phpstorm 的代码注释有两种风格,一种是双斜杠,另一种是 /* ...  */风格,两者的快捷键都是开关式(即按第一次为注释,再按一次为撤销注释),快捷键如下: 1.双斜杠注释   Ctrl + ...

  7. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第七章:在Direct3D中绘制(二)

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第七章:在Direct3D中绘制(二) 代码工程地址: https:/ ...

  8. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制 代码工程地址: https://gi ...

  9. Introduction to 3D Game Programming with DirectX 11 翻译--开篇

    Direct3D 11简介 Direct3D 11是一个渲染库,用于在Windows平台上使用现代图形硬件编写高性能3D图形应用程序.Direct3D是一个windows底层库,因为它的应用程序编程接 ...

随机推荐

  1. Hibernate 代码生成器

    Hibernate 代码生成器 点击Hibernate Code Generation 点击以下 创建管理代码生成配置 点击RUN.自动生成

  2. Selenium2学习-002-Selenium2 Web 元素定位及 XPath 编写演示示例

    此文主要对 Selenium2 的 Web 元素定位及 XPath 编写示例,敬请各位亲们参阅,共同探讨.若有不足之处,敬请各位大神指正,不胜感激! 通过 Firefox(火狐)浏览器的插件 Fire ...

  3. 我的工具箱之MyEclipse9.1

    下载地址:http://pan.baidu.com/s/1bbuN1s 这个工具是用来开发Java程序,自带JDK和Tomcat,功能全面周到,使用方便. 市面上MyEclipse版本很多,但都需要破 ...

  4. ByteBuffer

    1.堆内:HeapByteBuffer,在java的堆内创建. 缺点:可能引起堆的不断gc 写文件的时候需要先将堆的buffer写进直接buffer里,然后再写入文件 2.堆外:DirectByteB ...

  5. 解决git clone时报错:The requested URL returned error: 401 Unauthorized while accessing

    版本问题,最直接的解决办法就是重新编辑安装git吧: 1. 下载:# wget -O git.zip https://github.com/git/git/archive/master.zip 2. ...

  6. TCP/IP之TCP的建立与终止

    TCP协议简介 tcp/ip协议族中传输层最重要的两种协议是UDP和TCP协议,上一篇文章用很短的篇幅介绍完了UDP协议相关的内容,但相对于UDP而言的TCP协议,是种更复杂,应用更广的协议.在接下来 ...

  7. python urllib2 Basic认证

    1.通过添加http header 来实现 import urllib2 from base64 import encodestring url = 'http://202.108.1.51' use ...

  8. arm跑飞 分析

    当arm跑飞后,可以用ICE 追踪是哪边出错了: 1. 链接ICE, 修改Ice的mode,由 udf -> system. (因为跑飞了,在UDF) 2. 查看寄存器: LR对应callbac ...

  9. c# 基本知识 ref 和 out

    一:首先两者都是引用传递,都是按地址传递的. 二: 区别 (1)ref 默认必须初始化,out 不需要显式初始化.例如: ; int num2; refMethod(ref num1); outMet ...

  10. Java基础之线程——管理线程同步方法(BankOperation2)

    控制台程序. 当两个或多个线程共享同一资源时,例如文件或内存块,就需要采取措施,确保其中的一个线程不会修改另一个线程正在使用的资源.当其中的一个线程更新文件中的某个记录,同时另一个线程正在检索这个记录 ...