Changeset 2760 for GTP/trunk


Ignore:
Timestamp:
06/14/08 19:04:01 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/CHC_revisited
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp

    r2757 r2760  
    1313namespace CHCDemo 
    1414{ 
    15  
    16 /*static STL_MAP<String,Texture *> stlm_textures; 
    17  
    18  
    19 // clear the texture table (called on new file load) 
    20 static void clear_textures() 
    21 { 
    22         STL_MAP<String,Texture *>::iterator it, it_end = stlm_textures.end(); 
    23  
    24         for (it = stlm_textures.begin(); it != it_end; ++ it) 
    25         { 
    26                 it->second->unref(); 
    27                 delete [] it->first; 
    28  
    29                 it ++; 
    30         } 
    31  
    32         stlm_textures.clear(); 
    33 } 
    34  
    35  
    36 static Texture *get_texture(const char *filename, TextureAttributes *&myTextureAttributes) 
    37 { 
    38         Texture * myTexture = NULL; 
    39  
    40         myTextureAttributes = new TextureAttributes; 
    41         myTextureAttributes->setTextureMode(TextureAttributes::DECAL); 
    42  
    43         // Michi: avoid multiple loading of same texture! 
    44         if (stlm_textures.find(filename) != stlm_textures.end()) 
    45         { 
    46                 myTexture = stlm_textures[filename]; 
    47         } 
    48         else 
    49         { 
    50                 ImageComponent *image = new ImageComponent(filename); 
    51                 //Texture *myTexture = new Texture(Texture::BASE_LEVEL, Texture::RGB, image->getWidth(), image->getHeight()); 
    52                 myTexture = new Texture(Texture::MULTI_LEVEL_MIPMAP, ImageComponent::FORMAT_RGBP, image->getWidth(), image->getHeight()); 
    53                 myTexture->setImage(0, image); 
    54                  
    55                 myTexture->setMagFilter(Texture::BASE_LEVEL_LINEAR); 
    56                 myTexture->setMinFilter(Texture::MULTI_LEVEL_LINEAR_POINT); 
    57  
    58                 myTexture->setBoundaryModeS(Texture::WRAP); 
    59                 myTexture->setBoundaryModeT(Texture::WRAP); 
    60                  
    61                 stlm_textures[filename] = myTexture; 
    62                 /// HACK!!! (texture not deleted on reload!) 
    63                 myTexture->ref(); 
    64         } 
    65  
    66         return myTexture; 
    67 }*/ 
    6815 
    6916 
     
    9845                str.read(texname, sizeof(char) * texnameSize); 
    9946 
    100                 cout << "loading texture " << texname << " with len " << texnameSize << " id: " << id << endl; 
    101  
     47                //cout << "loading texture " << texname << " with len " << texnameSize << " id: " << id << endl; 
    10248                Texture *tex = new Texture(texname); 
    10349 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp

    r2756 r2760  
    131131mIndices(NULL), 
    132132mTestIndices(NULL), 
    133 mCurrentIndicesPtr(0) 
     133mCurrentIndicesPtr(0), 
     134mNumNodes(0), 
     135mMaxDepthForTestingChildren(4), 
     136mAreaRatioThreshold(1.4f) 
    134137{} 
    135138 
    136 /* 
    137 Bvh::Bvh(const GeometryVector &geometry,  
    138                  DistanceSortedRenderAction *const renderer): 
     139 
     140Bvh::Bvh(const SceneEntityContainer &entities): 
    139141mCamera(NULL),  
    140142mFrameId(-1),  
     
    144146mTestIndices(NULL), 
    145147mCurrentIndicesPtr(0), 
    146 { 
    147         mGeometry = new NodeGeometry*[geometry.size()]; 
    148         mGeometrySize = geometry.size(); 
    149  
    150         BoundingBox sceneBox; 
    151  
    152         // compute scene extent 
    153         for (size_t i = 0; i < mGeometrySize; ++ i) 
    154         { 
    155                 mGeometry[i] = geometry[i]; 
    156                 sceneBox.combine(&mGeometry[i]->mBox); 
    157  
    158                 mBvhStats.mTriangles += mGeometry[i]->mNumTriangles; 
    159         } 
    160  
    161  
    162         //////// 
    163         //-- create root 
    164  
    165         BvhLeaf *leaf = new BvhLeaf(NULL); 
    166         leaf->mDepth = 0; 
    167         leaf->mFirst = 0; 
    168         leaf->mLast = (int)geometry.size() - 1; 
    169         leaf->mBox = sceneBox; 
    170  
    171         OUT1("geometry in root: " << leaf->mLast); 
    172  
    173         mRoot = leaf; 
    174         mNumNodes = 1; 
    175  
    176         // parameters 
    177         mMaxGeometry = Settings::Global()->get_nvocc_bvh_max_objects(); 
    178         mMaxTriangles = Settings::Global()->get_nvocc_bvh_max_triangles(); 
    179         mMaxDepth = Settings::Global()->get_nvocc_bvh_max_depth(); 
    180         mSplitType = Settings::Global()->get_nvocc_bvh_split_type(); 
    181  
    182         float sceneArea = sceneBox.getSurface(); 
    183         float minAreaRatio = Settings::Global()->get_nvocc_bvh_min_area(); 
    184  
    185         mMinArea = minAreaRatio * sceneArea; 
    186  
    187         mMaxDepthForTestingChildren = Settings::Global()->get_nvocc_bvh_max_depth_for_testing_children(); 
    188                  
    189         mAreaRatioThreshold = Settings::Global()->get_nvocc_area_ratio_threshold(); 
    190         mVolRatioThreshold = Settings::Global()->get_nvocc_vol_ratio_threshold(); 
    191 } 
    192 */ 
     148mNumNodes(0), 
     149mMaxDepthForTestingChildren(4), 
     150mAreaRatioThreshold(1.4f) 
     151{ 
     152        mGeometrySize = entities.size(); 
     153        mGeometry = new SceneEntity*[mGeometrySize]; 
     154         
     155        mBox.Initialize(); 
     156 
     157        SceneEntityContainer::const_iterator it, it_end = entities.end(); 
     158 
     159        int i = 0; 
     160        for (it = entities.begin(); it != it_end; ++ it, ++ i) 
     161        { 
     162                mGeometry[i] = (*it); 
     163                mBox.Include((*it)->GetBoundingBox()); 
     164        } 
     165 
     166        cout << "scene box: " << mBox << endl; 
     167} 
     168 
    193169 
    194170Bvh::~Bvh()  
     
    801777        cout << "leafNodesVolume = " << mBvhStats.mLeafVol / mRoot->mBox.GetVolume() << endl; 
    802778 
    803         cout << "boundsInteriorNodesSA = " << mBvhStats.mBoundsInteriorSA / mBvhStats.mLeafSA << endl; 
    804         cout << "boundsLeafNodesSA = " << mBvhStats.mBoundsLeafSA / mBvhStats.mLeafSA << endl; 
    805         cout << "boundsInteriorNodesVolume = " << mBvhStats.mBoundsInteriorVol / mBvhStats.mLeafVol << endl; 
    806         cout << "boundsLeafNodesVolume = " << mBvhStats.mBoundsLeafVol / mBvhStats.mLeafVol << "\n" << endl; 
    807  
    808         cout << "boundsLeaves: " <<  (float)mBvhStats.mBoundsLeavesCount / (float)GetNumLeaves() << "\n" << endl; 
    809779        cout << "geometry per leaf: " <<  mBvhStats.mGeometryRatio << endl; 
    810780        cout << "triangles per leaf: " <<  mBvhStats.mTriangleRatio << endl; 
     
    828798} 
    829799 
    830 } 
     800 
     801void Bvh::UpdateNumLeaves(BvhNode *node) const 
     802{ 
     803        if (node->IsLeaf()) 
     804        { 
     805                node->mNumLeaves = 1; 
     806        } 
     807        else 
     808        { 
     809                BvhNode *f = static_cast<BvhInterior *>(node)->GetFront(); 
     810                BvhNode *b = static_cast<BvhInterior *>(node)->GetBack(); 
     811 
     812                UpdateNumLeaves(f); 
     813                UpdateNumLeaves(b); 
     814 
     815                node->mNumLeaves = f->mNumLeaves + b->mNumLeaves; 
     816        } 
     817} 
     818 
     819 
     820int Bvh::Render(BvhNode *node, RenderState *state) 
     821{ 
     822        //cout << "r " << node->mFirst << " " <<  node->mLast << endl; 
     823 
     824        int rendered = 0; 
     825 
     826        for (int i = node->mFirst; i <= node->mLast; ++ i) 
     827        { 
     828                if (mGeometry[i]->GetLastRendered() != mFrameId) 
     829                { 
     830                        mGeometry[i]->Render(state); 
     831                        mGeometry[i]->SetLastRendered(mFrameId); 
     832                        ++ rendered; 
     833                } 
     834        } 
     835 
     836        return rendered; 
     837} 
     838 
     839 
     840} 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h

    r2756 r2760  
    1414 
    1515//////// 
    16 // Forward declarations 
     16//-- Forward declarations 
    1717 
    1818class SceneEntity; 
    1919class Camera; 
     20class RenderState; 
    2021 
    2122 
     
    210211        /// the bounding box 
    211212        AxisAlignedBox3 mBox; 
    212  
    213213}; 
    214214 
     
    347347        /** Returns split axis of this interior node. 
    348348        */ 
    349         inline int GetAxis() { return (int)mAxis; } 
     349        //inline int GetAxis() { return (int)mAxis; } 
    350350        /** Returns position of the split axis. 
    351351        */ 
    352         inline float GetPosition() {return (float)mPosition;} 
     352        //inline float GetPosition() {return (float)mPosition;} 
    353353 
    354354 
     
    356356 
    357357        /// the position of the split plane 
    358         float mPosition; 
     358        //float mPosition; 
    359359         
    360360        BvhNode *mBack; 
     
    407407                mInteriorVol(0), 
    408408                mLeafVol(0), 
    409                 mBoundsInteriorSA(0), 
    410                 mBoundsLeafSA(0), 
    411                 mBoundsInteriorVol(0), 
    412                 mBoundsLeafVol(0), 
    413                 mBoundsLeavesCount(0), 
    414409                mTriangles(0), 
    415410                mTriangleRatio(0), 
     
    423418                float mInteriorVol; 
    424419                float mLeafVol;  
    425                 float mBoundsInteriorSA; 
    426                 float mBoundsLeafSA; 
    427                 float mBoundsInteriorVol; 
    428                 float mBoundsLeafVol; 
    429                 int mBoundsLeavesCount; 
     420                 
    430421                int mTriangles; 
    431422 
     
    479470        int RenderBoundingBoxes(const BvhNodeContainer &nodes); 
    480471 
     472        /** Returns the bounding box of this bvh. 
     473        */ 
     474        inline const AxisAlignedBox3 &GetBox() { return mBox; } 
    481475 
    482476 
     
    535529        const BvhStats &GetBvhStats() const {return mBvhStats;} 
    536530         
     531        int Render(BvhNode *node, RenderState *state); 
     532 
    537533 
    538534protected: 
     
    543539        */ 
    544540        Bvh(); 
     541 
     542        /** Protected constructor taking scene geometry into account 
     543        */ 
     544        const Bvh(const SceneEntityContainer &entities); 
    545545         
    546546 
     
    574574        */ 
    575575        void RecomputeBounds(); 
    576         /** Does some postprocessing on the leaves. 
    577                 @returns #leaves that were chosen for tighter bounds. 
    578         */ 
    579         int PostProcessLeaves(BvhLeafContainer &leaves); 
    580                  
    581          
     576        /** Does some postprocessing on the nodes. 
     577        */ 
     578        //void PostProcess(); 
     579        /** Helper method that updates the number of leaves in the subtree under 
     580                this node. 
     581        */ 
     582        void UpdateNumLeaves(BvhNode *node) const; 
     583 
    582584        //////////////////////// 
    583585 
     
    619621        int mNumNodes; 
    620622 
     623        /// the bounding box 
     624        AxisAlignedBox3 mBox; 
    621625 
    622626        ////////////// 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp

    r2755 r2760  
    1919 
    2020 
    21 BvhLeaf *BvhLoader::ImportBinLeaf(ifstream &stream, BvhInterior *parent) 
    22 { 
    23         BvhLeaf *leaf = new BvhLeaf(parent); 
    24  
    25         int first, last; 
    26  
    27         stream.read(reinterpret_cast<char *>(&first), sizeof(int)); 
    28         stream.read(reinterpret_cast<char *>(&last), sizeof(int)); 
    29  
    30         leaf->mFirst = first; 
    31         leaf->mLast = last; 
    32  
    33         return leaf; 
    34 } 
    35  
    36  
    37 BvhInterior *BvhLoader::ImportBinInterior(ifstream &stream, BvhInterior *parent) 
    38 { 
    39         BvhInterior *interior = new BvhInterior(parent); 
    40  
    41         stream.read(reinterpret_cast<char *>(&interior->mAxis), sizeof(char)); 
    42         stream.read(reinterpret_cast<char *>(&interior->mPosition), sizeof(float)); 
    43  
    44         return interior; 
    45 } 
    46  
    47  
    4821BvhNode *BvhLoader::LoadNextNode(ifstream &stream, BvhInterior *parent) 
    4922{ 
     
    5124        stream.read(reinterpret_cast<char *>(&nodeType), sizeof(int)); 
    5225 
     26        BvhNode *node; 
     27 
    5328        if (nodeType == TYPE_LEAF) 
    5429        { 
    55                 //OUT1("l"); 
    56                 return ImportBinLeaf(stream, static_cast<BvhInterior *>(parent)); 
     30                // cout << "l"; 
     31                node = new BvhLeaf(parent); 
     32        } 
     33        else if (nodeType == TYPE_INTERIOR) 
     34        { 
     35                //cout << "i"; 
     36                node = new BvhInterior(parent); 
     37        } 
     38        else 
     39        { 
     40                cerr << "wrong node type: " << nodeType << endl; 
     41                //exit(0); 
    5742        } 
    5843 
    59         if (nodeType == TYPE_INTERIOR) 
    60         { 
    61                 //OUT1("i"); 
    62                 return ImportBinInterior(stream, static_cast<BvhInterior *>(parent)); 
    63         } 
     44        Vector3 bMin, bMax; 
    6445 
    65         return NULL; 
     46        stream.read(reinterpret_cast<char *>(&(node->mFirst)), sizeof(int)); 
     47        stream.read(reinterpret_cast<char *>(&(node->mLast)), sizeof(int)); 
     48        stream.read(reinterpret_cast<char *>(&bMin), sizeof(Vector3)); 
     49        stream.read(reinterpret_cast<char *>(&bMax), sizeof(Vector3)); 
     50 
     51        node->mBox = AxisAlignedBox3(bMin, bMax); 
     52 
     53        node->mArea = node->mBox.SurfaceArea(); 
     54 
     55        //cout << "box: " << node->mBox << " area: " << node->mArea << endl; 
     56 
     57        return node; 
    6658} 
    6759 
    6860 
    69 Bvh *BvhLoader::LoadFromFile(const string &filename,   
    70                                                         const SceneEntityContainer &entities) 
     61Bvh *BvhLoader::Load(const string &filename,   
     62                                        const SceneEntityContainer &entities) 
    7163{ 
    7264        // export binary version of mesh 
     
    7769 
    7870        cout << "loading bvh" << endl; 
    79         Bvh *bvh = new Bvh(); 
    8071 
    81         bvh->mGeometrySize = entities.size(); 
    82         bvh->mGeometry = new SceneEntity*[bvh->mGeometrySize]; 
    83  
    84         for (size_t i = 0; i < bvh->mGeometrySize; ++ i) 
    85                 bvh->mGeometry[i] = entities[i]; 
    86  
     72        Bvh *bvh = new Bvh(entities); 
    8773        bvh->mRoot = LoadNextNode(stream, NULL); 
    8874 
     
    117103        cout << "... finished loading " << bvh->mNumNodes << " nodes, updating boxes" << endl; 
    118104 
    119         //adjust bounding boxes 
    120         //bvh->UpdateBoxes(bvh->mRoot); 
    121         //bvh->UpdateNumLeaves(bvh->mRoot); 
     105        /////////// 
     106        //-- post process 
    122107 
     108        bvh->UpdateNumLeaves(bvh->mRoot); 
    123109        // compute unique ids 
    124         //bvh->ComputeIds(); 
    125         // update the indices of the geometry so we can render interiors as well 
    126         //bvh->UpdateInteriors(bvh->mRoot); 
    127         // do this once so at least the current node bounding box is tested 
    128         //bvh->RecomputeBounds(); 
     110        bvh->ComputeIds(); 
     111        // specify bounds for occlusion tests 
     112        bvh->RecomputeBounds(); 
     113        // compute and print stats 
     114        bvh->ComputeBvhStats(); 
     115        bvh->PrintBvhStats(); 
    129116 
    130117        return bvh; 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.h

    r2755 r2760  
    1616public: 
    1717 
    18         Bvh *LoadFromFile(const std::string &filename, const SceneEntityContainer &entities); 
     18        Bvh *Load(const std::string &filename, const SceneEntityContainer &entities); 
    1919 
    2020protected: 
    2121         
    22         BvhLeaf *ImportBinLeaf(std::ifstream &stream, BvhInterior *parent); 
    23  
    24         BvhInterior *ImportBinInterior(std::ifstream &stream, BvhInterior *parent); 
    25  
    2622        BvhNode *LoadNextNode(std::ifstream &stream, BvhInterior *parent); 
    27  
    28  
    2923}; 
    3024 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp

    r2756 r2760  
    1212        mWidth = 100; 
    1313        mHeight = 100; 
    14         mFovy = 90.0f * M_PI/180.0f; 
     14        mFovy = 90.0f * M_PI / 180.0f; 
    1515} 
    1616 
     
    2121        mHeight = height; 
    2222         
    23         mFovy = fieldOfView * M_PI/180.0f; 
     23        mFovy = fieldOfView * M_PI / 180.0f; 
    2424} 
    2525 
     
    7474void Camera::GetProjectionMatrix(Matrix4x4 &mat) 
    7575{ 
    76         //float m[16]; 
    77          
    7876        glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat.x); 
    79         //mat = Matrix4x4((const float *)m); 
    8077} 
    8178 
     
    8380void Camera::GetModelViewMatrix(Matrix4x4 &mat) 
    8481{ 
    85         //float m[16]; 
    86  
    8782        glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mat.x); 
    88         //mat = Matrix4f((const float *)m); 
    8983} 
    9084 
     
    10094        matProjectionView *= matViewing; 
    10195 
    102          
    10396        float fInvLength; 
    104  
    10597        float planes[6][4]; 
    10698 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp

    r2757 r2760  
    11#include "FrustumCullingTraverser.h" 
     2#include "SceneEntity.h" 
     3 
    24 
    35namespace CHCDemo 
     
    1113void FrustumCullingTraverser::Render() 
    1214{ 
     15        mRenderState->mTexturesEnabled = false; 
     16        mDistanceQueue.push(mBvh->GetRoot()); 
     17 
    1318        while (!mDistanceQueue.empty()) 
    1419        { 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp

    r2759 r2760  
    2020        mAmbientColor = RgbColor(0.2, 0.2, 0.2); 
    2121        mDiffuseColor = RgbColor(1, 1, 1); 
    22         //mSpecularColor = RgbColor(0.5, 0.5, 0.5); 
    23         mSpecularColor = RgbColor(1, 1, 1); 
     22        mSpecularColor = RgbColor(0.0, 0.0, 0.0); 
     23        //mSpecularColor = RgbColor(1, 1, 1); 
    2424} 
    2525 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp

    r2755 r2760  
    6868        if (node->IsLeaf()) 
    6969        { 
    70                 //mNumRenderedGeometry += node->Render(); 
     70                //mNumRenderedGeometry += 
     71                mBvh->Render(node, mRenderState); 
    7172        } 
    7273        else  
     
    8182} 
    8283 
     84 
     85void RenderTraverser::SetHierarchy(Bvh *bvh) 
     86{ 
     87        mBvh = bvh; 
     88        //DelQueries(); 
     89} 
     90 
     91 
     92void RenderTraverser::SetRenderState(RenderState *state) 
     93{ 
     94        mRenderState = state; 
     95        //DelQueries(); 
     96} 
     97 
     98 
    8399#if 0 
     100 
     101Bvh *RenderTraverser::GetHierarchy() 
     102{ 
     103        return mBvh; 
     104} 
     105 
    84106 
    85107void RenderTraverser::RenderVisualization() 
     
    135157} 
    136158 
    137 void RenderTraverser::SetHierarchy(HierarchyNode *sceneRoot) 
    138 { 
    139         mHierarchyRoot = sceneRoot; 
    140  
    141         DelQueries(); 
    142 } 
    143  
    144 HierarchyNode *RenderTraverser::GetHierarchy() 
    145 { 
    146         return mHierarchyRoot; 
    147 } 
    148159 
    149160unsigned int RenderTraverser::GetOcclusionQueryResult(HierarchyNode *node) const 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h

    r2755 r2760  
    1212class Camera; 
    1313class Matrix4x4; 
     14 
    1415 
    1516 
     
    8384        */ 
    8485        void SetUseOptimization(bool useOptimization); 
     86        /** Sets the current render state 
     87        */ 
     88        void SetRenderState(RenderState *state); 
     89 
    8590 
    8691protected: 
     
    113118        void EnqueueNode(BvhNode *node); 
    114119 
     120 
    115121        //////////// 
    116122        //-- members 
     
    138144        //bool mIntersects; 
    139145        bool mUseOptimization; 
     146 
     147        RenderState *mRenderState; 
    140148}; 
    141149 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp

    r2759 r2760  
    1313#include "Camera.h" 
    1414#include "Geometry.h" 
     15#include "BvhLoader.h" 
     16#include "FrustumCullingTraverser.h" 
     17 
    1518 
    1619 
     
    3033/// the scene bounding box 
    3134AxisAlignedBox3 sceneBox; 
     35/// the current render state 
     36RenderState state; 
    3237 
    3338// eye near plane distance 
    3439float nearDist = 0.1f;  
    35 int winWidth, winHeight; 
     40int winWidth = 1024; 
     41int winHeight = 768; 
    3642float winAspectRatio = 1.0f; 
    3743 
     
    4450bool showCreateParams = false; 
    4551 
    46  
    47 Vector3 eyePos = Vector3(0.0f, 0.0f, 3.0f);    // eye position  
    48 Vector3 viewDir = Vector3(0.0f, 0.0f, -1.0f);  // eye view dir  
    49 Vector3 lightDir = Vector3(0.0f, 0.0f, 1.0f);  // light dir  
    50  
    51 Matrix4x4 visView; // visualisation view matrix 
     52int currentFrame = -1; 
     53 
     54// visualisation view matrix 
     55Matrix4x4 visView;  
    5256 
    5357//mouse navigation state 
    5458int xEyeBegin, yEyeBegin, yMotionBegin, verticalMotionBegin, horizontalMotionBegin = 0; 
    5559//int renderMode = RenderTraverser::RENDER_COHERENT; 
    56  
    5760 
    5861const int renderTimeSize = 100; 
     
    100103int main(int argc, char* argv[]) 
    101104{ 
    102         camera = new Camera(800, 600); 
    103  
    104         glutInitWindowSize(800, 600); 
     105        camera = new Camera(winWidth, winHeight); 
     106 
     107        glutInitWindowSize(winWidth, winHeight); 
    105108        glutInit(&argc, argv); 
    106109        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); 
     
    124127 
    125128        //const string filename("house_test.dem"); 
    126         const string filename("city_demo.dem"); 
     129        //const string filename("city_demo.dem"); 
     130        const string filename("city.dem"); 
    127131 
    128132        if (loader.Load(filename, sceneEntities)) 
     
    131135                cerr << "loading scene " << filename << " failed" << endl; 
    132136 
    133         sceneBox.Initialize(); 
    134  
    135         SceneEntityContainer::const_iterator it, it_end = sceneEntities.end(); 
    136  
    137         for (it = sceneEntities.begin(); it != it_end; ++ it) 
    138                 sceneBox.Include((*it)->GetBoundingBox()); 
    139  
    140         cout << "scene box: " << sceneBox << endl; 
    141  
     137        BvhLoader bvhLoader; 
     138        bvh = bvhLoader.Load("city.bvh", sceneEntities); 
     139 
     140        sceneBox = bvh->GetBox(); 
     141 
     142        traverser = new FrustumCullingTraverser(); 
     143        traverser->SetHierarchy(bvh); 
     144        traverser->SetRenderState(&state); 
    142145 
    143146        //SetupProjection(800, 600, 60, sceneBox); 
     
    162165void InitGLstate(void)  
    163166{ 
    164         glClearColor(0.0f, 0.0f, 0.0f, 0.0); 
     167        glClearColor(0.5f, 0.5f, 0.8f, 0.0); 
    165168         
    166169        glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
     
    171174        SetupLighting(); 
    172175 
    173         glColor3f(1.0f, 0.0f, 0.0f); 
     176        glColor3f(1.0f, 1.0f, 1.0f); 
    174177        glShadeModel(GL_SMOOTH); 
    175          
    176178         
    177179        glMaterialf(GL_FRONT, GL_SHININESS, 64); 
     
    190192        glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor); 
    191193        glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor); 
    192  
    193         glColor3f(1.0f, 0.0f, 0.0f); 
    194194        //setupVisView(); 
    195195} 
     
    277277        GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; 
    278278        GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; 
     279        //GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; 
    279280        GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; 
    280281             
     
    286287        glLightfv(GL_LIGHT0, GL_SPECULAR, specular); 
    287288 
    288         GLfloat position[] = {0.0, 3.0, 3.0, 0.0}; 
     289        GLfloat position[] = {1.0, 1.0, 1.0, 0.0}; 
    289290        glLightfv(GL_LIGHT0, GL_POSITION, position); 
    290291 
     
    293294        //-- second light 
    294295 
    295         GLfloat ambient1[] = {0.2, 0.2, 0.2, 1.0}; 
     296        GLfloat ambient1[] = {0.5, 0.5, 0.5, 1.0}; 
     297        //GLfloat diffuse1[] = {1.0, 1.0, 1.0, 1.0}; 
    296298        GLfloat diffuse1[] = {0.5, 0.5, 0.5, 1.0}; 
    297         GLfloat specular1[] = {0.0, 0.0, 0.0, 1.0}; 
     299        GLfloat specular1[] = {0.5, 0.5, 0.5, 1.0}; 
    298300 
    299301        glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1); 
     
    314316void SetupEyeView(void) 
    315317{ 
    316          
    317318        glMatrixMode(GL_PROJECTION); 
    318319        glLoadIdentity(); 
     
    323324        glLoadIdentity();        
    324325 
    325         GLfloat position[] = {0.0f, 3.0f, 3.0f, 0.0f}; 
     326        camera->SetupCameraView(); 
     327 
     328        GLfloat position[] = {0.8f, 1.0f, 1.5f, 0.0f}; 
    326329        glLightfv(GL_LIGHT0, GL_POSITION, position); 
    327330 
    328         GLfloat position1[] = {sceneBox.Center().x, sceneBox.Center().y, sceneBox.Center().z, 1.0f}; 
     331        GLfloat position1[] = {sceneBox.Center().x, sceneBox.Max().y, sceneBox.Center().z, 1.0f}; 
     332        //GLfloat position1[] = {-2.0f, 1.0f, 0.0f, 0.0f}; 
    329333        glLightfv(GL_LIGHT1, GL_POSITION, position1); 
    330  
    331         camera->SetupCameraView(); 
    332  
    333  
    334334} 
    335335 
     
    374374*/ 
    375375         
     376        ++ currentFrame; 
    376377 
    377378        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     
    380381        SetupEyeView(); 
    381382 
     383        bvh->InitFrame(camera, currentFrame); 
     384 
     385 
    382386        InitTiming(); 
    383387 
     
    389393        glEnableClientState(GL_NORMAL_ARRAY); 
    390394 
     395        traverser->Render(); 
     396/* 
    391397        bool usesTextures = false; 
    392398 
     
    412418                entity->Render(); 
    413419        } 
    414  
     420*/ 
    415421        glDisableClientState(GL_VERTEX_ARRAY); 
    416422        glDisableClientState(GL_NORMAL_ARRAY); 
     
    568574{ 
    569575        // used to avoid vertical motion with the keys 
    570         Vector3 hvec = Vector3(viewDir[0], 0, viewDir[2]); 
     576        //Vector3 hvec = Vector3(viewDir[0], 0, viewDir[2]); 
    571577         
    572578        switch(c)  
Note: See TracChangeset for help on using the changeset viewer.