Terrain - Quadtrees

Started by
29 comments, last by _DarkWIng_ 19 years, 3 months ago
oh yeah, am using recursion to create the tree, didnt think of using it in the rendering. Thanks
Advertisement
Do people really use recursion when traversing trees in production software? Wouldn't it be faster to use your own stack instead of hacking the call stack? Or would it really make any difference?
I like the DARK layout!
Yeah, I fear the call stack so I use my own stack when going through the quadtree. I heard no one uses recursion in released software so I stopped using it.
If you're going to recurse a few levels, it's not a big deal. If your base chunk size is 17x17 on a 513x513 map, you're only going to recurse, what, 5 levels or so. That's fine. It's times when it may recurse dozens, hundreds or thousands of times that you should try to avoid it.
no i dont think either recursion is something to be avoided here. its not THAT time critical is it?

id use recursion, just because its prettier/shorter to code.
I have an odd question. I implemented a quadtree that from what I can test, doesnt care about the size being by 1 or 2. When I process my map I have it split the lowest nodes by dividing say 257 by 2. Which is 128.5 on both sides. If A triangle crosses that boundry either split it or render it depending on whatcha like. If your working with ints I can understand why it wouldnt work, but most terrain needs to be more exact than that doesnt it?

Paul7, I break my terrain up at compile time, and then send the triangles to the program with the size of the boundaries. so say the size is - 256 to 256, I simply cut at 0(the middle) at run time and walk the nodes (recursion) and place everything together. With vectors in the optimize compiler settings, it takes me roughly 5 seconds to load a large map. I dont think any1 would need it faster, but if so you can precompile every node then write your file output for that.

I upon compile time walk though the nodes and each triangle is linked to a index number(part of the structure) that is in the most child node. I simply say, if im at the child node, then it must be in view and add the vertex's index numbers to a dynamic index buffer. And continue through the nodes. Once this index is built I render the terrain. It might be slower than others, but again Its so damn fast for me I dont complain.
--X
Thanks for the help, Ive got all my boundaries defined now and in the tree but am just a bit stuck now as how to assosiate a chunk of terrain with each of the leaf nodes of the tree?

Also would it be better having a dynamic index buffer or a different index buffer for each leaf node? surely a dynamic one would be slower but lots of them will use more memory, dont no which is best!
If you organize your vertex memory like this:

A1----A2----A3B1----B2----B3|      |      |      |     | |      |      |      |     | |      |      |      |     | A4----A5----A6B4-----B5----B6|      |      |      |     | |      |      |      |     | |      |      |      |     | A7C1--A8C2--A9C7----B8-----B9


WHere A, B, C, etc is each leaf node, then your index order will be the same for each leaf, so you can use one index list and just change the pointer. Point to A, render vertex 1,4,2,5,3,6 then point to B render vertex 1, 4, 2, 5, 3 6.... etc.


THen if oyu need to go back and implement LOD, you can create a new index list and it will work on all your leaf nodes again.
Right so Ive got my quadtree all set up, if I draw all the leaf nodes I get the complete terrain which is what I want. I now have to implement frustum culling. The way ive got it is that each node of the quadtree defines a bounding box (2D) so I have to check the left, right, near and far clip clip planes of the view frustum again this, is this right? it shouldn't be 3D?

Anyone have any good resources on how to get the planes of the view frustum in DirectX?
Try this article.

This topic is closed to new replies.

Advertisement