vtlib Continuous LOD (CLOD)

vtlib contains several CLOD terrain implementations.




Adding Your Own Terrain Rendering Algorithm

You can plug your own algorithm into the vtlib framework.  There are only a few constraints that it must obey:

  1. It will be initialized with a regular grid heightfield
  2. It must store its own representation of the heightfield data
  3. It must be able to render itself making calls to OpenGL

Here are the steps to adding your own algorithm:

  1. In \TerrainSDK\vtlib\core, copy the sample implementation modules (BruteTerrain.cpp, BruteTerrain.h)
    Give them your own name (e.g. MyTerrain.cpp, MyTerrain.h)

  2. Add the new files to the vtosg project.

  3. In the files, replace "CustomTerrain" with the name of your terrain class.

  4. in MyTerrain::Init, copy the provided heightfield values into your own data structures.

  5. in MyTerrain::DoCulling, compute which detail will actually get drawn.

  6. in MyTerrain::RenderSurface, call OpenGL to draw your data

There are some useful things your algorithm will inherit from its parent class:

  1. The desired detail level will be contained in these two fields:
    float m_fPixelError;    // e.g. 2.0 pixels of error
    int m_iPolygonTarget;    // e.g. 10000 triangles
    You can use whichever is appropriate for your algorithm.

  2. PreRender() and PostRender() will take care of the OpenGL state for you, so you don't have to worry about it.

  3. 4 forms of the function IsVisible() will test your triangle, sphere, or point against the view frustum - see CustomTerrain.cpp for details.

Here are the steps to making the VTP framework aware of your module:

  1. in vtlib/core/Terrain.h, add your header, e.g.
    #include "MyTerrain.h"

  2. in vtlib/core/TParams.h, add a line to enum LodMethodEnum, e.g.

  3. in vtlib/core/Terrain.cpp, in the function vtTerrain::create_dynamic_terrain, add a case like this:

    if (m_Params.m_eLodMethod == LM_MYTERRAIN)
      m_pDynGeom = new MyTerrain();
      m_pDynGeom->SetName2("My Terrain Shape");

  4. in Enviro/wx/TParamsDlg.cpp, in TParamsDlg::OnInitDialog, add a line like this after the other LOD methods:
      m_pLodMethod->Append("My Algorithm");

That's it!