# Computing distance for LOD

This topic is 4878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm writing some code for basic LOD and detail mapping, and I want to get the distance between my camera and the chunk of terrain (or whatever else the object might be). Is there any other way to do this except to do the distance formula? I was thinking about just taking the distance between the camera and each quadtree node, but I may have a chunk of terrain that straddles the quadtree splitting line and that could screw things up. I guess my question is, how do most people do this? It seems costly to compute distance for each 33x33 chunk of a 1024x1024 terrain every frame.

##### Share on other sites
Just sort tiles into quadtree using its center coordinates. there should be no problem. btw computing distance for every tile is not a big deal. you do not even need to take care about all, but the visible ones (you should be able to find them through the quadtree). Once visible tiles found, calculate the distance square between the camera and each object. its 3 multiplications and 2 additions per tile. not a big deal...

##### Share on other sites
just in case you miss the subtile important word, i've quoted the above with some emphasis: =)

Quote:
 Original post by orbanocalculate the distance SQUARE between the camera and each object.

i.e. use distance squared instead of the actual distance. you'll still get a meaningful number without the expense of the sqrt function.

-me

##### Share on other sites
you could probably figure out a way to interpolate LOD values for each tile, instead of calculating each one individually.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631429
• Total Posts
3000033
×