Show
Ignore:
Timestamp:
08/18/05 10:37:01 (9 years ago)
Author:
robert
Message:

Implemented more SceneView? operations in main as a move to try and replace SceneView? usage in this example.

Files:
1 modified

Legend:

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

    r4439 r4440  
    1313 
    1414#include <iostream> 
     15 
     16 
     17 
     18//////////////////////////////////////////////////////////////////////////////// 
     19// 
     20// 
     21//  **************** THIS IS AN EXPERIMENTAL IMPLEMENTATION *************** 
     22//  ************************** PLEASE DO NOT COPY  ************************ 
     23// 
     24// 
     25/////////////////////////////////////////////////////////////////////////////// 
     26 
    1527 
    1628#if 1 
     
    5466    // create the view of the scene. 
    5567    osg::ref_ptr<osg::CameraNode> camera = new osg::CameraNode; 
     68    camera->setRenderOrder(osg::CameraNode::NESTED_RENDER); 
     69    camera->setClearColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); 
     70    camera->setCullingActive(false); 
     71     
    5672    camera->addChild(loadedModel.get()); 
     73     
     74     
    5775 
    5876    // initialize the view to look at the center of the scene graph 
     
    7290    osg::ref_ptr<osgUtil::CullVisitor> cullVisitor = new osgUtil::CullVisitor; 
    7391 
    74     cullVisitor->setRenderGraph(new osgUtil::RenderGraph); 
     92    osg::ref_ptr<osgUtil::RenderGraph> renderGraph = new osgUtil::RenderGraph; 
     93    cullVisitor->setRenderGraph(renderGraph.get()); 
    7594 
    7695    osg::ref_ptr<osgUtil::RenderStage> renderStage = new osgUtil::RenderStage; 
     
    86105         
    87106        updateVisitor->reset(); 
    88         cullVisitor->reset(); 
    89          
     107                 
    90108        // pass frame stamp to the SceneView so that the update, cull and draw traversals all use the same FrameStamp 
    91109        updateVisitor->setFrameStamp(frameStamp.get()); 
    92110        updateVisitor->setTraversalNumber(frameStamp->getFrameNumber()); 
    93111 
     112         
     113        // set the view 
     114        camera->setViewMatrix(viewMatrix); 
     115 
     116        // do the update traversal the scene graph - such as updating animations 
     117        camera->accept(*updateVisitor); 
     118         
     119        cullVisitor->reset(); 
    94120        cullVisitor->setFrameStamp(frameStamp.get()); 
    95121        cullVisitor->setTraversalNumber(frameStamp->getFrameNumber()); 
     122 
    96123         
    97124        // update the viewport dimensions, incase the window has been resized. 
    98125        camera->setViewport(0,0,traits->_width,traits->_height); 
     126 
     127        renderGraph->clean(); 
     128        renderStage->reset(); 
    99129        renderStage->setViewport(camera->getViewport()); 
    100130         
     131        osg::ref_ptr<osg::RefMatrix> proj = new osg::RefMatrix(camera->getProjectionMatrix()); 
     132        osg::ref_ptr<osg::RefMatrix> mv = new osg::RefMatrix(camera->getViewMatrix()); 
     133 
    101134        cullVisitor->pushViewport(camera->getViewport()); 
    102          
    103         // set the view 
    104         camera->setViewMatrix(viewMatrix); 
    105  
    106         // do the update traversal the scene graph - such as updating animations 
    107         camera->accept(*updateVisitor); 
    108          
     135        cullVisitor->pushProjectionMatrix(proj.get()); 
     136        cullVisitor->pushModelViewMatrix(mv.get()); 
     137 
    109138        // do the cull traversal, collect all objects in the view frustum into a sorted set of rendering bins 
    110         camera->accept(*cullVisitor); 
    111          
     139        //camera->accept(*cullVisitor); 
     140        loadedModel->accept(*cullVisitor); 
     141 
     142        cullVisitor->popModelViewMatrix(); 
     143        cullVisitor->popProjectionMatrix(); 
    112144        cullVisitor->popViewport(); 
    113145         
     146        renderStage->sort(); 
     147 
     148        // prune out any empty RenderGraph children. 
     149        // note, this would be not required if the rendergraph had been 
     150        // reset at the start of each frame (see top of this method) but 
     151        // a clean has been used instead to try to minimize the amount of 
     152        // allocation and deleteing of the RenderGraph nodes. 
     153        renderGraph->prune(); 
     154         
     155        renderStage->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 
     156         
     157        gfxc->getState()->setInitialViewMatrix(mv.get()); 
     158 
     159        std::cout<<"before"<<std::endl; 
     160 
    114161        // draw traversal 
    115162        osgUtil::RenderLeaf* previous = NULL; 
     
    118165        // Swap Buffers 
    119166        gfxc->swapBuffers(); 
     167         
     168        std::cout<<"swap"<<std::endl; 
    120169    } 
    121170