LOD Calculations?

Blitz3D Forums/Blitz3D Beginners Area/LOD Calculations?

There's no way you're going to have enough entities in your scene that you need to worry about optimizing a distance check to each one. Even if you had a thousand entities, that's only a thousand square roots each frame, which on today's PC's is nothing.

But if you are that concerned about it, it's trivial to optimize out the square root simply by calculating the square of the distance and using that instead.

Let's say the max distance your first LOD should be visible is 100 meters. You can easily calculate the LOD to use like so:

MinDist# = 100

Exyz = Entity xyz
Cxyz = Camera xyz

DistSquared# = (Ex#-Cx#)^2 + (Ey#-Cy#)^2 + (Ez#-Cz#)^2

LOD = 4
For Loop = 0 to 4
  If DistSquared# < (MinDist# * 2^Loop)^2
     LOD = Loop
     Exit
   EndIf
Next