Ignore:
Timestamp:
12/01/08 16:50:13 (16 years ago)
Author:
mattausch
Message:

finally found bvh tighter bounds bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r3201 r3202  
    6161 
    6262 
    63 const static int sNumIndicesPerBox = 20; 
     63const static int NUM_INDICES_PER_BOX = 20; 
    6464 
    6565/*      Order of vertices 
     
    548548        else 
    549549        { 
     550                BvhNodeContainer::const_iterator nit, nit_end = nodes.end(); 
     551 
     552                /*for (nit = nodes.begin(); nit != nit_end; ++ nit) 
     553                { 
     554                        BvhNode *node = *nit; 
     555 
     556                        for (int i = 0; i < node->mNumTestNodes; ++ i) 
     557                        { 
     558                                RenderBoundingBoxImmediate(mTestNodes[node->mTestNodesIdx + i]->GetBox()); 
     559                        } 
     560                }*/ 
     561 
    550562                renderedBoxes = PrepareBoundsWithDrawArrays(nodes); 
    551563                RenderBoundsWithDrawArrays(renderedBoxes, state); 
     
    582594        { 
    583595                BvhNode *node = *nit; 
    584         const int numIndices = node->mNumTestNodes * sNumIndicesPerBox; 
     596        const int numIndices = node->mNumTestNodes * NUM_INDICES_PER_BOX; 
    585597                 
    586598                // copy indices 
    587                 memcpy(mIndices + numNodes * sNumIndicesPerBox,  
     599                memcpy(mIndices + numNodes * NUM_INDICES_PER_BOX,  
    588600                           mTestIndices + node->mIndicesPtr,  
    589601                           numIndices * sizeof(unsigned int)); 
     
    610622        } 
    611623 
    612         // we do use the last or the first index (they are generate and only used to connect strips) 
    613         int numElements = numNodes * sNumIndicesPerBox - 1; 
     624        // we don't use the last or the first index (they are generate and only used to connect strips) 
     625        int numElements = numNodes * NUM_INDICES_PER_BOX - 1; 
    614626        // don't render first degenerate index 
    615627        glDrawElements(GL_TRIANGLE_STRIP, numElements, GL_UNSIGNED_INT, mIndices + 1);  
     
    621633        // collect bvh nodes 
    622634        BvhNodeContainer nodes; 
    623         CollectNodes(mRoot, nodes); 
     635        // first collect dynamic nodes so we make sure that they are in the beginning 
     636        CollectNodes(mDynamicRoot, nodes); 
     637        // then collect static nodes 
     638        CollectNodes(mStaticRoot, nodes); 
     639        //CollectNodes(mRoot, nodes); 
    624640 
    625641        cout << "creating new indices" << endl; 
     
    631647        for (lit = nodes.begin(); lit != lit_end; ++ lit) 
    632648        { 
    633                 int offset = (*lit)->mNumTestNodes * sNumIndicesPerBox; 
     649                int offset = (*lit)->mNumTestNodes * NUM_INDICES_PER_BOX; 
    634650#ifdef ALIGN_INDICES 
    635651                // align with 32 in order to speed up memcopy 
     
    641657        cout << "creating global indices buffer" << endl; 
    642658 
    643         if (mIndices) delete [] mIndices; 
     659        if (mIndices)     delete [] mIndices; 
    644660        if (mTestIndices) delete [] mTestIndices; 
    645661 
    646662        // global buffer: create it once so we don't have 
    647         // to allocate memory from the chunks of the node 
     663        // to allocate memory for each individual chunk of the node 
    648664        mIndices = new unsigned int[numMaxIndices]; 
    649665        // create new index buffer for the individual nodes 
     
    662678                // the bounding boxes of the test nodes are rendered instead of the node itself 
    663679                // => store their indices 
    664                 for (int i = 0; i < node->mNumTestNodes; ++ i, numIndices += sNumIndicesPerBox) 
     680                for (int i = 0; i < node->mNumTestNodes; ++ i, numIndices += NUM_INDICES_PER_BOX) 
    665681                { 
    666682                        BvhNode *testNode = mTestNodes[node->mTestNodesIdx + i]; 
    667683 
    668                         // add indices to root node 
    669                         for (int j = 0; j < sNumIndicesPerBox; ++ j) 
     684                        // add vertex indices of boxes to root node 
     685                        for (int j = 0; j < NUM_INDICES_PER_BOX; ++ j) 
    670686                        { 
    671687                                mTestIndices[mCurrentIndicesPtr + numIndices + j] = sIndices[j] + testNode->GetId() * 8; 
     
    732748                BvhNode *node = *lit; 
    733749 
     750                Vector3 v; 
     751 
    734752                for (int j = 0; j < 8; ++ j) 
    735                         (static_cast<Vector3 *>(mVertices))[node->GetId() * 8 + j] = node->GetBox().GetVertex(j); 
     753                { 
     754                        node->GetBox().GetVertex2(j, v); 
     755                        (static_cast<Vector3 *>(mVertices))[node->GetId() * 8 + j] = v; 
     756                } 
    736757        } 
    737758 
     
    12941315        else 
    12951316        { 
    1296                 for (int i = 0; i < node->mNumTestNodes; ++ i) 
     1317                glPolygonMode(GL_FRONT, GL_LINE); 
     1318                BvhNodeContainer nodes; 
     1319                nodes.push_back(node); 
     1320                int renderedBoxes = PrepareBoundsWithDrawArrays(nodes); 
     1321                RenderBoundsWithDrawArrays(renderedBoxes, state); 
     1322                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
     1323 
     1324                /*for (int i = 0; i < node->mNumTestNodes; ++ i) 
    12971325                { 
    12981326                        RenderBoxForViz(mTestNodes[node->mTestNodesIdx + i]->GetBox()); 
    1299                 } 
     1327                }*/ 
    13001328        } 
    13011329 
Note: See TracChangeset for help on using the changeset viewer.