CTerrainSceneNode

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Qps
Posts: 18
Joined: Thu Jan 27, 2011 2:02 pm

CTerrainSceneNode

Post by Qps »

Hi,

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);
I believe could be simplified to:

Code: Select all

const f32 distance =cameraPosition.getDistanceFromSQ(TerrainData.Patches[j].Center);
Also

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;
  }
}
I believe could be simplified to:

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;
  }
}
Last edited by Qps on Fri Aug 05, 2011 12:48 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: CTerrainSceneNode

Post by hybrid »

I think the second approach won't work as the distance for threshold 0 can be positive. But it can be easily set to 0 before the loop, and only test for larger thresholds. I will run the test suite and commit this later on.
Qps
Posts: 18
Joined: Thu Jan 27, 2011 2:02 pm

Re: CTerrainSceneNode

Post by Qps »

Of course your right missed that Ill update my first post.
Post Reply