vtlib contains several CLOD terrain implementations.
You can plug your own algorithm into the vtlib framework. There are only a few constraints that it must obey:
- It will be initialized with a regular grid heightfield
- It must store its own representation of the heightfield data
- It must be able to render itself making calls to OpenGL
Here are the steps to adding your own algorithm:
\TerrainSDK\vtlib\core,copy the sample implementation modules (
Give them your own name (e.g.
Add the new files to the
In the files, replace
"CustomTerrain"with the name of your terrain class.
,copy the provided heightfield values into your own data structures.
,compute which detail will actually get drawn.
,call OpenGL to draw your data
There are some useful things your algorithm will inherit from its parent class:
The desired detail level will be contained in these two fields:
float m_fPixelError; // e.g. 2.0 pixels of errorYou can use whichever is appropriate for your algorithm.
int m_iPolygonTarget; // e.g. 10000 triangles
PostRender()will take care of the OpenGL state for you, so you don't have to worry about it.
4 forms of the function
IsVisible()will test your triangle, sphere, or point against the view frustum - see
Here are the steps to making the VTP framework aware of your module:
vtlib/core/Terrain.h,add your header, e.g.
vtlib/core/TParams.h,add a line to
enum LodMethodEnum, e.g.
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");
Enviro/wx/TParamsDlg.cpp, in TParamsDlg::OnInitDialog,add a line like this after the other LOD methods: