Changeset 3070 for GTP


Ignore:
Timestamp:
10/26/08 18:29:27 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
23 edited

Legend:

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

    r3012 r3070  
    2828 
    2929 
    30 SimpleVec SimpleTri::GetCenter() const  
     30SimpleVec SimpleTri::GetWorldCenter() const  
    3131{ 
    3232        return (mVertices[0] + mVertices[1] + mVertices[2]) / 3.0f; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/SimpleTri.h

    r3012 r3070  
    1515        SimpleVec GetNormal() const; 
    1616 
    17         SimpleVec GetCenter() const; 
     17        SimpleVec GetWorldCenter() const; 
    1818 
    1919        float GetSpatialAngle(const SimpleVec &point) const; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp

    r3065 r3070  
    15051505 
    15061506 
    1507 } 
    1508  
     1507int AxisAlignedBox3::MajorAxis() const 
     1508{ 
     1509        const Vector3 sizeVec = mMax - mMin; 
     1510 
     1511        int axis; 
     1512 
     1513        if (sizeVec.x > sizeVec.y) axis = (sizeVec.x > sizeVec.z) ? 0 : 2; 
     1514        else axis = (sizeVec.y > sizeVec.z) ? 1 : 2; 
     1515 
     1516        return axis; 
     1517} 
     1518 
     1519 
     1520} 
     1521 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h

    r2951 r3070  
    6565 
    6666        float Size(const int axis) const; 
    67  
    68         // Read-only const access tomMin and max vectors using references 
     67        /** Returns axis where box has largest extent. 
     68        */ 
     69        int MajorAxis() const; 
     70        /** Read-only const access tomMin and max vectors using references 
     71        */ 
    6972        const Vector3& Min() const; 
    7073        const Vector3& Max() const; 
     
    9194        float Radius() const { return 0.5f * Magnitude(Size()); } 
    9295        float SqrRadius() const { return 0.5f * SqrMagnitude(Size()); } 
    93  
    94         // Return whether the box is unbounded.  Unbounded boxes appear 
    95         // when unbounded objects such as quadric surfaces are included. 
     96        /** Return whether the box is unbounded.  Unbounded boxes appear 
     97                when unbounded objects such as quadric surfaces are included. 
     98        */ 
    9699        bool Unbounded() const; 
    97100 
     
    127130        */ 
    128131        void Scale(float scale); 
    129  
     132        /** Scale box non-uniformally 
     133        */ 
    130134        void Scale(const Vector3 &scale); 
    131135        /** Translates the box with the factor. 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r3069 r3070  
    151151 
    152152 
     153 
     154inline AxisAlignedBox3 ComputeBoundingBox(SceneEntity **entities, int numEntities) 
     155{ 
     156        AxisAlignedBox3 box = entities[0]->GetWorldBoundingBox(); 
     157 
     158        for (int i = 1; i < numEntities; ++ i) 
     159        { 
     160                box.Include(entities[i]->GetWorldBoundingBox()); 
     161        } 
     162 
     163        return box; 
     164} 
     165 
     166 
    153167Bvh::Bvh() 
    154168{ 
     
    419433        if (!mDynamicEntities.empty()) 
    420434        { 
    421                 UpdateDynamicBranch(); 
     435                if (!mDynamicRoot) 
     436                        CreateDynamicBranch(); 
     437                 
     438                UpdateDynamicBranch(mDynamicRoot); 
    422439        } 
    423440} 
     
    448465        { 
    449466                SceneEntity *ent = entities[i]; 
    450                 float dist = ent->GetTransformedBoundingBox().GetMaxDistance(sNearPlane); 
     467                float dist = ent->GetWorldBoundingBox().GetMaxDistance(sNearPlane); 
    451468 
    452469                if (dist > maxDist) maxDist = dist; 
     
    800817 
    801818 
    802 void Bvh::ComputeBvhStats()  
    803 { 
     819void Bvh::ComputeBvhStats(BvhNode *root, BvhStats &bvhStats)  
     820{ 
     821        bvhStats.Reset(); 
    804822        std::stack<BvhNode *> nodeStack; 
    805         nodeStack.push(mRoot); 
     823        nodeStack.push(root); 
    806824 
    807825        int numVirtualLeaves = 0; 
     826        int numGeometry = 0; 
    808827 
    809828        while (!nodeStack.empty())  
     
    815834                { 
    816835                        ++ numVirtualLeaves; 
     836                        numGeometry += node->CountPrimitives(); 
    817837 
    818838                        BvhLeaf *leaf = static_cast<BvhLeaf *>(node); 
    819839 
    820                         mBvhStats.mTriangles += CountTriangles(leaf); 
    821                         mBvhStats.mLeafSA += leaf->mBox.SurfaceArea(); 
    822                         mBvhStats.mLeafVol += leaf->mBox.GetVolume(); 
     840                        bvhStats.mTriangles += CountTriangles(leaf); 
     841                        bvhStats.mLeafSA += leaf->mBox.SurfaceArea(); 
     842                        bvhStats.mLeafVol += leaf->mBox.GetVolume(); 
    823843                }  
    824844                else  
    825845                { 
    826                         mBvhStats.mInteriorSA += node->mBox.SurfaceArea(); 
    827                         mBvhStats.mInteriorVol += node->mBox.GetVolume(); 
     846                        bvhStats.mInteriorSA += node->mBox.SurfaceArea(); 
     847                        bvhStats.mInteriorVol += node->mBox.GetVolume(); 
    828848 
    829849                        BvhInterior *interior = static_cast<BvhInterior *>(node); 
     
    834854        } 
    835855 
    836         mBvhStats.mGeometryRatio = mGeometrySize / (float)numVirtualLeaves; 
    837         mBvhStats.mTriangleRatio = mBvhStats.mTriangles / (float)numVirtualLeaves; 
    838 } 
    839  
    840  
    841 void Bvh::PrintBvhStats() const 
    842 { 
    843         cout << "\n******** bvh stats: ***********" << endl; 
    844         cout << "interiorNodesSA = " << mBvhStats.mInteriorSA / mRoot->mBox.SurfaceArea() << endl; 
    845         cout << "leafNodesSA = " << mBvhStats.mLeafSA / mRoot->mBox.SurfaceArea() << endl; 
    846         cout << "interiorNodesVolume = " << mBvhStats.mInteriorVol / mRoot->mBox.GetVolume() << endl; 
    847         cout << "leafNodesVolume = " << mBvhStats.mLeafVol / mRoot->mBox.GetVolume() << endl; 
    848  
    849         cout << "geometry per leaf: " <<  mBvhStats.mGeometryRatio << endl; 
    850         cout << "triangles per leaf: " <<  mBvhStats.mTriangleRatio << endl; 
    851         cout << "**************" << endl << endl; 
     856        bvhStats.mGeometryRatio = (float)numGeometry / numVirtualLeaves; 
     857        bvhStats.mTriangleRatio = (float)bvhStats.mTriangles / numVirtualLeaves; 
     858        bvhStats.mLeaves = numVirtualLeaves; 
     859} 
     860 
     861 
     862void Bvh::PrintBvhStats(const BvhStats &bvhStats) const 
     863{ 
     864        cout << "\n============ BVH statistics =============" << endl; 
     865        cout << "interiorNodesSA = " << bvhStats.mInteriorSA / mRoot->mBox.SurfaceArea() << endl; 
     866        cout << "leafNodesSA = " << bvhStats.mLeafSA / mRoot->mBox.SurfaceArea() << endl; 
     867        cout << "interiorNodesVolume = " << bvhStats.mInteriorVol / mRoot->mBox.GetVolume() << endl; 
     868        cout << "leafNodesVolume = " << bvhStats.mLeafVol / mRoot->mBox.GetVolume() << endl; 
     869 
     870        cout << "geometry per leaf: " << bvhStats.mGeometryRatio << endl; 
     871        cout << "triangles per leaf: " << bvhStats.mTriangleRatio << endl; 
     872        cout << "===========================================" << endl << endl; 
    852873} 
    853874 
     
    11551176int Bvh::SortTriangles(BvhLeaf *leaf,  
    11561177                                           int axis,  
    1157                                            float position, 
    1158                                            SceneEntityContainer &entities) 
     1178                                           float position 
     1179                                           ) 
    11591180{ 
    11601181        int i = leaf->mFirst; 
    11611182        int j = leaf->mLast; 
    11621183 
    1163     while (1)  
    1164         { 
    1165                 while (entities[i]->GetCenter()[axis] < position)  
     1184    while (1) 
     1185        { 
     1186                while (mGeometry[i]->GetWorldCenter()[axis] < position)  
     1187                { 
     1188                        //cout<<" i " << i << " " << mGeometry[i]->GetWorldCenter()[axis]; 
    11661189                        ++ i; 
    1167          
    1168                 while (position < entities[j]->GetCenter()[axis]) 
     1190                } 
     1191 
     1192                while (position < mGeometry[j]->GetWorldCenter()[axis]) 
     1193                { 
     1194                        //cout<< axis << " j " << j << " " << mGeometry[j]->GetWorldCenter()[axis] << " " << position<< " "; 
    11691195                        -- j; 
     1196                } 
    11701197 
    11711198                // sorting finished 
     
    11731200 
    11741201                // swap entities 
    1175                 swap(entities[i], entities[j]); 
     1202                swap(mGeometry[i], mGeometry[j]); 
    11761203                         
    11771204                ++ i; 
     
    11841211 
    11851212int Bvh::SortTrianglesSpatialMedian(BvhLeaf *leaf,  
    1186                                                                         int axis, 
    1187                                                                         SceneEntityContainer &entities) 
     1213                                                                        int axis 
     1214                                                                        ) 
    11881215{ 
    11891216        // spatial median 
    11901217        float m = leaf->mBox.Center()[axis]; 
    1191         return SortTriangles(leaf, axis, m, entities); 
     1218        //cout << "here3 " << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl; 
     1219        return SortTriangles(leaf, axis, m); 
    11921220} 
    11931221 
    11941222 
    11951223BvhNode *Bvh::SubdivideLeaf(BvhLeaf *leaf,  
    1196                                                         int parentAxis,  
    1197                                                         SceneEntityContainer &entities) 
     1224                                                        int parentAxis 
     1225                                                        ) 
    11981226{ 
    11991227        if (TerminationCriteriaMet(leaf)) 
    12001228        { 
    12011229                leaf->mIsVirtualLeaf = true; 
     1230                leaf->mIsMaxDepthForVirtualLeaf = true; 
    12021231                return leaf; 
    12031232        } 
    12041233 
    1205         //int axis = leaf->mBox.MajorAxis(); 
    1206         int axis = (parentAxis + 1) % 3; 
     1234        //const int axis = (parentAxis + 1) % 3; 
     1235        const int axis = leaf->mBox.MajorAxis(); 
     1236         
     1237 
     1238        const int scale = 20; 
    12071239 
    12081240        // position of the split in the partailly sorted array of triangles 
    12091241        // corresponding to this leaf 
    12101242        int split = -1; 
    1211         const int scale = 20; 
    1212  
    12131243        float pos = -1.0f; 
    1214  
     1244         
    12151245        // Spatial median subdivision 
    1216         split = SortTrianglesSpatialMedian(leaf, axis, entities); 
     1246        split = SortTrianglesSpatialMedian(leaf, axis); 
    12171247        pos = leaf->mBox.Center()[axis]; 
    12181248         
     
    12471277         
    12481278        // reset box 
    1249         leaf->mBox.Initialize(); 
     1279        //leaf->mBox.Initialize(); 
     1280 
     1281        front->mBox = ComputeBoundingBox(mGeometry + front->mFirst, front->CountPrimitives()); 
     1282        leaf->mBox = ComputeBoundingBox(mGeometry + leaf->mFirst, leaf->CountPrimitives()); 
    12501283 
    12511284        // recursively continue subdivision 
    1252         parent->mBack = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mBack), axis, entities); 
    1253         parent->mFront = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mFront), axis, entities); 
     1285        parent->mBack = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mBack), axis); 
     1286        parent->mFront = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mFront), axis); 
    12541287         
    12551288        return parent; 
     
    12671300 
    12681301 
    1269 void Bvh::UpdateDynamicBranch() 
     1302void Bvh::UpdateDynamicBranch(BvhNode *node) 
     1303{ 
     1304        if (node->IsLeaf()) 
     1305        { 
     1306                int numEntities; 
     1307                SceneEntity **entities = GetGeometry(node, numEntities); 
     1308 
     1309                node->mBox = ComputeBoundingBox(entities, numEntities); 
     1310                //cout << "box: " << node->mBox << endl; 
     1311        } 
     1312        else 
     1313        { 
     1314                BvhNode *f = static_cast<BvhInterior *>(node)->GetFront(); 
     1315                BvhNode *b = static_cast<BvhInterior *>(node)->GetBack(); 
     1316 
     1317                UpdateDynamicBranch(f); 
     1318                UpdateDynamicBranch(b); 
     1319 
     1320                node->mBox = f->mBox; 
     1321                node->mBox.Include(b->mBox); 
     1322        } 
     1323} 
     1324 
     1325 
     1326void Bvh::CreateDynamicBranch() 
    12701327{ 
    12711328        // the bvh has two main branches 
     
    12781335        // the movements of the objects within 
    12791336 
    1280         // delete old branch 
    1281         cout << "deleting old branch" << endl; 
    1282  
    12831337        DEL_PTR(mDynamicRoot); 
    12841338 
    1285         mDynamicRoot = new BvhLeaf(mRoot); 
    1286         mDynamicRoot->mBox = mRoot->mBox; 
    1287  
    1288         mDynamicRoot->mFirst = 0; 
    1289         mDynamicRoot->mLast = (int)mDynamicEntities.size() - 1; 
    1290         mDynamicRoot->mArea = mDynamicRoot->mBox.SurfaceArea(); 
    1291          
    1292         cout << "updating dynamic branch" << endl; 
    1293  
    1294         mDynamicRoot = SubdivideLeaf(static_cast<BvhLeaf *>(mDynamicRoot), 0, mDynamicEntities); 
    1295  
    1296         cout << "finished updating dynamic branch" << endl; 
    1297 } 
    1298  
    1299  
    1300 void Bvh::AddDynamicObject(SceneEntity *ent) 
    1301 { 
    1302         mDynamicEntities.push_back(ent); 
     1339        BvhLeaf *l = new BvhLeaf(mRoot); 
     1340 
     1341        l->mBox.Initialize(); 
     1342 
     1343        SceneEntityContainer::const_iterator sit, sit_end = mDynamicEntities.end(); 
     1344 
     1345        for (sit = mDynamicEntities.begin(); sit != sit_end; ++ sit) 
     1346        { 
     1347                l->mBox.Include((*sit)->GetWorldBoundingBox()); 
     1348        } 
     1349 
     1350        l->mFirst = (int)(mGeometrySize - mDynamicEntities.size()); 
     1351        l->mLast = (int)mGeometrySize - 1; 
     1352        l->mArea = l->mBox.SurfaceArea(); 
     1353         
     1354        cout << "updating dynamic branch " << l->mFirst << " " << l->mLast << endl; 
     1355 
     1356        mDynamicRoot = SubdivideLeaf(l, 0); 
     1357 
     1358        BvhStats bvhStats; 
     1359        ComputeBvhStats(mDynamicRoot, bvhStats); 
     1360 
     1361        cout << "\n=========== Dynamic BVH statistics: =========" << endl; 
     1362        cout << "leaves = " << bvhStats.mLeaves << endl; 
     1363        cout << "interiorNodesSA = " << bvhStats.mInteriorSA << endl; 
     1364        cout << "leafNodesSA = " << bvhStats.mLeafSA << endl; 
     1365        cout << "interiorNodesVolume = " << bvhStats.mInteriorVol  << endl; 
     1366        cout << "leafNodesVolume = " << bvhStats.mLeafVol << endl; 
     1367 
     1368        cout << "geometry per leaf: " << bvhStats.mGeometryRatio << endl; 
     1369        cout << "triangles per leaf: " << bvhStats.mTriangleRatio << endl; 
     1370        cout << "=============================================" << endl << endl; 
     1371} 
     1372 
     1373 
     1374void Bvh::AddDynamicObjects(const SceneEntityContainer &entities) 
     1375{ 
     1376        // copy old entities 
     1377        SceneEntity **newGeom = new SceneEntity*[mGeometrySize + (int)entities.size()]; 
     1378 
     1379        memcpy(newGeom, mGeometry, mGeometrySize * sizeof(SceneEntity *)); 
     1380 
     1381        delete [] mGeometry; 
     1382        mGeometry = newGeom; 
     1383 
     1384        // now add new entities 
     1385        SceneEntityContainer::const_iterator it, it_end = entities.end(); 
     1386 
     1387        size_t i = mGeometrySize; 
     1388        for (it = entities.begin(); it != it_end; ++ it, ++ i) 
     1389        { 
     1390                mGeometry[i] = (*it); 
     1391                mDynamicEntities.push_back(*it); 
     1392        } 
     1393 
     1394 
     1395        mGeometrySize += entities.size(); 
    13031396} 
    13041397 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r3065 r3070  
    478478        struct BvhStats 
    479479        { 
    480                 BvhStats():  
    481                 mInteriorSA(0), 
    482                 mLeafSA(0), 
    483                 mInteriorVol(0), 
    484                 mLeafVol(0), 
    485                 mTriangles(0), 
    486                 mTriangleRatio(0), 
    487                 mGeometryRatio(0), 
    488                 mMaxGeometry(0), 
    489                 mMaxTriangles(0) 
    490                 {} 
    491                  
     480                BvhStats() { Reset(); } 
     481 
     482                void Reset()  
     483                { 
     484                        mInteriorSA = .0f; 
     485                        mLeafSA = .0f; 
     486                        mInteriorVol = .0f; 
     487                        mLeafVol = .0f; 
     488                        mTriangleRatio = .0f; 
     489                        mGeometryRatio = .0f; 
     490 
     491                        mTriangles = 0; 
     492                        mLeaves = 0; 
     493                } 
     494 
     495                /////////////////// 
     496 
    492497                float mInteriorSA; 
    493498                float mLeafSA; 
     
    495500                float mLeafVol;  
    496501                 
    497                 int mTriangles; 
    498  
    499502                float mTriangleRatio; 
    500503                float mGeometryRatio; 
    501504 
    502                 int mMaxGeometry; 
    503                 int mMaxTriangles; 
     505                int mTriangles; 
     506                int mLeaves; 
    504507        }; 
    505508 
     
    525528        */ 
    526529        inline BvhNode *GetRoot(); 
     530 
     531        inline BvhNode *GetDynamicRoot(); 
    527532        /** Returns the bounding box of this bvh. 
    528533        */ 
     
    643648        void RenderBoundsForViz(BvhNode *node, RenderState *state, bool useTightBounds); 
    644649 
    645         void AddDynamicObject(SceneEntity *ent); 
     650        void AddDynamicObjects(const SceneEntityContainer &entities); 
     651 
    646652 
    647653 
     
    661667 
    662668        ///////////// 
    663  
    664         void ComputeBvhStats(); 
    665         void PrintBvhStats() const; 
     669        /** Traverse hierarchy and compute stats. 
     670        */ 
     671        void ComputeBvhStats(BvhNode *root, BvhStats &bvhStats); 
     672        /** Output the bvh statistics. 
     673        */ 
     674        void PrintBvhStats(const BvhStats &bvhStats) const; 
    666675 
    667676 
     
    712721        int SortTriangles(BvhLeaf *leaf,  
    713722                              int axis,  
    714                                           float position, 
    715                                           SceneEntityContainer &entities); 
     723                                          float position); 
    716724 
    717725        int SortTrianglesSpatialMedian(BvhLeaf *leaf,  
    718                                            int axis, 
    719                                                                    SceneEntityContainer &entities); 
     726                                           int axis); 
    720727 
    721728        BvhNode *SubdivideLeaf(BvhLeaf *leaf,  
    722                                    int parentAxis,  
    723                                                    SceneEntityContainer &entities); 
     729                                   int parentAxis); 
    724730        /** Recompute the dynamic branch of the hierarchy. 
    725731        */ 
    726         void UpdateDynamicBranch(); 
     732        void CreateDynamicBranch(); 
     733 
     734        void UpdateDynamicBranch(BvhNode *node); 
    727735 
    728736        inline bool TerminationCriteriaMet(BvhLeaf *leaf) const; 
     
    830838 
    831839 
     840BvhNode *Bvh::GetDynamicRoot() 
     841{  
     842        return mDynamicRoot;  
     843} 
     844 
     845 
    832846const AxisAlignedBox3 &Bvh::GetBox() const  
    833847{  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp

    r3069 r3070  
    130130 
    131131        // compute and print stats 
    132         bvh->ComputeBvhStats(); 
    133         bvh->PrintBvhStats(); 
     132        bvh->ComputeBvhStats(bvh->mRoot, bvh->mBvhStats); 
     133        bvh->PrintBvhStats(bvh->mBvhStats); 
    134134 
    135135        return bvh; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/EntityMerger.cpp

    r2980 r3070  
    3030        Shape *shape = MergeShapes(shape1, shape2, ent); 
    3131         
    32         LODLevel *lodLevel = new LODLevel(0); 
     32        LODLevel lodLevel(0); 
    3333 
    34         lodLevel->AddShape(shape); 
     34        lodLevel.AddShape(shape); 
    3535        ent->AddLODLevel(lodLevel); 
    3636 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r3066 r3070  
    157157        // add root node to queue 
    158158        EnqueueNode(mBvh->GetRoot()); 
     159        // add dynamic root 
     160        EnqueueNode(mBvh->GetDynamicRoot()); 
    159161 
    160162 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3058 r3070  
    5151        CLEAR_CONTAINER(mTrafos); 
    5252        CLEAR_CONTAINER(mShapes); 
    53         CLEAR_CONTAINER(mLODs); 
     53        //CLEAR_CONTAINER(mLODs); 
    5454} 
    5555 
     
    103103                str.read(reinterpret_cast<char *>(&numShapes), sizeof(int)); 
    104104 
    105                 LODLevel *lodLevel = new LODLevel(dist); 
     105                //LODLevel *lodLevel = new LODLevel(dist); 
     106                LODLevel lodLevel(dist); 
    106107 
    107108                for (int j = 0; j < numShapes; ++ j) 
     
    119120 
    120121                        sceneGeom->AddShape(shape); 
    121                         lodLevel->AddShape(shape); 
     122                        lodLevel.AddShape(shape); 
    122123                } 
    123124 
    124                 mLODs.push_back(lodLevel); 
     125                //mLODs.push_back(lodLevel); 
    125126                sceneGeom->AddLODLevel(lodLevel); 
    126127        } 
     
    407408} 
    408409 
    409 } 
    410  
     410 
     411void ResourceManager::AddSceneEntity(SceneEntity *ent) 
     412{ 
     413        mSceneEntities.push_back(ent); 
     414} 
     415 
     416 
     417Transform3 *ResourceManager::CreateTransform(const Matrix4x4 &m) 
     418{ 
     419        Transform3 *t = new Transform3(m); 
     420 
     421        mTrafos.push_back(t); 
     422        return t; 
     423} 
     424 
     425} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h

    r3057 r3070  
    5050        */ 
    5151        static void DelSingleton(); 
     52        /** Adds a scene entity to be handled by the resource mananger. 
     53        */ 
     54        void AddSceneEntity(SceneEntity *ent); 
     55        /** Adds a scene entity to be handled by the resource mananger. 
     56        */ 
     57        Transform3 *CreateTransform(const Matrix4x4 &m); 
     58 
    5259 
    5360protected: 
     
    8390        TransformContainer mTrafos; 
    8491        ShapeContainer mShapes; 
    85         LODContainer mLODs; 
     92        //LODContainer mLODs; 
    8693        /// the scene entities 
    8794        SceneEntityContainer mSceneEntities; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r3034 r3070  
    3939        if (!sUseLODs) return; 
    4040 
    41         const Vector3 pos = GetCenter(); 
     41        const Vector3 pos = GetWorldCenter(); 
    4242 
    4343        const float dist = SqrDistance(pos, viewPoint); 
     
    4848        for (int i = 0; i < l; ++ i) 
    4949        { 
    50                 LODLevel *lod = mLODLevels[i]; 
    51  
    52                 if (lod->GetSquaredDistance() > dist) 
     50                if (mLODLevels[i].GetSquaredDistance() > dist) 
    5351                        break; 
    5452 
     
    7977        } 
    8078 
    81         start = mLODLevels[mCurrentLODLevel]->GetShapes().begin();  
    82         end   = mLODLevels[mCurrentLODLevel]->GetShapes().end(); 
     79        start = mLODLevels[mCurrentLODLevel].GetShapes().begin();  
     80        end   = mLODLevels[mCurrentLODLevel].GetShapes().end(); 
    8381} 
    8482 
     
    8886                                                          ShapeContainer::iterator &end) 
    8987{ 
    90         LODLevel *lod = mLODLevels[level]; 
    91  
    92         start = lod->GetShapes().begin(); 
    93         end = lod->GetShapes().end(); 
     88        start = mLODLevels[level].GetShapes().begin(); 
     89        end = mLODLevels[level].GetShapes().end(); 
    9490} 
    9591 
     
    9995        ShapeContainer::iterator sit, sit_end; 
    10096 
    101         GetCurrentLODLevel(sit, sit_end); 
     97        if (!mLODLevels.empty()) 
     98                GetCurrentLODLevel(sit, sit_end); 
     99        else 
     100        { 
     101                sit = mShapes.begin(); sit_end = mShapes.end(); 
     102        } 
    102103 
    103104        for (; sit != sit_end; ++ sit) 
     
    146147        } 
    147148 
    148         return mLODLevels[lodLevel]->GetNumTriangles(); 
     149        return mLODLevels[lodLevel].GetNumTriangles(); 
    149150} 
    150151 
    151152 
    152 AxisAlignedBox3 SceneEntity::GetTransformedBoundingBox() const 
     153AxisAlignedBox3 SceneEntity::GetWorldBoundingBox() const 
    153154{ 
    154155        if (mTransform->IsIdentity()) return mBox; 
     
    166167 
    167168 
    168 Vector3 SceneEntity::GetCenter() const 
     169Vector3 SceneEntity::GetWorldCenter() const 
    169170{ 
    170171        if (mTransform->IsIdentity()) 
    171172                return mCenter; 
    172173 
    173         Matrix4x4 mat = mTransform->GetMatrix(); 
    174  
    175         return mat * mCenter; 
     174        return mTransform->GetMatrix() *  mCenter; 
    176175} 
    177176 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h

    r3042 r3070  
    3434        */ 
    3535        SceneEntity(Transform3 *trafo); 
    36  
     36        /** Copy constructur. 
     37        */ 
     38        //SceneEntity(const SceneEntity &trafo); 
     39        /** Destructor. 
     40        */ 
    3741        virtual ~SceneEntity(); 
    3842        /** Renders this node. 
     
    6468        */ 
    6569        int CountNumTriangles(int lodLevel = -1); 
    66         /** Returns the bounding box. 
     70        /** Returns the local bounding box. 
    6771        */ 
    6872        AxisAlignedBox3 GetBoundingBox() const; 
    6973        /** Returns the transformed bounding box. 
    7074        */ 
    71         AxisAlignedBox3 GetTransformedBoundingBox() const; 
     75        AxisAlignedBox3 GetWorldBoundingBox() const; 
    7276         
    7377 
     
    8488        /** Adds a new lod level. 
    8589        */ 
    86         void AddLODLevel(LODLevel *lod) { mLODLevels.push_back(lod); } 
     90        void AddLODLevel(const LODLevel &lod) { mLODLevels.push_back(lod); } 
    8791        /** Returns numbers of lod levels. 
    8892        */ 
     
    9094        /** Returns transformed center point of this shape. 
    9195        */ 
    92         Vector3 GetCenter() const; 
     96        Vector3 GetWorldCenter() const; 
    9397        /** If false, the highest (most detailed) LOD level is used for all entities. 
    9498        */ 
     
    111115        Transform3 *mTransform; 
    112116        /// Stores information about the LOD levels 
    113         LODLevelContainer mLODLevels; 
     117        LODLevelArray mLODLevels; 
    114118        /// the renderable shapes 
    115119        ShapeContainer mShapes; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp

    r3023 r3070  
    4646        ent->AddShape(shape); 
    4747 
    48         LODLevel *lodLevel = new LODLevel(0); 
     48        LODLevel lodLevel(0); 
    4949 
    50         lodLevel->AddShape(shape); 
     50        lodLevel.AddShape(shape); 
    5151        ent->AddLODLevel(lodLevel); 
    5252 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp

    r3054 r3070  
    5353 
    5454 
    55 AxisAlignedBox3 Shape::GetTransformedBoundingBox() const 
     55AxisAlignedBox3 Shape::GetWorldBoundingBox() const 
    5656{ 
    5757        if (mParent->GetTransform()->IsIdentity()) 
     
    6464 
    6565 
    66 Vector3 Shape::GetCenter() const 
     66Vector3 Shape::GetWorldCenter() const 
    6767{ 
    6868        if (mParent->GetTransform()->IsIdentity()) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h

    r3061 r3070  
    5252        /** Returns bounding box transformed with the parent transform. 
    5353        */ 
    54         AxisAlignedBox3 GetTransformedBoundingBox() const; 
     54        AxisAlignedBox3 GetWorldBoundingBox() const; 
    5555        /** Returns material of this shape. 
    5656        */ 
     
    5858        /** Returns transformed center point of this shape. 
    5959        */ 
    60         Vector3 GetCenter() const; 
     60        Vector3 GetWorldCenter() const; 
    6161 
    6262 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp

    r3057 r3070  
    157157void SkyPreetham::RenderSunDisk(const Vector3 &sunDir, Camera *camera) 
    158158{ 
    159 #if TODOD 
     159#if TODO 
    160160        // Move skybox with camera. 
    161161        Vector3 position = camera->GetPosition(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp

    r3034 r3070  
    77{ 
    88 
    9 CGparameter Transform3::sModelMatrixParam; 
     9 
     10Transform3::Transform3() 
     11{ 
     12        Reset(); 
     13} 
    1014 
    1115 
     
    1317{ 
    1418        mIsIdentity = false; 
    15 } 
    16  
    17  
    18 Transform3::Transform3() 
    19 { 
    20         Reset(); 
    2119} 
    2220 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h

    r3061 r3070  
    33 
    44#include "Matrix4x4.h" 
    5 #include "glInterface.h" 
    65#include "common.h" 
    7 #include <Cg/cg.h> 
    8 #include <Cg/cgGL.h> 
    96 
    107 
     
    4946        inline bool IsIdentity() const { return mIsIdentity; } 
    5047 
    51         static CGparameter sModelMatrixParam; 
    52  
    5348 
    5449protected: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Triangle3.cpp

    r2957 r3070  
    4949 
    5050 
    51 Vector3 Triangle3::GetCenter() const  
     51Vector3 Triangle3::GetWorldCenter() const  
    5252{ 
    5353        return (mVertices[0] + mVertices[1] + mVertices[2]) / 3.0f; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Triangle3.h

    r2957 r3070  
    2121        Vector3 GetNormal() const; 
    2222 
    23         Vector3 GetCenter() const; 
     23        Vector3 GetWorldCenter() const; 
    2424 
    2525        float GetSpatialAngle(const Vector3 &point) const; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3068 r3070  
    7171/// the renderable scene geometry 
    7272SceneEntityContainer sceneEntities; 
     73SceneEntityContainer dynamicObjects; 
    7374// traverses and renders the hierarchy 
    7475RenderTraverser *traverser = NULL; 
     
    289290void PrepareRenderQueue(); 
    290291/// loads the specified model 
    291 void LoadModel(const string &model); 
     292void LoadModel(const string &model, SceneEntityContainer &entities); 
    292293 
    293294inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 
     
    450451        //-- load the static scene geometry 
    451452 
    452         LoadModel("city.dem"); 
     453        LoadModel("city.dem", sceneEntities); 
    453454 
    454455 
     
    478479        //-- setup the skydome model 
    479480 
    480         LoadModel("sky.dem"); 
     481        LoadModel("sky.dem", sceneEntities); 
    481482        skyDome = sceneEntities.back(); 
    482483 
     
    494495        visualization = new Visualization(bvh, camera, NULL, &state); 
    495496 
    496  
    497         LoadModel("hbuddha.dem"); 
    498         buddha = sceneEntities.back(); 
    499  
     497        LoadModel("hbuddha.dem", dynamicObjects); 
     498        buddha = dynamicObjects.back(); 
     499        dynamicObjects.clear(); 
    500500        Vector3 sceneCenter(470.398f, 240.364f, 182.5f); 
    501501        Matrix4x4 transl = TranslationMatrix(sceneCenter); 
    502  
    503502        buddha->GetTransform()->SetMatrix(transl); 
    504503 
    505         bvh->AddDynamicObject(buddha); 
    506  
     504        Vector3 offs = Vector3::ZERO(); 
     505 
     506        for (int i = 0; i < 10; ++ i) 
     507        { 
     508                SceneEntity *ent = new SceneEntity(*buddha); 
     509                resourceManager->AddSceneEntity(ent); 
     510 
     511                offs.x = RandomValue(.0f, 50.0f); 
     512                offs.y = RandomValue(.0f, 50.0f); 
     513 
     514                transl = TranslationMatrix(sceneCenter + offs); 
     515                Transform3 *transform = resourceManager->CreateTransform(transl); 
     516 
     517                ent->SetTransform(transform); 
     518                dynamicObjects.push_back(ent); 
     519        } 
     520         
     521        bvh->AddDynamicObjects(dynamicObjects); 
    507522 
    508523        // this function assign the render queue bucket ids of the materials in beforehand 
    509524        // => probably a little less overhead for new parts of the scene that are not yet assigned 
    510525        PrepareRenderQueue(); 
    511          
    512526        /// forward rendering is the default 
    513527        state.SetRenderTechnique(FORWARD); 
    514  
    515528        // frame time is restarted every frame 
    516529        frameTimer.Start(); 
     
    20042017 
    20052018 
    2006 void LoadModel(const string &model) 
     2019void LoadModel(const string &model, SceneEntityContainer &entities) 
    20072020{ 
    20082021        const string filename = string(model_path + model); 
    20092022 
    2010         if (resourceManager->Load(filename, sceneEntities)) 
     2023        if (resourceManager->Load(filename, entities)) 
    20112024                cout << "model " << filename << " loaded" << endl; 
    20122025        else 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h

    r3042 r3070  
    505505typedef std::vector<ShaderProgram *> ShaderContainer; 
    506506typedef std::vector<Technique *> TechniqueContainer; 
     507 
    507508typedef std::vector<Vector3> VertexArray; 
    508  
     509typedef std::vector<LODLevel> LODLevelArray; 
    509510 
    510511typedef std::pair<float, float> Texcoord2; 
Note: See TracChangeset for help on using the changeset viewer.