Ignore:
Timestamp:
06/14/08 19:04:01 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.