让Ogre的地形能自动产生连续随机高度的方法 用到libnoise 发现其生成函数似乎有些不合适
对其实用工具的一些改动
 1  void NoiseMapBuilderPlane::Build ()
 2  {
 3      if ( m_upperXBound <= m_lowerXBound
 4          || m_upperZBound <= m_lowerZBound
 5          || m_destWidth <= 0
 6          || m_destHeight <= 0
 7          || m_pSourceModule == NULL
 8          || m_pDestNoiseMap == NULL) 
 9      {
10          throw noise::ExceptionInvalidParam ();
11      }

12
13      // Resize the destination noise map so that it can store the new output
14      // values from the source model.
15      m_pDestNoiseMap->SetSize (m_destWidth, m_destHeight);
16
17      // Create the plane model.
18      model::Plane planeModel;
19      planeModel.SetModule (*m_pSourceModule);
20
21      double xExtent = m_upperXBound - m_lowerXBound;
22      double zExtent = m_upperZBound - m_lowerZBound;
23      double xDelta  = xExtent / (double)(m_destWidth-1) ;
24      double zDelta  = zExtent / (double)(m_destHeight-1);
25      double xCur    = m_lowerXBound;
26      double zCur    = m_lowerZBound;
27
28      // Fill every point in the noise map with the output values from the model.
29      for (int z = 0; z < m_destHeight; z++
30      {
31          if(z==m_destHeight-1)
32              zCur=m_upperZBound;
33          float* pDest = m_pDestNoiseMap->GetSlabPtr (z);
34          xCur = m_lowerXBound;
35          for (int x = 0; x < m_destWidth; x++)
36          {
37              if(x==m_destWidth-1)
38                  xCur = m_upperXBound;
39              float finalValue;
40
41              finalValue = planeModel.GetValue (xCur, zCur);
42              
43              *pDest++ = finalValue;
44              xCur += xDelta;
45          }

46          zCur += zDelta;
47          if (m_pCallback != NULL)
48          {
49              m_pCallback (z);
50          }

51      }

52  }

53

实现无缝的地形高度拼接
posted on 2012-11-27 09:51 野猪红 阅读(564) 评论(0)  编辑 收藏 引用 所属分类: Ogre

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理