I was looking into the CTerrainSceneNode, I found a few lines of code which could be simplified:
line 629:
Code: Select all
const f32 distance = (cameraPosition.X - TerrainData.Patches[j].Center.X) * (cameraPosition.X - TerrainData.Patches[j].Center.X) +
(cameraPosition.Y - TerrainData.Patches[j].Center.Y) * (cameraPosition.Y - TerrainData.Patches[j].Center.Y) +
(cameraPosition.Z - TerrainData.Patches[j].Center.Z) * (cameraPosition.Z - TerrainData.Patches[j].Center.Z);
Code: Select all
const f32 distance =cameraPosition.getDistanceFromSQ(TerrainData.Patches[j].Center);
line 633:
Code: Select all
for (s32 i = TerrainData.MaxLOD - 1; i >= 0; --i)
{
if (distance >= TerrainData.LODDistanceThreshold[i])
{
TerrainData.Patches[j].CurrentLOD = i;
break;
}
//else if (i == 0)
{
// If we've turned off a patch from viewing, because of the frustum, and now we turn around and it's
// too close, we need to turn it back on, at the highest LOD. The if above doesn't catch this.
TerrainData.Patches[j].CurrentLOD = 0;
}
}
Code: Select all
//Start with highest LOD
TerrainData.Patches[j].CurrentLOD = 0;
for(s32 i = 0; i < TerrainData.MaxLOD; ++i)
{
if(distance <= TerrainData.LODDistanceThreshold[i])
{
TerrainData.Patches[j].CurrentLOD = i;
break;
}
}