The main reason I believe an octree should ever be used for terrain, imo, is not rendering, but collision detection, line of sight, etc (all my comments reguading them assume this). Drawing clusters of only a few triangles at a time is never going to be very efficient, especially when you want to start using the processor for other, more important things. Using blocks of, say, 64 triangles is, imo, more a lot more efficient, and you can do nice stuff like occlusion culling, vertex cache optimizations, using a single index array, triangle strips, etc. It''s very hard to optimize terrain rendering through a octree above the level generic triangles..
And, also, when using a 1d height map (3d is a different story - or a true mesh) a quad tree with verticle bounds is usually a better option.
anyway, enough of that,
ok.
consider this.
you have a tree node cube, somewhere. Where it is doesn''t really matter. Size also doesn''t matter.
there are 10 triangles inside it, say. (based on their rough centre)
Now.
some are completly inside the cube. Which is good. Some arn''t.
If they jut out very slightly, it would be easy to calculate how far they jut out. Because if a vertex is 1 unit outside the cube on the x-axis, then, well, the triangle juts out 1 unit... etc.
So,
what you do,
is go through all the triangles, and test if the verticies of all are outside the cube.
If they are, you store HOW FAR they extend over the edge, for all 6 sides of the cube. Ie, +
Simply store this in 2 vectors.
I''ll refer to these vectors as the bounds from now on.
Before you know it, you now have 2 verticies outside (or on the edges) of the cube. These 2 vectors discribe a rectangular volume. Or, if no triangles jutted out, they discribe the original cube.
So, now, you have the real volume of the triangles inside the octree node.
But, the parent nodes still need this info, So, traverse up the tree, and, obviously, set the bounds for each of these nodes too. (but base it on the child node bounds - not the child data).
If there are any utterly enormous triangles it may be wise to clip those, but they would have to be extreme. (or simply stick them in thier own node).
