Show
Ignore:
Timestamp:
02/20/07 12:44:10 (7 years ago)
Author:
robert
Message:

Added beginings of full dome correction support, starting with 6 slave camera
configuration.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgdistortion/osgdistortion.cpp

    r5923 r6242  
    170170} 
    171171 
     172void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments) 
     173{ 
     174  
     175    osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 
     176    if (!wsi)  
     177    { 
     178        osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; 
     179        return; 
     180    } 
     181 
     182    unsigned int width, height; 
     183    wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); 
     184 
     185    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; 
     186    traits->x = 0; 
     187    traits->y = 0; 
     188    traits->width = width; 
     189    traits->height = height; 
     190    traits->windowDecoration = true; 
     191    traits->doubleBuffer = true; 
     192    traits->sharedContext = 0; 
     193 
     194    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 
     195    if (!gc) 
     196    { 
     197        osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<<std::endl; 
     198        return; 
     199    } 
     200 
     201 
     202    int center_x = width/2; 
     203    int center_y = height/2; 
     204    int camera_width = 256; 
     205    int camera_height = 256; 
     206 
     207    // front face 
     208    { 
     209        osg::ref_ptr<osg::Camera> camera = new osg::Camera; 
     210        camera->setGraphicsContext(gc.get()); 
     211        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y, camera_width, camera_height)); 
     212        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; 
     213        camera->setDrawBuffer(buffer); 
     214        camera->setReadBuffer(buffer); 
     215 
     216        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); 
     217    } 
     218     
     219    // top face 
     220    { 
     221        osg::ref_ptr<osg::Camera> camera = new osg::Camera; 
     222        camera->setGraphicsContext(gc.get()); 
     223        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y+camera_height, camera_width, camera_height)); 
     224        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; 
     225        camera->setDrawBuffer(buffer); 
     226        camera->setReadBuffer(buffer); 
     227 
     228        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0)); 
     229    } 
     230 
     231    // left face 
     232    { 
     233        osg::ref_ptr<osg::Camera> camera = new osg::Camera; 
     234        camera->setGraphicsContext(gc.get()); 
     235        camera->setViewport(new osg::Viewport(center_x-camera_width*3/2, center_y, camera_width, camera_height)); 
     236        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; 
     237        camera->setDrawBuffer(buffer); 
     238        camera->setReadBuffer(buffer); 
     239 
     240        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0)); 
     241    } 
     242 
     243    // right face 
     244    { 
     245        osg::ref_ptr<osg::Camera> camera = new osg::Camera; 
     246        camera->setGraphicsContext(gc.get()); 
     247        camera->setViewport(new osg::Viewport(center_x+camera_width/2, center_y, camera_width, camera_height)); 
     248        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; 
     249        camera->setDrawBuffer(buffer); 
     250        camera->setReadBuffer(buffer); 
     251 
     252        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0)); 
     253    } 
     254 
     255    // bottom face 
     256    { 
     257        osg::ref_ptr<osg::Camera> camera = new osg::Camera; 
     258        camera->setGraphicsContext(gc.get()); 
     259        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y-camera_height, camera_width, camera_height)); 
     260        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; 
     261        camera->setDrawBuffer(buffer); 
     262        camera->setReadBuffer(buffer); 
     263 
     264        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0)); 
     265    } 
     266 
     267    // back face 
     268    { 
     269        osg::ref_ptr<osg::Camera> camera = new osg::Camera; 
     270        camera->setGraphicsContext(gc.get()); 
     271        camera->setViewport(new osg::Viewport(center_x-camera_width/2, center_y-2*camera_height, camera_width, camera_height)); 
     272        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; 
     273        camera->setDrawBuffer(buffer); 
     274        camera->setReadBuffer(buffer); 
     275 
     276        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-180.0f), 1.0,0.0,0.0)); 
     277    } 
     278     
     279    viewer.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); 
     280 
     281    viewer.assignSceneDataToCameras(); 
     282} 
    172283 
    173284int main(int argc, char** argv) 
     
    186297        return 1; 
    187298    } 
    188      
    189     osg::Node* distortionNode = createDistortionSubgraph(loadedModel, viewer.getCamera()->getClearColor()); 
    190      
    191     // add model to the viewer. 
    192     viewer.setSceneData( distortionNode ); 
     299 
     300    if (arguments.read("--dome")) 
     301    {     
     302        viewer.setSceneData( loadedModel ); 
     303 
     304        setDomeCorrection(viewer, arguments); 
     305     
     306    } 
     307    else 
     308    { 
     309        osg::Node* distortionNode = createDistortionSubgraph(loadedModel, viewer.getCamera()->getClearColor()); 
     310 
     311        // add model to the viewer. 
     312        viewer.setSceneData( distortionNode ); 
     313    } 
    193314 
    194315    return viewer.run();