Question

Im currently implementing an Octree for my bachelor thesis project. My Octree takes a std::vector as argument:

octree::Octree::Octree(std::vector<const D3DXVECTOR3*> vec) : 
    m_vertices(std::vector<D3DXVECTOR3*>()),
    m_size(m_vertices.size())
{
    int i=0;
    for(;i<m_size;++i) {
        m_vertices.push_back(new D3DXVECTOR3(*vec.at(i)));
    }
}

Im asking for what is typically used to store the vertices in before rendering them and making any culling test etc to them.

I kept this very simple for now, all i have is a function that renders a grid. Some snippets:

#define GRIDFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)

struct GridVertex {
    D3DXVECTOR3 position; 
    DWORD color;
};


g_dev->SetTransform(D3DTS_WORLD, &matIdentity);
g_dev->SetStreamSource(0, g_buffer, 0, sizeof(GridVertex));
g_dev->SetTexture(0, NULL);
g_dev->DrawPrimitive(D3DPT_LINELIST, 0, GridSize * 4 + 2);

Now when rendering this i use my custom struct GridVertex, thats saves a D3DXVECTOR9 for pos and a DWORD for the color value and the tell the GPU by setting the flexible vertex format to GRIDFVF. But in my Octree i only want to store the positions to perform the test if certain vertices are inside nodes within my Octree and so on. Therefore I thought of creating another class called SceneManager and storing all values within an std::vector and finally pass it to my Octree class, that does the test and afterwards pass the checked vertices to the GPU. Would this be a solid solution or whats common to implement something like this? Thanks in advance

Was it helpful?

Solution

Generally, one does not put the actual render geometry vertices themselves in the octree or whatever spatial partitioning structure one uses. That level of granularity is not useful, because if a set of vertices that make up a model spans partition nodes such that some subset of those vertices would be culled, you couldn't properly draw the model.

What you'd typically want to do is have an object representing an entity and its bounds within the world (axis-oriented bounding boxes, or bounding spheres, are simple and efficient bounding volumes, for example). Each entity is also associated with (or can be associated with by some other subsystem) rendering geometry. The entities themselves are sorted within the octree.

Then, you use your octree to determine which entities are visible, and submit all of their associated render geometry to the card.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top