Ignore:
Timestamp:
06/22/08 09:23:45 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2782 r2796  
    1818 
    1919const static int viewport[4] = {0, 0, 512, 512}; 
    20 //static DepthComponent<float> *sDepth = NULL; 
     20//const static int viewport[4] = {0, 0, 1024, 768}; 
    2121 
    2222 
    2323 
    2424SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *renderer):  
    25 mSceneBox(sceneBox) 
     25mSceneBox(sceneBox), mDepth(NULL) 
    2626{ 
    2727        Prepare(renderer); 
     
    3232{ 
    3333        int px = (pt.x - mSceneBox.Min(0)) * (viewport[2] - 1) / mSceneBox.Size(0); 
    34         int py = (pt.y - mSceneBox.Min(2)) * (viewport[3] - 1) /  mSceneBox.Size(2); 
     34        int py = (pt.y - mSceneBox.Min(1)) * (viewport[3] - 1) / mSceneBox.Size(1); 
    3535 
    36         const float d = 1.0f;// - sDepth->getPixel(px, py); 
     36        const float d = mDepth[px + py * viewport[1]]; 
    3737 
    3838        if (d > 0.0f) 
    3939        { 
    40                 pt.z = mSceneBox.Size(2) * d + mSceneBox.Min(2); 
     40                pt.z =  mSceneBox.Min().z + mSceneBox.Size().z * d; 
    4141                cout << "new depth " << pt.z << " (" << d << ")" << endl; 
    4242 
     
    5252        cout << "Preparing scene queries" << endl; 
    5353 
    54         // center camera on "highest" point 
    55         Vector3 pos; 
    56  
    57         pos.x = mSceneBox.Center(0); 
    58         pos.y = mSceneBox.Max(1); 
    59         pos.z = mSceneBox.Center(2); 
    60  
    61         // for ortho cam this is the width 
    62         const Vector3 len = mSceneBox.Size(); 
    63  
    64         Camera *orthoCam = new Camera(len.x, len.y); 
    65         //orthoCam->SetOrtho(true); 
     54        const float xlen = mSceneBox.Size().x * 0.5f; 
     55        const float ylen = mSceneBox.Size().y * 0.5f; 
     56         
     57        Camera *orthoCam = new Camera(xlen, ylen); 
     58        orthoCam->SetOrtho(true); 
    6659 
    6760        orthoCam->SetNear(0.0f); 
    68         //orthoCam->SetFar(len.z); 
     61        orthoCam->Yaw(M_PI * 0.5f); 
    6962 
     63        Vector3 pos = Vector3(mSceneBox.Center().x, mSceneBox.Center().y, mSceneBox.Max().z); 
    7064        orthoCam->SetPosition(pos); 
    7165 
    72         cout << "fov: " << orthoCam->GetFov() << endl; 
    73         cout << "near: " << orthoCam->GetNear() << endl; 
    74         //cout << "far: " << orthoCam->GetFar() << endl; 
    75         cout << "aspect: " << orthoCam->GetAspect() << endl; 
     66        glPixelStorei(GL_PACK_ROW_LENGTH, viewport[2]); 
    7667 
    77         cout << "pos: " << orthoCam->GetPosition() << endl; 
    78         cout << "view: " << orthoCam->GetDirection() << endl; 
    79         cout << "up: " << orthoCam->GetUpVector() << endl; 
     68        // hack: should create offscreen buffer for this 
     69        glViewport(0, 0, viewport[2], viewport[3]); 
    8070 
    81         //orthoCam->SetDirection(Vector3(0, 1, 0)); 
    82         //orthoCam->Yaw(M_PI * 0.5f); 
     71        glMatrixMode(GL_PROJECTION); 
     72        glLoadIdentity(); 
    8373         
    84         renderer->SetCamera(orthoCam); 
     74        glOrtho(-xlen, xlen, -ylen, ylen, 0.0f, mSceneBox.Size().z);  
     75         
     76        glMatrixMode(GL_MODELVIEW); 
     77         
     78        orthoCam->SetupCameraView(); 
    8579 
    86         //OffscreenRenderArea *of = new OffscreenRenderArea(); 
    87         //of->Init(viewport[2], viewport[3]); 
     80        glClear(GL_DEPTH_BUFFER_BIT); 
     81 
     82        mDepth = new float[viewport[2] * viewport[3]]; 
     83 
     84        //renderer->SetCamera(orthoCam); 
    8885 
    8986        renderer->RenderScene(); 
    90         //sDepth = of->GetDepthFloat(); 
    9187 
    92         delete orthoCam; 
     88        glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, mDepth); 
     89 
     90        DEL_PTR(orthoCam); 
    9391} 
    9492 
Note: See TracChangeset for help on using the changeset viewer.