Changeset 70 for osgVisual/src/sky_Silverlining
- Timestamp:
- Jul 20, 2010, 9:24:42 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
osgVisual/src/sky_Silverlining/visual_skySilverLining.cpp
r64 r70 41 41 void visual_skySilverLining::skyUpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv) 42 42 { 43 std::cout << "Sky silverlining update callback" << std::endl; 43 44 // Check if atmosphere is initialized. 44 45 if (!sky->isInitialized()) … … 166 167 skyDrawable = new skySilverLining_skyDrawable(viewer, sceneRoot); 167 168 169 if(distortedRoot) // if distortion used: 170 { 171 int rootKids = distortedRoot->getNumChildren(); 172 for (int i = 0; i < rootKids; i++) 173 { 174 osg::Node *n = distortedRoot->getChild(i); 175 osg::Camera *cam = dynamic_cast<osg::Camera*>(n); 176 if (cam && cam->getRenderOrder() == osg::Camera::PRE_RENDER) 177 sceneCamera = cam; 178 } 179 } 180 else // if no distortion used: 181 sceneCamera = viewer->getCamera(); 182 168 183 osg::Camera *mainCamera = viewer->getCamera(); 169 184 if (!useProjMatrixCallback) … … 175 190 mainCamera->setProjectionMatrixAsPerspective(fovy, aspect, 2, 125000); 176 191 } 177 178 int rootKids = distortedRoot->getNumChildren();179 for (int i = 0; i < rootKids; i++)180 {181 osg::Node *n = distortedRoot->getChild(i);182 osg::Camera *cam = dynamic_cast<osg::Camera*>(n);183 if (cam)184 {185 if (cam->getRenderOrder() == osg::Camera::PRE_RENDER)186 {187 cam->setClearMask(0);188 189 osg::ref_ptr<skySilverLining_atmosphereReference> ar = new skySilverLining_atmosphereReference;190 ar->atmosphere = atmosphere;191 cam->setUserData(ar);192 mainCamera->setUserData(ar);193 sceneCamera = cam;194 195 if (useProjMatrixCallback)196 {197 skySilverLining_projectionMatrixCallback *cb = new skySilverLining_projectionMatrixCallback( atmosphere, viewer->getCamera(), sceneRoot);198 cam->setClampProjectionMatrixCallback(cb);199 cb->setSkyDrawable(skyDrawable);200 }201 }202 }203 }204 205 // Create and install updateCallback (for position etc.)206 updateCallback = new skyUpdateCallback( sceneGraphRoot, sceneCamera, this );207 this->setUpdateCallback( updateCallback );208 209 // Use a RenderBin to enforce that the sky gets drawn first, then the scene, then the clouds210 skyDrawable->getOrCreateStateSet()->setRenderBinDetails(-1, "RenderBin");211 212 // Add the models213 sceneGraphRoot->getOrCreateStateSet()->setRenderBinDetails(1, "RenderBin");214 215 // Add the clouds (note, you need this even if you don't want clouds - it calls216 // Atmosphere::EndFrame() )217 cloudsDrawable = new skySilverLining_cloudsDrawable(viewer);218 cloudsDrawable->getOrCreateStateSet()->setRenderBinDetails(99, "RenderBin");219 220 // Add drawable to this geode to get rendered221 this->addDrawable(skyDrawable);222 this->addDrawable(cloudsDrawable);223 }224 225 void visual_skySilverLining::init(osg::CoordinateSystemNode *sceneGraphRoot)226 {227 sceneRoot = sceneGraphRoot;228 229 // Use projection matrix callback oder fixed Cullsettings?230 bool useProjMatrixCallback = true;231 232 // add Sky to SceneRoot233 sceneGraphRoot->addChild( this );234 235 // Deactivate culling for the sky node (required by the silverlining sky framework)236 this->setCullingActive(false);237 238 // Instantiate an Atmosphere and associate it with this camera. If you have multiple cameras239 // in multiple contexts, be sure to instantiate seperate Atmosphere objects for each.240 // ***IMPORTANT!**** Check that the path to the resources folder for SilverLining in SkyDrawable.cpp241 // SkyDrawable::initializeSilverLining matches with where you installed SilverLining.242 atmosphere = new SilverLining::Atmosphere(SILVERLINING_LICENSEE, SILVERLINING_LICENSE);243 244 // Add the sky (calls Atmosphere::BeginFrame and handles initialization once you're in245 // the rendering thread)246 skyDrawable = new skySilverLining_skyDrawable(viewer, sceneRoot);247 248 if (!useProjMatrixCallback)249 {250 viewer->getCamera()->setClearMask(0);251 viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);252 double fovy, aspect, zNear, zFar;253 viewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar);254 viewer->getCamera()->setProjectionMatrixAsPerspective(fovy, aspect, 2, 125000);255 }256 192 else 257 193 { 258 194 cb = new skySilverLining_projectionMatrixCallback( atmosphere, viewer->getCamera(), sceneRoot); 259 viewer->getCamera()->setClampProjectionMatrixCallback(cb);195 sceneCamera->setClampProjectionMatrixCallback(cb); 260 196 cb->setSkyDrawable(skyDrawable); 261 197 } 262 198 263 264 viewer->getCamera()->setClearMask(0); 265 266 osg::ref_ptr<skySilverLining_atmosphereReference> ar = new skySilverLining_atmosphereReference; 199 // append atmosphere pointer to the cameras. 200 sceneCamera->setClearMask(0); 201 osg::ref_ptr<skySilverLining_atmosphereReference> ar = new skySilverLining_atmosphereReference; 267 202 ar->atmosphere = atmosphere; 268 viewer->getCamera()->setUserData(ar); 269 sceneCamera = viewer->getCamera(); 270 271 203 sceneCamera->setUserData(ar); 204 mainCamera->setUserData(ar); 205 272 206 // Create and install updateCallback (for position etc.) 273 207 updateCallback = new skyUpdateCallback( sceneGraphRoot, sceneCamera, this );
Note: See TracChangeset
for help on using the changeset viewer.