java3d室外场景构建_3D室外场景的构建(1)----地形初步构建

1.2、构建三角形的顶点及索引数据

地形由一个个三角形面构成,可利用顶点索引构建三角形,三角形从左往右构建。

A |----- | B

|   /   |

C |/___ | D

先构建顶点数据:

float uCoordIncrementSize = 1.0f / (float)_numCellsPerRow;

float vCoordIncrementSize = 1.0f / (float)_numCellsPerCol;

TerrainVertex* v = 0;

_vb->Lock(0, 0, (void**)&v, 0);

for(int i = 0; i <_numvertsperrow i>

{

for(int j = 0; j < _numVertsPerCol; j++)

{

int index = i * _numVertsPerRow + j;

v[index] = TerrainVertex(

(float)j*_cellSpacing + startX,

(float)_heightmap[index],

(float)i*_cellSpacing + startZ,

0.0f,

1.0f,

0.0f,

(float)j * uCoordIncrementSize,

(float)i * vCoordIncrementSize);

}

}

_vb->Unlock();

再构建三角形索引:

WORD* indices = 0;

_ib->Lock(0, 0, (void**)&indices, 0);

int baseIndex = 0;

for(int i = 0; i < _numCellsPerCol; i++)

{

for(int j = 0; j < _numCellsPerRow; j++)

{

indices[baseIndex]     =   i   * _numVertsPerRow + j;

indices[baseIndex + 1] = (i+1) * _numVertsPerRow + j;

indices[baseIndex + 2] =   i   * _numVertsPerRow + j +1;

indices[baseIndex + 3] = (i+1) * _numVertsPerRow + j;

indices[baseIndex + 4] = (i+1) * _numVertsPerRow + j + 1;

indices[baseIndex + 5] =   i   * _numVertsPerRow + j + 1;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值