[osg-users] generate height map using fractal

Paul Martz pmartz at skew-matrix.com
Sun Mar 22 15:27:29 PDT 2009

Wow. That article is like 13 years old. I think I wrote it with VC4 and
OpenGL 1.1.
As a debugging technique, try to separate the heightfield population
algorithm from the rendering issue. For example, try populating the
heightfield with an array of linearly increasing values and see if it
renders as you would expect. If it still renders wrong, then you know the
fractal algorithm isn't to blame and the problem is probably with how you
are using OSG. As a result, you'll have a much simpler example to post here.
I'd also suggest using Geometry instead of some other Drawable, as Geometry
is more flexible (you can run them through the Simplifier, for example).
Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com <http://www.skew-matrix.com/> 
+1 303 859 9466


From: osg-users-bounces at lists.openscenegraph.org
[mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of ami guru
Sent: Sunday, March 22, 2009 7:46 AM
To: OpenSceneGraph Users
Subject: [osg-users] generate height map using fractal

Hello forum,

I have been using the Paul's article about generating terrain using fractals


I am populating the values in the osg height map structure.

But The rendering is giving me a flat surface.

I hope that Paul sees that as well.


  osg::ref_ptr<osg::Geode> myTerrain = new osg::Geode;

  //Now load the terrain

  osg::ref_ptr<osg::Node> terrainNode (osgDB::readNodeFile("Terrain2.3ds"));

  //generate the 2D fractal
  float *heightData = alloc2DFractArray(512);

  //Define some constants for the fractal terrain
  static const float DEF_HEIGHT_SCALE = 0.1f;
  static float TILING_SURFACE = 3;
  int randomSeed = 1;
  float H = 0.3;
  float iteration = 10;

  fill2DFractArray (heightData,512, randomSeed,DEF_HEIGHT_SCALE,H);
  //using the height field
  osg::ref_ptr<osg::HeightField> heightMap = new osg::HeightField;

  //allocate the space for the height field

  //populate the height map
  for(unsigned int i = 0; i < heightMap->getNumColumns();i++)
      for(unsigned int j = 0; j < heightMap->getNumRows();j++)
      int size = heightMap->getNumRows();

      //std::cout << heightMap->getHeight(i,j) << std::endl;

  //now add the drawable to  the terain
  myTerrain->addDrawable(new osg::ShapeDrawable(heightMap.get()));




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20090322/f6852408/attachment-0003.htm>

More information about the osg-users mailing list