Ignore:
Timestamp:
01/02/09 17:29:48 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter
Files:
3 edited

Legend:

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

    r3241 r3242  
    246246 
    247247        // update bvh bounding boxes with loaded geometry 
    248         UpdateNodeBox(mRoot); 
     248        UpdateBvh(mRoot); 
     249 
     250        cout << "bvh: " << mRoot->first << " " << mRoot->last << " bb: " << mRoot->box << endl; 
    249251 
    250252        cout << "writing scene" << endl; 
     
    331333                                default: 
    332334                                        sscanf(str + 1, "%f %f %f", &x, &y, &z); 
    333                                         //const float scale = 5e-3f; 
    334                                         const float scale = 0.1f; 
     335                                        const float scale = 1.0f; 
     336                                        //const float scale = 0.1f; 
    335337                                        tempVertices.push_back(CHCDemoEngine::Vector3(x * scale, y * scale, z * scale)); 
    336338                                        //cout <<"v " << x << " " << y << " "<< z << " "; 
     
    395397 
    396398                                        sscanf(str + 1, "%f %f %f", &x, &y, &z); 
    397                                         const float scale = 0.1f; 
     399                                        const float scale = 1.0f; 
    398400                                        vertices.push_back(CHCDemoEngine::Vector3(x * scale, y * scale, z * scale)); 
    399401                                        break; 
     
    558560        vector<TexCoord> _texCoords; 
    559561 
     562        CHCDemoEngine::AxisAlignedBox3 testBox; 
     563        testBox.Initialize(); 
     564 
     565        for (int i = 0; i < vertices.size(); ++ i) 
     566        { 
     567                testBox.Include(vertices[i]); 
     568        } 
     569 
     570        cout << "testbox: " << testBox << endl; 
     571 
    560572        mGeometry.reserve(mBvhLeaves.size()); 
    561573 
     
    580592                LoadShape(_vertices, _normals, _texCoords); 
    581593                 
    582                 node->geometry = mGeometry.back(); 
     594                // we store geometry in our bvh => change first and last pointer 
     595                // fromt triangles to geometry 
     596                node->first = (int)mGeometry.size() - 1; 
     597                node->last = (int)mGeometry.size() - 1; 
    583598 
    584599                _vertices.clear(); 
     
    639654        leaf->box.Initialize(); 
    640655 
    641         Geometry *geom = leaf->geometry; 
     656        Geometry *geom = mGeometry[leaf->first]; 
    642657 
    643658        for (size_t i = 0; i < geom->mVertexCount; ++ i) 
     
    842857        int nodeType; 
    843858 
    844         if (!node->IsLeaf()) 
     859        if (node->IsLeaf()) 
    845860                nodeType = TYPE_LEAF; 
    846861        else  
     
    856871 
    857872        stream.write(reinterpret_cast<char *>(&bMin), sizeof(CHCDemoEngine::Vector3)); 
    858         stream.write(reinterpret_cast<char *>(&bMin), sizeof(CHCDemoEngine::Vector3)); 
    859 } 
    860  
    861  
    862 void VisibilitySolutionConverter::UpdateNodeBox(BvhNode *node) 
     873        stream.write(reinterpret_cast<char *>(&bMax), sizeof(CHCDemoEngine::Vector3)); 
     874} 
     875 
     876 
     877void VisibilitySolutionConverter::UpdateBvh(BvhNode *node) 
    863878{ 
    864879        if (!node->IsLeaf()) 
    865880        { 
    866881                BvhInterior *interior = (BvhInterior *)node; 
     882 
     883                UpdateBvh(interior->front); 
     884                UpdateBvh(interior->back); 
     885 
     886                interior->first = min(interior->front->first, interior->back->first); 
     887                interior->last = max(interior->front->last, interior->back->last); 
     888                 
    867889                node->box = Union(interior->front->box, interior->back->box); 
    868  
    869                 UpdateNodeBox(interior->front); 
    870                 UpdateNodeBox(interior->back); 
    871890        } 
    872891        else 
    873892        { 
    874893                UpdateLeafBox((BvhLeaf *)node); 
     894                //cout << "bb: " << node->box << endl; 
    875895        } 
    876896} 
     
    883903 
    884904        if (!stream.is_open()) return NULL; 
    885  
    886         cout << "loading bvh" << endl; 
    887905 
    888906        WriteNextNode(stream, mRoot); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h

    r3241 r3242  
    6868struct BvhLeaf: public BvhNode 
    6969{ 
    70         Geometry *geometry; 
    71  
    72         BvhLeaf(): BvhNode(), geometry(NULL) {} 
     70        BvhLeaf(): BvhNode() {} 
    7371}; 
    7472 
     
    141139 
    142140        void UpdateLeafBox(BvhLeaf *leaf); 
    143  
    144         void UpdateNodeBox(BvhNode *node); 
     141        /** Prepare bvh for exporting. 
     142        */ 
     143        void UpdateBvh(BvhNode *node); 
    145144 
    146145 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp

    r3238 r3242  
    2323        } 
    2424         
    25         //std::cin.get(); 
    2625        cout << "conversion successful" << endl; 
     26 
     27        std::cin.get(); 
    2728 
    2829        return 0; 
Note: See TracChangeset for help on using the changeset viewer.