Changeset 4440 for OpenSceneGraph/trunk/examples/osgcamera/osgcamera.cpp
- Timestamp:
- 08/18/05 10:37:01 (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgcamera/osgcamera.cpp
r4439 r4440 13 13 14 14 #include <iostream> 15 16 17 18 //////////////////////////////////////////////////////////////////////////////// 19 // 20 // 21 // **************** THIS IS AN EXPERIMENTAL IMPLEMENTATION *************** 22 // ************************** PLEASE DO NOT COPY ************************ 23 // 24 // 25 /////////////////////////////////////////////////////////////////////////////// 26 15 27 16 28 #if 1 … … 54 66 // create the view of the scene. 55 67 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 56 72 camera->addChild(loadedModel.get()); 73 74 57 75 58 76 // initialize the view to look at the center of the scene graph … … 72 90 osg::ref_ptr<osgUtil::CullVisitor> cullVisitor = new osgUtil::CullVisitor; 73 91 74 cullVisitor->setRenderGraph(new osgUtil::RenderGraph); 92 osg::ref_ptr<osgUtil::RenderGraph> renderGraph = new osgUtil::RenderGraph; 93 cullVisitor->setRenderGraph(renderGraph.get()); 75 94 76 95 osg::ref_ptr<osgUtil::RenderStage> renderStage = new osgUtil::RenderStage; … … 86 105 87 106 updateVisitor->reset(); 88 cullVisitor->reset(); 89 107 90 108 // pass frame stamp to the SceneView so that the update, cull and draw traversals all use the same FrameStamp 91 109 updateVisitor->setFrameStamp(frameStamp.get()); 92 110 updateVisitor->setTraversalNumber(frameStamp->getFrameNumber()); 93 111 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(); 94 120 cullVisitor->setFrameStamp(frameStamp.get()); 95 121 cullVisitor->setTraversalNumber(frameStamp->getFrameNumber()); 122 96 123 97 124 // update the viewport dimensions, incase the window has been resized. 98 125 camera->setViewport(0,0,traits->_width,traits->_height); 126 127 renderGraph->clean(); 128 renderStage->reset(); 99 129 renderStage->setViewport(camera->getViewport()); 100 130 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 101 134 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 109 138 // 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(); 112 144 cullVisitor->popViewport(); 113 145 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 114 161 // draw traversal 115 162 osgUtil::RenderLeaf* previous = NULL; … … 118 165 // Swap Buffers 119 166 gfxc->swapBuffers(); 167 168 std::cout<<"swap"<<std::endl; 120 169 } 121 170
