I was thinking hove to add LOD support for my terrain scene nodes and hove this LOD should work. And I came with idea of kind of flexible tile which can be subdivided in to four smaller tiles and those can be subdivided further. All on run time of course. In such a way unlimited number of LODs can be created and more importantly LOD can be used in different ways. Except classical further away from camera = less detail I especially like idea of putting detail only where needed. Flat parts can consist of smaller number of large tiles while other parts can get more smaller tiles.
This idea was written in to class with work name of FlexibleTile. It is template in fact so it can use any vertex format. Rest is developed around this class ...or better say should be. Code which I provide here is mostly for testing.
Small demonstration program: demo source files
Flexible tile class:
Code: Select all
template <class T> class FlexiTile
{
protected:
T Vertex[4];
FlexiTile *SubTile[4];
public:
FlexiTile()
{
for(u32 i=0; i<4; i++) SubTile[i] = NULL;
}
~FlexiTile()
{
if(isSubdivided())
for(u32 i=0; i<4; i++) delete SubTile[i];
}
virtual void subDivide()
{
for(u32 i=0; i<4; i++) SubTile[i] = new FlexiTile;
}
virtual void unifi()
{
if(isSubdivided())
for(u32 i=0; i<4; i++)
{
SubTile[i]->unifi();
delete SubTile[i];
SubTile[i] = NULL;
}
}
virtual bool isSubdivided()
{
if(SubTile[0]) return true;
return false;
}
virtual u32 getTileCount()
{
s32 count = 0;
if(isSubdivided())
for(u32 i=0; i<4; i++) count += SubTile[i]->getTileCount();
else
count = 1;
return count;
}
virtual u32 getVertexCount()
{
s32 count = 0;
if(isSubdivided())
for(u32 i=0; i<4; i++) count += SubTile[i]->getVertexCount();
else
count = 4;
return count;
}
virtual FlexiTile& getSubtile(TILE_CORNER position)
{
return *SubTile[position];
}
virtual T getVertex(TILE_CORNER corner)
{
T vertex;
if(isSubdivided()) vertex = SubTile[corner]->getVertex(corner);
else vertex = Vertex[corner];
return vertex;
}
virtual void assignVertex(T vertex, TILE_CORNER corner)
{
Vertex[corner] = vertex;
if(isSubdivided()) SubTile[corner]->assignVertex(vertex, corner);
}
};