
I’d probably make a triangle struct containing an array of three points, then keep an std::vector of triangles. This allows you to add additional data like normals and UVs later.

Rather than storing a list of triangles in every kdtree node  which will lead to a lot of duplicated data in memory and cache thrashing  I would rather keep all the triangles in a vector, and sort it as you build the kdtree, so that the triangles in a single node are adjacent to each other in the vector. Then in the node, you can just store the beginning and ending indices where its triangles are in the vector. This will be a trickier data structure to build, but it will be worth it when rendering complicated scenes, as it will greatly improve performance.
It’s also a neat trick to store the kdtree nodes in an array in a similarly sorted order. The root node is at element 1 (element 0 is unused) and for any given node, if it’s at element N in the array, then its two children are at 2N and 2N+1. So the root is at 1, its children are 2 and 3, their children are 4, 5, 6, and 7, and so on. Keeping the nodes together in an array like this will also yield performance gains. And it removes the need for a node to store pointers to its child or parent nodes.
Hi, im currently working in a very simple C implementation of a Ray Tracer; basically all I have to do is, given a set of triangles and a ray, find out where is the intersection point if it exists. I have some questions regarding the design and handling of some stuff (I’m gonna use a kdtree to manage the tracing):
1) What is a good way to store the triangles? I made a “Point” structure to store the x, y, z coordinates of a point. Would a Point vector be a good idea?
2) What should the kdtree structure contain? I’ve read some papers and that could be the set of triangles (and maybe the quantity), the bounding box, the left and right nodes, maybe a leaf flag, maybe some depth indicator. Am I missing anything?
Thanks in advance.