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:
In
\TerrainSDK\vtlib\core,
copy the sample implementation modules (BruteTerrain.cpp, BruteTerrain.h
)
Give them your own name (e.g.MyTerrain.cpp, MyTerrain.h
)Add the new files to the
vtosg
project.In the files, replace
"CustomTerrain"
with the name of your terrain class.in
MyTerrain::Init
,
copy the provided heightfield values into your own data structures.in
MyTerrain::DoCulling
,
compute which detail will actually get drawn.in
MyTerrain::
RenderSurface
,
call OpenGL to draw your dataThere 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 error
You can use whichever is appropriate for your algorithm.
int m_iPolygonTarget; // e.g. 10000 triangles
PreRender()
andPostRender()
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 - seeCustomTerrain.cpp
for details.Here are the steps to making the VTP framework aware of your module:
in
vtlib/core/Terrain.h,
add your header, e.g.
#include "MyTerrain.h"
in
vtlib/core/TParams.h,
add a line toenum LodMethodEnum
, e.g.
LM_MYTERRAIN
in
vtlib/core/Terrain.cpp,
in the functionvtTerrain::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");
}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!