Changeset 3202 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
- Timestamp:
- 12/01/08 16:50:13 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3201 r3202 61 61 62 62 63 const static int sNumIndicesPerBox= 20;63 const static int NUM_INDICES_PER_BOX = 20; 64 64 65 65 /* Order of vertices … … 548 548 else 549 549 { 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 550 562 renderedBoxes = PrepareBoundsWithDrawArrays(nodes); 551 563 RenderBoundsWithDrawArrays(renderedBoxes, state); … … 582 594 { 583 595 BvhNode *node = *nit; 584 const int numIndices = node->mNumTestNodes * sNumIndicesPerBox;596 const int numIndices = node->mNumTestNodes * NUM_INDICES_PER_BOX; 585 597 586 598 // copy indices 587 memcpy(mIndices + numNodes * sNumIndicesPerBox,599 memcpy(mIndices + numNodes * NUM_INDICES_PER_BOX, 588 600 mTestIndices + node->mIndicesPtr, 589 601 numIndices * sizeof(unsigned int)); … … 610 622 } 611 623 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; 614 626 // don't render first degenerate index 615 627 glDrawElements(GL_TRIANGLE_STRIP, numElements, GL_UNSIGNED_INT, mIndices + 1); … … 621 633 // collect bvh nodes 622 634 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); 624 640 625 641 cout << "creating new indices" << endl; … … 631 647 for (lit = nodes.begin(); lit != lit_end; ++ lit) 632 648 { 633 int offset = (*lit)->mNumTestNodes * sNumIndicesPerBox;649 int offset = (*lit)->mNumTestNodes * NUM_INDICES_PER_BOX; 634 650 #ifdef ALIGN_INDICES 635 651 // align with 32 in order to speed up memcopy … … 641 657 cout << "creating global indices buffer" << endl; 642 658 643 if (mIndices) delete [] mIndices;659 if (mIndices) delete [] mIndices; 644 660 if (mTestIndices) delete [] mTestIndices; 645 661 646 662 // global buffer: create it once so we don't have 647 // to allocate memory f rom the chunksof the node663 // to allocate memory for each individual chunk of the node 648 664 mIndices = new unsigned int[numMaxIndices]; 649 665 // create new index buffer for the individual nodes … … 662 678 // the bounding boxes of the test nodes are rendered instead of the node itself 663 679 // => 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) 665 681 { 666 682 BvhNode *testNode = mTestNodes[node->mTestNodesIdx + i]; 667 683 668 // add indices to root node669 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) 670 686 { 671 687 mTestIndices[mCurrentIndicesPtr + numIndices + j] = sIndices[j] + testNode->GetId() * 8; … … 732 748 BvhNode *node = *lit; 733 749 750 Vector3 v; 751 734 752 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 } 736 757 } 737 758 … … 1294 1315 else 1295 1316 { 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) 1297 1325 { 1298 1326 RenderBoxForViz(mTestNodes[node->mTestNodesIdx + i]->GetBox()); 1299 } 1327 }*/ 1300 1328 } 1301 1329
Note: See TracChangeset
for help on using the changeset viewer.