- Timestamp:
- 06/04/04 10:40:15 (9 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgprerendercubemap/osgprerendercubemap.cpp
r2233 r3033 12 12 #include <osg/PositionAttitudeTransform> 13 13 14 #include <osg/MatrixTransform> 15 14 16 #include <osgUtil/RenderToTextureStage> 15 17 #include <osgUtil/Optimizer> 18 #include <osgUtil/TransformCallback> 16 19 17 20 #include <osgDB/ReadFile> … … 28 31 #include <vector> 29 32 30 31 //#define UPDATE_ONE_IMAGE_PER_FRAME 1 33 #define UPDATE_ONE_IMAGE_PER_FRAME 1 32 34 33 35 … … 73 75 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) 74 76 { 77 // Reset this counter to zero, otherwise it wont do the while loop down below. 78 // And the cubemap will never update the newer frames. 79 if (_updateCubemapFace > 5) 80 _updateCubemapFace = 0; 81 75 82 osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv); 76 83 if (cv && _cubemap.valid() && _subgraph.valid()) … … 95 102 { 96 103 _clearColor = clearColArray[_updateCubemapFace]; 97 doPreRender(* cv, _updateCubemapFace++);104 doPreRender(*node, *cv, _updateCubemapFace++); 98 105 } 99 106 #else … … 101 108 { 102 109 _clearColor = clearColArray[_updateCubemapFace]; 103 doPreRender(* cv, _updateCubemapFace++);104 } 110 doPreRender(*node, *cv, _updateCubemapFace++); 111 } 105 112 #endif 106 113 } 107 114 108 115 // must traverse the subgraph 109 116 traverse(node,nv); 110 117 } 111 112 void doPreRender(osg Util::CullVisitor& cv, const int nFace);118 119 void doPreRender(osg::Node& node, osgUtil::CullVisitor& cv, const int nFace); 113 120 114 121 struct ImageData … … 128 135 129 136 130 void PrerenderCullCallback::doPreRender(osg Util::CullVisitor& cv, const int nFace)137 void PrerenderCullCallback::doPreRender(osg::Node& /*node*/, osgUtil::CullVisitor& cv, const int nFace) 131 138 { 132 139 const ImageData id[] = … … 222 229 } 223 230 224 int height = 128;225 int width = 128;231 int height = 512; 232 int width = 512; 226 233 227 234 const osg::Viewport& viewport = *cv.getViewport(); … … 244 251 245 252 // if one exist attach image to the RenderToTextureStage. 246 // if (_image.valid()) rtts->setImage(_image.get());253 // if (image.valid()) rtts->setImage(_image.get()); 247 254 if (image) rtts->setImage(image); 248 255 } … … 254 261 return new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),radius)); 255 262 } 256 257 263 258 264 osg::Node* createPreRenderSubGraph(osg::Node* subgraph) … … 447 453 #if 1 448 454 osg::Node* sky = osgDB::readNodeFile("skydome.osg"); 449 if (sky) 450 rootNode->addChild(createPreRenderSubGraph(sky)); 455 456 // Proof of concept to see if the skydome really rotates and that the cubemap gets updated. 457 // create a transform to spin the model. 458 459 osg::MatrixTransform* loadedModelTransform = new osg::MatrixTransform; 460 loadedModelTransform->addChild(sky); 461 462 osg::NodeCallback* nc = new osgUtil::TransformCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(5.0f)); 463 loadedModelTransform->setUpdateCallback(nc); 464 465 // osg::Group* rootNode = new osg::Group(); 466 // rootNode->addChild(loadedModelTransform); 467 // rootNode->addChild(createPreRenderSubGraph(loadedModelTransform)); 468 469 470 if (loadedModelTransform) 471 { 472 rootNode->addChild(createPreRenderSubGraph(loadedModelTransform)); 473 } 451 474 #endif 452 475 … … 457 480 rootNode->addChild(pat); 458 481 #endif 482 459 483 // load the nodes from the commandline arguments. 460 484 osg::Node* loadedModel = osgDB::readNodeFiles(arguments); … … 462 486 rootNode->addChild(loadedModel); 463 487 464 465 488 // add model to the viewer. 466 489 viewer.setSceneData( rootNode ); 467 468 490 469 491 // create the windows and run the threads.
