Changeset 2806 for GTP/trunk


Ignore:
Timestamp:
06/29/08 02:31:58 (16 years ago)
Author:
mattausch
Message:

improved visualization

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
8 edited

Legend:

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

    r2801 r2806  
    33        ProjectType="Visual C++" 
    44        Version="8,00" 
    5         Name="chc_revisited" 
     5        Name="friendlyculling" 
    66        ProjectGUID="{03661866-4093-4B02-B26A-028EA91AF023}" 
    77        RootNamespace="chc_revisited" 
     
    243243                        </File> 
    244244                        <File 
    245                                 RelativePath=".\src\ResourceManager.cpp" 
    246                                 > 
    247                         </File> 
    248                         <File 
    249                                 RelativePath=".\src\ResourceManager.h" 
    250                                 > 
    251                         </File> 
    252                         <File 
    253245                                RelativePath=".\src\SceneQuery.cpp" 
    254246                                > 
     
    458450                </Filter> 
    459451                <Filter 
    460                         Name="render" 
     452                        Name="rendering" 
    461453                        > 
    462454                        <Filter 
     
    494486                                </File> 
    495487                                <File 
     488                                        RelativePath=".\src\ResourceManager.h" 
     489                                        > 
     490                                </File> 
     491                                <File 
    496492                                        RelativePath=".\src\SceneEntity.h" 
    497493                                        > 
     
    632628                                                /> 
    633629                                        </FileConfiguration> 
     630                                </File> 
     631                                <File 
     632                                        RelativePath=".\src\ResourceManager.cpp" 
     633                                        > 
    634634                                </File> 
    635635                                <File 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Readme.txt

    r2789 r2806  
    1 HARDWARE OCCLUSION QUERIES MADE USEFUL 
     1GAME ENGINE FRIENDLY OCCLUSION CULLING 
    22====================================== 
    33 
     
    3737SPACE key (view-frustum culling, hierarchical stop and wait, coherent hierarchical culling, chc++). 
    3838 
    39 A bird eye view visualization of the culling algorithm from can be shown by pressing '1' on the keyboard. 
    40  
     39A bird eye view visualization of the culling algorithm from can be shown by pressing 'F2' on the keyboard. 
     40Pressing 'F8' switches between using / not using the glFinish command, which causes slightly slower frame rates but brings more reliable fps measurements. 
    4141 
    4242---------- 
     
    5959------------- 
    6060 
    61 We use a simple OpenGL based engine which was designed to be as simple as possible while providing the necessary feature list to simulate the behaviour of full-fledged game engines like Ogre3D. The engine supports simple material sorting mainly based on the texture size, avoiding the mix of differently sized textures, which according to various sources induces one of the costliest state change. We demonstrate the integration of the culling algorithm into the engine, and show how occlusion cullig and state sorting are possible within one framework, two paradigms that were previously considered to be cancelling out each other ("either you do front-back-sorting or material sorting"). 
     61We use a simple OpenGL based engine which was designed to be as simple as possible while providing the necessary feature list to simulate the behaviour of full-fledged game engines like Ogre3D. The engine supports simple material sorting mainly based on the texture format, avoiding the mix of different texture formats, which according to various sources induces one of the costliest state change. We demonstrate the integration of the culling algorithm into the engine, and show how occlusion cullig and state sorting are possible within one framework, two paradigms that were previously considered to be cancelling out each other ("either you do front-back-sorting or material sorting"). 
    6262 
    6363 
     
    6666---------- 
    6767 
    68 A binary for Win32 and a solution for visual studio 2005 included. The program should work under XP and Windows Vista. 
     68A binary for Win32 and a solution for visual studio 2005 and 2003 included. The program should work under XP and Windows Vista. 
    6969 
    7070 
     
    7777The rendering core of the engine is provided by the class RenderTraverser, which provides front to back scene traversal based on a priority queue. It's subclasses implement the various culling algorithms. The new algorithm is represented by the class CHCPlusPlusTraverser. 
    7878 
    79 The main routine is implemented in chcdemo.cpp. Also it contains the OpenGl setup code, glut stuff, and sets up of the scene hierarchy. 
     79The main routine is implemented in chcdemo.cpp. Also it contains the OpenGl setup code, glut stuff, and setups of the scene hierarchy. 
    8080 
    81 The project is separated into one section containing supportive code (utils), the traversal algorithms (traversal), and the basic engine classes like Camera, Geometry, Material, or RenderState (scene).  
     81The project is separated into one section containing supportive code (utils), the traversal algorithms (traversal), and the basic engine classes like Camera, Geometry, Material, or RenderState (rendering).  
    8282 
    8383If you find any problem with the code or have any comments, please feel free to ask us at any time. 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp

    r2796 r2806  
    6666{ 
    6767        mNear = nearDist; 
     68} 
     69 
     70 
     71void Camera::SetFar(float farDist)  
     72{  
     73        mFar = farDist;  
    6874} 
    6975 
     
    165171                                                   Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) 
    166172{ 
    167         float z_near = 0.1f; 
    168         float z_far = 300; 
     173        float z_near = mNear; 
     174        float z_far = mFar; 
    169175 
    170176        const float h_near = 2.0f * tan(mFovy / 2) * z_near; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h

    r2796 r2806  
    4848 
    4949        void CalcFrustum(Frustum &frustum); 
    50  
     50        /** Computes the extremal points of this frustum. 
     51        */ 
    5152        void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
    5253                               Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr); 
    5354         
     55        /** Returns the near plane. 
     56        */ 
    5457        inline float GetNear() const { return mNear; } 
     58        /** Returns the far plane. 
     59        */ 
     60        inline float GetFar() const { return mFar; } 
     61        /** Sets the near plane 
     62        */ 
    5563        void SetNear(float nearDist); 
     64        /** Sets the far plane. 
     65        */ 
     66        void SetFar(float farDist); 
    5667         
    57         inline float GetFar() const { return mFar; } 
    58  
    59         void SetFar(float farDist) { mFar = farDist; } 
    60  
    6168        void SetOrtho(bool ortho); 
    6269 
     
    6471        void Pitch(float angle); 
    6572         
     73        float GetPitch() const { return mPitch; } 
     74        float GetYaw() const { return mYaw; } 
     75 
    6676 
    6777 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.h

    r2800 r2806  
    2121        SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *traverser); 
    2222        ~SceneQuery() { DEL_ARRAY_PTR(mDepth); } 
     23 
     24        /** Calculates intersection of vertical ray at position pt.x, pt.y and  
     25            stores the intersection point if valid. returns true if the intersection  
     26                is valid. 
     27        */ 
    2328        bool CalcIntersection(Vector3 &pt); 
     29 
    2430 
    2531protected: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp

    r2796 r2806  
    6464 
    6565/******************************************************/ 
    66 /*           Vizualization implementation           */ 
     66/*           Vizualization implementation             */ 
    6767/******************************************************/ 
    6868 
     
    7878mFrameId(0) 
    7979{ 
    80         mSphere = (GLUquadric *)gluNewQuadric(); 
    8180} 
    8281 
     
    8483Visualization::~Visualization()  
    8584{ 
    86         //DEL_PTR(mSphere); 
    8785} 
    8886 
     
    110108        stack<BvhNode *> tStack; 
    111109        tStack.push(mBvh->GetRoot()); 
    112  
    113         glDisable(GL_LIGHTING); 
    114          
    115         RenderViewPoint(); 
    116         RenderFrustum(); 
    117         RenderBoxForViz(mBvh->GetBox()); 
    118  
    119         glEnable(GL_LIGHTING); 
    120110 
    121111        glEnableClientState(GL_VERTEX_ARRAY); 
     
    147137                                }                
    148138                        } 
    149                         //leaves.push_back(static_cast<BvhLeaf *>(node)); 
    150139                } 
    151140        } 
    152141 
    153         mRenderState->Reset(); 
    154  
    155142        glDisableClientState(GL_VERTEX_ARRAY); 
    156143        glDisableClientState(GL_NORMAL_ARRAY); 
    157 } 
    158  
    159  
    160 void Visualization::RenderViewPoint() 
    161 { 
    162         glPushMatrix(); 
    163         Vector3 pos = mCamera->GetPosition(); 
    164         pos.z += 100; 
    165         glTranslatef(pos.x, pos.y, pos.z); 
     144 
     145 
     146        mRenderState->Reset(); 
     147 
     148        glPushAttrib(GL_CURRENT_BIT); 
     149        glDisable(GL_LIGHTING); 
     150        glDisable(GL_DEPTH_TEST); 
     151 
     152        RenderFrustum(); 
     153        //RenderBoxForViz(mBvh->GetBox()); 
    166154         
    167         glScalef(5.0f, 5.0f, 5.0f); 
    168         glPushAttrib(GL_CURRENT_BIT); 
    169  
    170         glColor3f(1.0f, 0.0f, 0.0f); 
    171          
    172         gluSphere((::GLUquadric *)mSphere, 
    173                 2e-3f * Magnitude(mBvh->GetBox().Size()), 6, 6); 
    174  
    175155        glPopAttrib(); 
    176         glPopMatrix(); 
    177156} 
    178157 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h

    r2796 r2806  
    2020{ 
    2121public: 
    22          
     22        /** Main constructor taking a bvh, a camera, a visualization camera and the current render state 
     23            as parameters 
     24        */ 
    2325        Visualization(Bvh *bvh, Camera *camera, Camera *vizCamera, RenderState *renderState); 
    2426 
     
    4951        */ 
    5052        void RenderFrustum(); 
    51         /** Renders the current view point. 
    52         */ 
    53         void RenderViewPoint(); 
    5453 
    5554 
     
    6766        /// the current frame id 
    6867        int mFrameId; 
    69  
    70         GLUquadric *mSphere; 
    7168}; 
    7269 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2803 r2806  
    163163        camera = new Camera(winWidth, winHeight, fov); 
    164164        camera->SetNear(nearDist); 
    165  
     165         
    166166        visCamera = new Camera(winWidth, winHeight, fov); 
     167 
    167168        visCamera->SetNear(0.0f); 
    168169        visCamera->Yaw(.5 * M_PI); 
     
    233234        } 
    234235 
     236        camera->SetFar(0.7f * Magnitude(bvh->GetBox().Diagonal())); 
     237 
    235238        bvh->SetCamera(camera); 
    236239 
    237240        ResetTraverser(); 
    238241 
    239         //camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 
    240242        camera->Pitch(-M_PI * 0.5); 
    241243        camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f)); 
     
    992994        glColor4f(0.0,0.0,0.0,0.5);  
    993995 
    994         glRecti(winWidth, 0, winWidth - winWidth / 4, winHeight / 3); 
     996        glRecti(winWidth, 0, winWidth - winWidth / 3, winHeight / 3); 
    995997        glDisable(GL_BLEND); 
    996998        End2D(); 
     
    10021004        const float yoffs = box.Size().y * 0.5f; 
    10031005 
    1004         Vector3 vizpos = Vector3(box.Center().x, box.Center().y, box.Max().z); 
     1006        Vector3 pos = camera->GetPosition(); 
     1007 
     1008        Vector3 vizpos = Vector3(box.Min().x, box.Min().y + 700, box.Min().z + box.Size().z * 50); 
     1009         
    10051010        visCamera->SetPosition(vizpos); 
    10061011         
    1007         glViewport(winWidth - winWidth / 4, winHeight - winHeight / 3, winWidth / 4, winHeight / 3); 
     1012        glViewport(winWidth - winWidth / 3, winHeight - winHeight / 3, winWidth / 3, winHeight / 3); 
    10081013 
    10091014        glMatrixMode(GL_PROJECTION); 
    10101015        glLoadIdentity(); 
    10111016         
    1012         glOrtho(-xoffs, xoffs, -yoffs, yoffs, 0.0f, box.Size().z);  
     1017        glOrtho(-xoffs, xoffs, -xoffs, xoffs, 0.0f, box.Size().z * 100.0f);  
    10131018 
    10141019        glMatrixMode(GL_MODELVIEW); 
    10151020 
    10161021        visCamera->SetupCameraView(); 
    1017          
     1022 
     1023        Matrix4x4 rotZ = RotationZMatrix(-camera->GetPitch()); 
     1024        glMultMatrixf((float *)rotZ.x); 
     1025 
     1026        glTranslatef(-pos.x, -pos.y, -pos.z); 
     1027 
     1028 
    10181029        GLfloat position[] = {0.8f, 1.0f, 1.5f, 0.0f}; 
    10191030        glLightfv(GL_LIGHT0, GL_POSITION, position); 
     
    10241035        glClear(GL_DEPTH_BUFFER_BIT); 
    10251036 
     1037 
    10261038        //////////// 
    10271039        //-- visualization of the occlusion culling 
     
    10291041        visualization->Render(); 
    10301042         
     1043        // reset vp 
    10311044        glViewport(0, 0, winWidth, winHeight); 
    10321045} 
Note: See TracChangeset for help on using the changeset viewer.