Ignore:
Timestamp:
01/15/09 18:28:11 (15 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r3269 r3280  
    3939mMaxTriangles(1), 
    4040mNumNodes(0), 
    41 mSplitType(SAH) 
     41//mSplitType(SAH) 
     42mSplitType(SAH_OR_SIZE) 
    4243{ 
    4344} 
     
    282283        return k; 
    283284} 
     285 
     286 
     287int BvhConstructor::SortTrianglesSurfaceArea(BvhLeaf *leaf, float sa) 
     288{ 
     289        int i = leaf->mFirst; 
     290        int j = leaf->mLast; 
     291 
     292        while(1)  
     293        { 
     294                while ((i <= j) && (mEntities[i]->GetWorldBoundingBox().SurfaceArea() < sa))  
     295                        ++ i; 
     296 
     297                while ((i <= j) && (sa < mEntities[j]->GetWorldBoundingBox().SurfaceArea())) 
     298                        -- j; 
     299 
     300                if (i < j)  
     301                { 
     302                        swap(mEntities[i], mEntities[j]); 
     303                        ++ i; 
     304                        -- j; 
     305                } 
     306                else 
     307                        break; 
     308        } 
     309 
     310        return j; 
     311} 
     312 
    284313 
    285314 
     
    333362                } 
    334363                break; 
     364        case SAH_OR_SIZE:  
     365                { 
     366                        // split by size instead 
     367                        const float saThreshold = 0.2f * leaf->GetBox().SurfaceArea(); 
     368                        split = SortTrianglesSurfaceArea(leaf, saThreshold); 
     369 
     370                        if ((split == leaf->mLast) || (split == leaf->mFirst - 1))  
     371                        { 
     372                                // use SAH 
     373                                float cost; 
     374                                pos = SelectPlaneSah(leaf, axis, cost); 
     375 
     376                                if (pos != MAX_FLOAT) 
     377                                        split = SortTriangles(leaf, axis, pos); 
     378                                else 
     379                                        split = SortTrianglesObjectMedian(leaf, axis, pos); 
     380                        } 
     381                        else 
     382                        { 
     383                                // note: no position is computed!! 
     384                                //OUT1("sorted by size"); 
     385                        } 
     386                } 
     387                break; 
    335388        default: 
    336389                cerr << "should not come here" << endl; 
Note: See TracChangeset for help on using the changeset viewer.