取自《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. 安装MVC3后没有dbcontext生成器的解决方案

    安装MVC3后,采用DBFIRS的方式,从数据库生成模型,这样生成的类是基于ObjectContext的,无法使用DbContext的一些方法,比如Set.Find.Entry等.需要用ADO.NET ...

  2. [LeetCode]题解(python):118-Excel Sheet Column Title

    题目来源 https://leetcode.com/problems/excel-sheet-column-title/ Given a positive integer, return its co ...

  3. jQuery获取自身HTML

    <html><head> <title>jQuery获取自身HTML</title> <meta http-equiv="Content ...

  4. mysql中varchar(50)最多能存多少个汉字

    首先要确定mysql版本4.0版本以下,varchar(50),指的是50字节,如果存放UTF8汉字时,只能存16个(每个汉字3字节) 5.0版本以上,varchar(50),指的是50字符,无论存放 ...

  5. LeetCode Perfect Squares

    原题链接在这里:https://leetcode.com/problems/perfect-squares/ 题目: Given a positive integer n, find the leas ...

  6. js基础的总结

    js中的每个函数都含有一个内建的arguments数组,能够返回函数接受的所有参数,不管函数有没有定义参数. function add() { var sum = 0; for (var i = 0; ...

  7. 在定位中,如何清除已经设置好的bottom

    这个东西其实很简单,将bottom设auto,便可在设置top的值,那么具体的应用是什么?目前一个是用于全屏,二是用于输入框在手机端的下半屏(被输入发遮挡问题)? 例子如下 css代码: * { ma ...

  8. JQuery:JQuery设置HTML

    JQuery:设置HTML1.Query - 设置内容和属性设置内容 - text().html() 以及 val()我们将使用前一章中的三个相同的方法来设置内容: text() - 设置或返回所选元 ...

  9. 判断远程图片是否存在【适用于windows服务器】

    <?php function file_exists2($url) { if(@file_get_contents($url,0,null,0,1)) return 1; else return ...

  10. 第四篇 Integration Services:增量加载-Updating Rows

    本篇文章是Integration Services系列的第四篇,详细内容请参考原文. 回顾增量加载记住,在SSIS增量加载有三个使用案例:1.New rows-add rows to the dest ...