[31] | 1 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer |
---|
| 2 | * |
---|
| 3 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
---|
| 7 | * |
---|
| 8 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
| 9 | * You have to aquire licenses for all used proprietary modules. |
---|
| 10 | * |
---|
| 11 | * This library is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * OpenSceneGraph Public License for more details. |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include <visual_skySilverLining.h> |
---|
| 18 | |
---|
| 19 | using namespace osgVisual; |
---|
| 20 | |
---|
| 21 | visual_skySilverLining::visual_skySilverLining(osgViewer::Viewer* viewer_) |
---|
| 22 | { |
---|
[87] | 23 | OSG_NOTIFY( osg::ALWAYS ) << "Initialize visual_skySilverlining..." << std::endl; |
---|
| 24 | |
---|
[31] | 25 | atmosphereInitialized = false; |
---|
| 26 | postInitialized = false; |
---|
| 27 | atmosphere = NULL; |
---|
| 28 | viewer = viewer_; |
---|
[113] | 29 | lat = 0; |
---|
| 30 | lon = 0; |
---|
| 31 | upVectorLat = 5; // Just to ensure deltaLatToUpdate is big enough to enforce the sky to update at the first frame |
---|
| 32 | upVectorLon = 5; // Just to ensure deltaLonToUpdate is big enough to enforce the sky to update at the first frame |
---|
[31] | 33 | for( int i=0; i<MAX_CLOUDLAYER_SLOTS; i++ ) |
---|
| 34 | { |
---|
| 35 | cloudLayerSlots.push_back( cloudLayerSlot() ); |
---|
| 36 | cloudLayerSlots.back().slot_id = i; |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | visual_skySilverLining::~visual_skySilverLining(void) |
---|
| 41 | { |
---|
| 42 | this->removeUpdateCallback( updateCallback ); |
---|
| 43 | if ( atmosphere != NULL ) |
---|
| 44 | delete atmosphere; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void visual_skySilverLining::skyUpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv) |
---|
| 48 | { |
---|
[73] | 49 | //std::cout << "Sky silverlining update callback" << std::endl; |
---|
[31] | 50 | // Check if atmosphere is initialized. |
---|
| 51 | if (!sky->isInitialized()) |
---|
| 52 | return; |
---|
| 53 | |
---|
| 54 | // on first time: perform Post-Init. |
---|
| 55 | sky->postInit(); |
---|
| 56 | |
---|
| 57 | // Update sky |
---|
[73] | 58 | double lat, lon, height; |
---|
[31] | 59 | util::getWGS84ofCamera( sceneCamera, csn, lat, lon, height ); |
---|
| 60 | //std::cout << "lat: " << osg::RadiansToDegrees(lat) << ", lon: " << osg::RadiansToDegrees(lon) << ", height: " << height << std::endl; |
---|
| 61 | sky->setLocation( lat, lon, height ); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void visual_skySilverLining::setDateTime( int year_, int month_, int day_, int hour_, int minute_, int second_, bool daylightSaving_, double timezoneOffset_ ) |
---|
| 65 | { |
---|
| 66 | // Check if atmosphere is initialized. |
---|
| 67 | if (!isInitialized()) |
---|
| 68 | return; |
---|
| 69 | |
---|
| 70 | SilverLining::LocalTime t = atmosphere->GetConditions()->GetTime(); |
---|
| 71 | t.SetYear( year_ ); |
---|
| 72 | t.SetMonth( month_ ); |
---|
| 73 | t.SetDay( day_ ); |
---|
| 74 | t.SetHour( hour_ ); |
---|
| 75 | t.SetMinutes( minute_ ); |
---|
| 76 | t.SetSeconds( second_ ); |
---|
| 77 | t.SetObservingDaylightSavingsTime( daylightSaving_ ); |
---|
| 78 | t.SetTimeZone( timezoneOffset_ ); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | void visual_skySilverLining::setTime( int hour_, int minute_, int second_ ) |
---|
| 82 | { |
---|
| 83 | // Check if atmosphere is initialized. |
---|
| 84 | if (!isInitialized()) |
---|
| 85 | return; |
---|
| 86 | |
---|
| 87 | SilverLining::LocalTime t = atmosphere->GetConditions()->GetTime(); |
---|
| 88 | t.SetHour( hour_ ); |
---|
| 89 | t.SetMinutes( minute_ ); |
---|
| 90 | t.SetSeconds( second_ ); |
---|
| 91 | atmosphere->GetConditions()->SetTime( t ); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | void visual_skySilverLining::setDate( int year_, int month_, int day_ ) |
---|
| 95 | { |
---|
| 96 | // Check if atmosphere is initialized. |
---|
| 97 | if (!isInitialized()) |
---|
| 98 | return; |
---|
| 99 | |
---|
| 100 | SilverLining::LocalTime t = atmosphere->GetConditions()->GetTime(); |
---|
| 101 | t.SetYear( year_ ); |
---|
| 102 | t.SetMonth( month_ ); |
---|
| 103 | t.SetDay( day_ ); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | void visual_skySilverLining::setDateByEpoch( int secondsSince1970_ ) |
---|
| 107 | { |
---|
| 108 | // Check if atmosphere is initialized. |
---|
| 109 | if (!isInitialized()) |
---|
| 110 | return; |
---|
| 111 | |
---|
| 112 | SilverLining::LocalTime t = atmosphere->GetConditions()->GetTime(); |
---|
| 113 | t.SetFromEpochSeconds( secondsSince1970_ ); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | void visual_skySilverLining::setLocation(double lat_, double lon_, double alt_) |
---|
| 117 | { |
---|
| 118 | // Check if atmosphere is initialized. |
---|
| 119 | if (!isInitialized()) |
---|
| 120 | return; |
---|
| 121 | |
---|
| 122 | lat = lat_; |
---|
| 123 | lon = lon_; |
---|
| 124 | height = alt_; |
---|
| 125 | |
---|
| 126 | SilverLining::Location loc = atmosphere->GetConditions()->GetLocation(); |
---|
| 127 | loc.SetAltitude(alt_); |
---|
| 128 | loc.SetLatitude(lat_); |
---|
| 129 | loc.SetLongitude(lon_); |
---|
| 130 | atmosphere->GetConditions()->SetLocation( loc ); |
---|
| 131 | |
---|
| 132 | updateUpVector(); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | bool visual_skySilverLining::isInitialized() |
---|
| 137 | { |
---|
| 138 | // Check if atmosphere is initialized. If not: make a deep lookup. If initialized, perform. Otherwise return |
---|
| 139 | if (!atmosphereInitialized) |
---|
| 140 | { |
---|
| 141 | skySilverLining_atmosphereReference *ar = dynamic_cast<skySilverLining_atmosphereReference *>(viewer->getCamera()->getUserData()); |
---|
| 142 | if (ar != NULL ) |
---|
| 143 | { |
---|
| 144 | if (ar->atmosphereInitialized) |
---|
| 145 | atmosphereInitialized = true; |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | return(atmosphereInitialized); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | void visual_skySilverLining::init(osg::Group *distortedRoot, osg::CoordinateSystemNode *sceneGraphRoot) |
---|
| 152 | { |
---|
| 153 | sceneRoot = sceneGraphRoot; |
---|
| 154 | |
---|
| 155 | // Use projection matrix callback oder fixed Cullsettings? |
---|
| 156 | bool useProjMatrixCallback = true; |
---|
| 157 | |
---|
| 158 | // add Sky to SceneGraphRoot |
---|
| 159 | sceneGraphRoot->addChild( this ); |
---|
| 160 | |
---|
| 161 | // Deactivate culling for the sky node (required by the silverlining sky framework) |
---|
| 162 | this->setCullingActive(false); |
---|
| 163 | |
---|
| 164 | // Instantiate an Atmosphere and associate it with this camera. If you have multiple cameras |
---|
| 165 | // in multiple contexts, be sure to instantiate seperate Atmosphere objects for each. |
---|
| 166 | // ***IMPORTANT!**** Check that the path to the resources folder for SilverLining in SkyDrawable.cpp |
---|
| 167 | // SkyDrawable::initializeSilverLining matches with where you installed SilverLining. |
---|
| 168 | atmosphere = new SilverLining::Atmosphere(SILVERLINING_LICENSEE, SILVERLINING_LICENSE); |
---|
| 169 | |
---|
| 170 | // Add the sky (calls Atmosphere::BeginFrame and handles initialization once you're in |
---|
| 171 | // the rendering thread) |
---|
[53] | 172 | skyDrawable = new skySilverLining_skyDrawable(viewer, sceneRoot); |
---|
[31] | 173 | |
---|
[70] | 174 | if(distortedRoot) // if distortion used: |
---|
| 175 | { |
---|
| 176 | int rootKids = distortedRoot->getNumChildren(); |
---|
| 177 | for (int i = 0; i < rootKids; i++) |
---|
| 178 | { |
---|
| 179 | osg::Node *n = distortedRoot->getChild(i); |
---|
| 180 | osg::Camera *cam = dynamic_cast<osg::Camera*>(n); |
---|
| 181 | if (cam && cam->getRenderOrder() == osg::Camera::PRE_RENDER) |
---|
| 182 | sceneCamera = cam; |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | else // if no distortion used: |
---|
| 186 | sceneCamera = viewer->getCamera(); |
---|
| 187 | |
---|
[31] | 188 | osg::Camera *mainCamera = viewer->getCamera(); |
---|
| 189 | if (!useProjMatrixCallback) |
---|
| 190 | { |
---|
| 191 | mainCamera->setClearMask(0); |
---|
| 192 | mainCamera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); |
---|
| 193 | double fovy, aspect, zNear, zFar; |
---|
| 194 | mainCamera->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar); |
---|
| 195 | mainCamera->setProjectionMatrixAsPerspective(fovy, aspect, 2, 125000); |
---|
| 196 | } |
---|
| 197 | else |
---|
| 198 | { |
---|
| 199 | cb = new skySilverLining_projectionMatrixCallback( atmosphere, viewer->getCamera(), sceneRoot); |
---|
[70] | 200 | sceneCamera->setClampProjectionMatrixCallback(cb); |
---|
[31] | 201 | cb->setSkyDrawable(skyDrawable); |
---|
| 202 | } |
---|
| 203 | |
---|
[70] | 204 | // append atmosphere pointer to the cameras. |
---|
| 205 | sceneCamera->setClearMask(0); |
---|
| 206 | osg::ref_ptr<skySilverLining_atmosphereReference> ar = new skySilverLining_atmosphereReference; |
---|
[31] | 207 | ar->atmosphere = atmosphere; |
---|
[70] | 208 | sceneCamera->setUserData(ar); |
---|
| 209 | mainCamera->setUserData(ar); |
---|
[31] | 210 | |
---|
| 211 | // Create and install updateCallback (for position etc.) |
---|
| 212 | updateCallback = new skyUpdateCallback( sceneGraphRoot, sceneCamera, this ); |
---|
| 213 | this->setUpdateCallback( updateCallback ); |
---|
| 214 | |
---|
| 215 | // Use a RenderBin to enforce that the sky gets drawn first, then the scene, then the clouds |
---|
| 216 | skyDrawable->getOrCreateStateSet()->setRenderBinDetails(-1, "RenderBin"); |
---|
| 217 | |
---|
| 218 | // Add the models |
---|
| 219 | sceneGraphRoot->getOrCreateStateSet()->setRenderBinDetails(1, "RenderBin"); |
---|
| 220 | |
---|
| 221 | // Add the clouds (note, you need this even if you don't want clouds - it calls |
---|
| 222 | // Atmosphere::EndFrame() ) |
---|
| 223 | cloudsDrawable = new skySilverLining_cloudsDrawable(viewer); |
---|
| 224 | cloudsDrawable->getOrCreateStateSet()->setRenderBinDetails(99, "RenderBin"); |
---|
| 225 | |
---|
| 226 | // Add drawable to this geode to get rendered |
---|
| 227 | this->addDrawable(skyDrawable); |
---|
| 228 | this->addDrawable(cloudsDrawable); |
---|
[116] | 229 | |
---|
| 230 | //SilverLining::Atmosphere::EnableHDR( true ); |
---|
[31] | 231 | } |
---|
| 232 | |
---|
| 233 | void visual_skySilverLining::postInit() |
---|
| 234 | { |
---|
| 235 | // Only allow one execution |
---|
[122] | 236 | //if(postInitialized) |
---|
| 237 | // return; |
---|
| 238 | //else postInitialized = true; |
---|
[31] | 239 | |
---|
| 240 | // Execute Updatecallback once before adding Clouds. |
---|
[122] | 241 | //updateCallback->operator ()(this, NULL); |
---|
[31] | 242 | |
---|
[54] | 243 | //atmosphere->GetConditions()->SetFog( 0.8, 1, 1, 1); // use this for simulation real fog. |
---|
[31] | 244 | |
---|
| 245 | //Todo: secure memory-manager of timer*. oder remove paragraph |
---|
| 246 | //MyMillisecondTimer *timer = new MyMillisecondTimer(); |
---|
| 247 | // atmosphere->GetConditions()->SetMillisecondTimer(timer); |
---|
| 248 | //atmosphere->GetConditions()->EnableTimePassage(true, -1); |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | void visual_skySilverLining::updateUpVector() |
---|
| 252 | { |
---|
[136] | 253 | double x,y,z; |
---|
| 254 | util::getXYZofCamera(sceneCamera, x, y, z); |
---|
| 255 | |
---|
| 256 | osg::Vec3d up(x, y, z); |
---|
| 257 | |
---|
| 258 | up.normalize(); |
---|
| 259 | osg::Vec3d north(0, 0, 1); // Z is north |
---|
| 260 | osg::Vec3d east = north ^ up; // Cross product |
---|
| 261 | east.normalize(); |
---|
| 262 | |
---|
| 263 | atmosphere->SetUpVector(up.x(), up.y(), up.z()); |
---|
| 264 | atmosphere->SetRightVector(east.x(), east.y(), east.z()); |
---|
| 265 | |
---|
| 266 | osg::Matrixd proj = sceneCamera->getProjectionMatrix(); |
---|
[138] | 267 | double dProj[16]; |
---|
[136] | 268 | |
---|
| 269 | int i = 0; |
---|
| 270 | for (int row = 0; row < 4; row++) |
---|
| 271 | { |
---|
| 272 | for (int col = 0; col < 4; col++) |
---|
| 273 | { |
---|
| 274 | dProj[i] = proj(row, col); |
---|
| 275 | i++; |
---|
| 276 | } |
---|
| 277 | } |
---|
[138] | 278 | atmosphere->SetProjectionMatrix(dProj); |
---|
[31] | 279 | } |
---|
| 280 | |
---|
| 281 | void visual_skySilverLining::shutdown() |
---|
| 282 | { |
---|
| 283 | if (isInitialized()) |
---|
| 284 | { |
---|
| 285 | // Remove this Node from scenegraph |
---|
| 286 | sceneRoot->removeChild( this ); |
---|
| 287 | |
---|
| 288 | // Remove updatecallback |
---|
| 289 | this->removeUpdateCallback( updateCallback ); |
---|
| 290 | updateCallback = NULL; |
---|
| 291 | |
---|
| 292 | // delete drawables |
---|
[53] | 293 | skyDrawable->shutdown(); |
---|
[31] | 294 | this->removeDrawable(skyDrawable); |
---|
| 295 | this->removeDrawable(cloudsDrawable); |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | void visual_skySilverLining::setVisibility(double visibility_) |
---|
| 300 | { |
---|
| 301 | if (isInitialized()) |
---|
| 302 | { |
---|
| 303 | atmosphere->GetConditions()->SetVisibility( visibility_ ); |
---|
| 304 | } |
---|
[53] | 305 | |
---|
[31] | 306 | } |
---|
| 307 | |
---|
| 308 | double visual_skySilverLining::getVisibility() |
---|
| 309 | { |
---|
| 310 | if (isInitialized()) |
---|
| 311 | { |
---|
| 312 | return atmosphere->GetConditions()->GetVisibility(); |
---|
| 313 | } |
---|
| 314 | else |
---|
| 315 | return -1; |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | void visual_skySilverLining::setTurbidity(double turbidity_) |
---|
| 319 | { |
---|
| 320 | if (isInitialized()) |
---|
| 321 | { |
---|
| 322 | atmosphere->GetConditions()->SetTurbidity( turbidity_ ); |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | double visual_skySilverLining::getTurbidity() |
---|
| 327 | { |
---|
| 328 | if (isInitialized()) |
---|
| 329 | { |
---|
| 330 | return atmosphere->GetConditions()->GetTurbidity(); |
---|
| 331 | } |
---|
| 332 | else |
---|
| 333 | return -1; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | void visual_skySilverLining::clearAllWindVolumes() |
---|
| 337 | { |
---|
| 338 | if (isInitialized()) |
---|
| 339 | { |
---|
| 340 | atmosphere->GetConditions()->ClearWindVolumes(); |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | bool visual_skySilverLining::insideWind(double height_, double& bottom_, double& top_, double& speed_, double& direction_) |
---|
| 345 | { |
---|
| 346 | if (isInitialized()) |
---|
| 347 | { |
---|
| 348 | // Calculation earth radius on the wind positionl approximated through the now used position. |
---|
| 349 | double radius; |
---|
| 350 | if ( util::calculateEarthRadiusAtWGS84Coordinate(lat, lon, sceneRoot, radius) ) |
---|
| 351 | { |
---|
| 352 | // go through all wind volumes an check them for inside() |
---|
[130] | 353 | //std::map<int, SilverLining::WindVolume> windvolumes = atmosphere->GetConditions()->GetWindVolumes(); |
---|
| 354 | SL_MAP(int, SilverLining::WindVolume) windvolumes = atmosphere->GetConditions()->GetWindVolumes(); |
---|
[31] | 355 | for(unsigned int i=0; i<windvolumes.size(); i++) |
---|
| 356 | { |
---|
| 357 | if( windvolumes[i].Inside(radius + height_) ) |
---|
| 358 | { |
---|
| 359 | // save wind data |
---|
| 360 | bottom_ = windvolumes[i].GetMinAltitude(); |
---|
| 361 | top_ = windvolumes[i].GetMaxAltitude() - radius; |
---|
| 362 | speed_ = windvolumes[i].GetWindSpeed() - radius; |
---|
| 363 | direction_ = windvolumes[i].GetDirection(); |
---|
| 364 | // return that wind was found |
---|
| 365 | return true; |
---|
| 366 | } |
---|
| 367 | } // For END |
---|
| 368 | } // If valid radius END |
---|
| 369 | } // If initialized() END |
---|
| 370 | bottom_ = -1; |
---|
| 371 | top_ = -1; |
---|
| 372 | speed_ = -1; |
---|
| 373 | direction_ = -1; |
---|
| 374 | return false; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | void visual_skySilverLining::addWindVolume(double bottom_, double top_, double speed_, int direction_) |
---|
| 378 | { |
---|
| 379 | if (isInitialized()) |
---|
| 380 | { |
---|
| 381 | // Calculation earth radius on current lat lon position |
---|
| 382 | double radius; |
---|
| 383 | if ( util::calculateEarthRadiusAtWGS84Coordinate(lat, lon, sceneRoot, radius) ) |
---|
| 384 | { |
---|
| 385 | // correct wind value: |
---|
| 386 | if ( direction_ < 180 ) |
---|
| 387 | direction_ += 180; |
---|
| 388 | else direction_ -= 180; |
---|
| 389 | |
---|
| 390 | // Setting up Wind |
---|
| 391 | SilverLining::WindVolume wv; |
---|
| 392 | wv.SetDirection( direction_ ); |
---|
| 393 | wv.SetMinAltitude( radius + bottom_ ); |
---|
| 394 | wv.SetMaxAltitude( radius + top_ ); |
---|
| 395 | wv.SetWindSpeed( speed_ ); |
---|
| 396 | atmosphere->GetConditions()->SetWind(wv); |
---|
| 397 | } |
---|
| 398 | } |
---|
| 399 | } |
---|
| 400 | |
---|
| 401 | void visual_skySilverLining::setLightPollution(double lightPollution_) |
---|
| 402 | { |
---|
| 403 | if (isInitialized()) |
---|
| 404 | { |
---|
| 405 | return atmosphere->GetConditions()->SetLightPollution( lightPollution_ ); |
---|
| 406 | } |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | double visual_skySilverLining::getLightPollution() |
---|
| 410 | { |
---|
| 411 | if (isInitialized()) |
---|
| 412 | { |
---|
| 413 | return atmosphere->GetConditions()->GetLightPollution(); |
---|
| 414 | } |
---|
| 415 | else |
---|
| 416 | return -1; |
---|
| 417 | |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | void visual_skySilverLining::addCloudLayer(int slot_, double baseLength_, double baseWidth_, double thickness_, double baseHeight_, double density_, CloudTypes cloudtype_ ) |
---|
| 421 | { |
---|
| 422 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 423 | { |
---|
[134] | 424 | // create cloudlayer order and pass to skyDrawable to instantiate. |
---|
| 425 | cloudlayerOrder newCL; |
---|
| 426 | newCL.slot = slot_; |
---|
| 427 | newCL.lat = lat; |
---|
| 428 | newCL.lon = lon; |
---|
| 429 | newCL.baseLength = baseLength_; |
---|
| 430 | newCL.baseWidth = baseWidth_; |
---|
| 431 | newCL.thickness = thickness_; |
---|
| 432 | newCL.baseHeight = baseHeight_; |
---|
| 433 | newCL.density = density_; |
---|
| 434 | newCL.cloudtype = cloudtype_; |
---|
| 435 | newCL.assocCloudLayerSlot = &cloudLayerSlots[slot_]; |
---|
| 436 | |
---|
| 437 | skyDrawable->addCloudLayerOrder( newCL ); |
---|
[31] | 438 | |
---|
| 439 | } // If isInitialized() END |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | void visual_skySilverLining::removeCloudLayer( int slot_ ) |
---|
| 443 | { |
---|
| 444 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 445 | { |
---|
| 446 | atmosphere->GetConditions()->RemoveCloudLayer( cloudLayerSlots[slot_].cloudLayerHandle ); |
---|
| 447 | cloudLayerSlots[slot_].used = false; |
---|
| 448 | cloudLayerSlots[slot_].cloudLayerHandle = -1; |
---|
| 449 | cloudLayerSlots[slot_].cloudLayerPointer = NULL; |
---|
| 450 | cloudLayerSlots[slot_].enabled = false; |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | void visual_skySilverLining::clearAllSlots() |
---|
| 455 | { |
---|
| 456 | if (isInitialized()) |
---|
| 457 | { |
---|
| 458 | atmosphere->GetConditions()->RemoveAllCloudLayers(); |
---|
| 459 | for( int i=0; i<MAX_CLOUDLAYER_SLOTS; i++ ) |
---|
| 460 | { |
---|
| 461 | cloudLayerSlots[i].used = false; |
---|
| 462 | cloudLayerSlots[i].cloudLayerHandle = -1; |
---|
| 463 | cloudLayerSlots[i].cloudLayerPointer = NULL; |
---|
| 464 | cloudLayerSlots[i].enabled = false; |
---|
| 465 | } |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | SilverLining::CloudLayer* visual_skySilverLining::getCloudLayer( int slot_ ) |
---|
| 470 | { |
---|
| 471 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 472 | { |
---|
| 473 | if ( cloudLayerSlots[slot_].used ) |
---|
| 474 | return cloudLayerSlots[slot_].cloudLayerPointer; |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | return NULL; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | void visual_skySilverLining::setEnabled(int slot_, bool enabled_ ) |
---|
| 481 | { |
---|
| 482 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 483 | { |
---|
| 484 | cloudLayerSlots[slot_].enabled = enabled_; |
---|
| 485 | } |
---|
| 486 | } |
---|
| 487 | |
---|
| 488 | bool visual_skySilverLining::isEnabled( int slot_ ) |
---|
| 489 | { |
---|
| 490 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 491 | { |
---|
| 492 | return cloudLayerSlots[slot_].enabled; |
---|
| 493 | } |
---|
| 494 | return false; |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | void visual_skySilverLining::fadeVisibility( int slot_, int fadetimeMS_ ) |
---|
| 498 | { |
---|
| 499 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 500 | { |
---|
| 501 | if (cloudLayerSlots[slot_].enabled) |
---|
| 502 | { |
---|
| 503 | cloudLayerSlots[slot_].enabled = false; |
---|
| 504 | cloudLayerSlots[slot_].cloudLayerPointer->SetEnabled( false, fadetimeMS_ ); |
---|
| 505 | } |
---|
| 506 | else |
---|
| 507 | { |
---|
| 508 | cloudLayerSlots[slot_].enabled = true; |
---|
| 509 | cloudLayerSlots[slot_].cloudLayerPointer->SetEnabled( true, fadetimeMS_ ); |
---|
| 510 | } |
---|
| 511 | } |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | std::string visual_skySilverLining::getCloudLayerTypeName( int slot_ ) |
---|
| 515 | { |
---|
| 516 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 517 | { |
---|
| 518 | return cloudLayerSlots[slot_].typeName; |
---|
| 519 | } |
---|
| 520 | return ""; |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | void visual_skySilverLining::clearGlobalPrecipitation() |
---|
| 524 | { |
---|
| 525 | if (isInitialized()) |
---|
| 526 | { |
---|
| 527 | atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::NONE, 0.0 ); |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | void visual_skySilverLining::setGlobalPrecipitation( double rate_mmPerHour_rain_, double rate_mmPerHour_drySnow_, double rate_mmPerHour_wetSnow_, double rate_mmPerHour_sleet_ ) |
---|
| 532 | { |
---|
| 533 | if ( isInitialized() ) |
---|
| 534 | { |
---|
| 535 | // Delete old Precipitation |
---|
| 536 | atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::NONE, 0.0 ); |
---|
| 537 | |
---|
| 538 | // Set new Precipitation |
---|
| 539 | atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::RAIN, rate_mmPerHour_rain_ ); |
---|
| 540 | atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::WET_SNOW, rate_mmPerHour_drySnow_ ); |
---|
| 541 | atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::DRY_SNOW, rate_mmPerHour_wetSnow_ ); |
---|
| 542 | atmosphere->GetConditions()->SetPrecipitation( SilverLining::CloudLayer::SLEET, rate_mmPerHour_sleet_ ); |
---|
| 543 | } |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | bool visual_skySilverLining::getOverallPrecipitationAtLocation( double& rate_mmPerHour_rain, double& rate_mmPerHour_drySnow, double& rate_mmPerHour_wetSnow, double& rate_mmPerHour_sleet, double lat_, double lon_, double height_ ) |
---|
| 547 | { |
---|
| 548 | if (isInitialized()) |
---|
| 549 | { |
---|
| 550 | // Init |
---|
| 551 | bool hasPrecipitation = false; |
---|
| 552 | double x = 0; |
---|
| 553 | double y = 0; |
---|
| 554 | double z = 0; |
---|
| 555 | //// If -1 : Use sky internal values |
---|
| 556 | if ( lat_ == -1 ) |
---|
| 557 | lat_ = lat; |
---|
| 558 | if ( lon_ == -1 ) |
---|
| 559 | lon_ = lon; |
---|
| 560 | if ( height_ == -1 ) |
---|
| 561 | height_ = height; |
---|
| 562 | |
---|
| 563 | // Set precipitation to zero; |
---|
| 564 | rate_mmPerHour_rain = 0; |
---|
| 565 | rate_mmPerHour_drySnow = 0; |
---|
| 566 | rate_mmPerHour_wetSnow = 0; |
---|
| 567 | rate_mmPerHour_sleet = 0; |
---|
| 568 | |
---|
| 569 | // Get global position |
---|
| 570 | util::calculateXYZAtWGS84Coordinate(lat_, lon_, height_, sceneRoot, x, y, z); |
---|
| 571 | |
---|
| 572 | // Look up every cloud layer for it's precipitation. |
---|
| 573 | for( int i=0; i<MAX_CLOUDLAYER_SLOTS; i++ ) |
---|
| 574 | { |
---|
| 575 | if ( cloudLayerSlots[i].used ) // IF used, Pointer should be valid |
---|
| 576 | { |
---|
| 577 | if( cloudLayerSlots[i].cloudLayerPointer->HasPrecipitationAtPosition(x, y, z) ) |
---|
| 578 | { |
---|
| 579 | hasPrecipitation = true; |
---|
[130] | 580 | SL_MAP (int, double) precipitationMap = cloudLayerSlots[i].cloudLayerPointer->GetPrecipitation(); |
---|
| 581 | for( SL_MAP (int, double)::iterator it = precipitationMap.begin(); it != precipitationMap.end(); it++ ) |
---|
[31] | 582 | { |
---|
| 583 | switch(it->first) |
---|
| 584 | { |
---|
| 585 | case SilverLining::CloudLayer::RAIN : rate_mmPerHour_rain += it->second; |
---|
| 586 | break; |
---|
| 587 | case SilverLining::CloudLayer::DRY_SNOW : rate_mmPerHour_drySnow += it->second; |
---|
| 588 | break; |
---|
| 589 | case SilverLining::CloudLayer::WET_SNOW : rate_mmPerHour_wetSnow += it->second; |
---|
| 590 | break; |
---|
| 591 | case SilverLining::CloudLayer::SLEET : rate_mmPerHour_sleet += it->second; |
---|
| 592 | break; |
---|
| 593 | default: OSG_NOTIFY( osg::FATAL ) << "ERROR: visual_skySilverLining::getOverallPrecipitationAtLocation() : Wrong precipitation type in map!" << std::endl; |
---|
| 594 | break; |
---|
| 595 | }; |
---|
| 596 | } |
---|
| 597 | } // If slot has Precipitation END |
---|
| 598 | } // If used END |
---|
| 599 | } // For all slots END |
---|
| 600 | |
---|
| 601 | OSG_NOTIFY( osg::ALWAYS ) << "Rain: " << rate_mmPerHour_rain << ", dry snow: " << rate_mmPerHour_drySnow << ", wet snow: " << rate_mmPerHour_wetSnow << ", sleet: " << rate_mmPerHour_sleet << std::endl; |
---|
| 602 | return hasPrecipitation; |
---|
| 603 | |
---|
| 604 | } // If initialized END |
---|
| 605 | return false; |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | |
---|
| 609 | bool visual_skySilverLining::getSlotPrecipitationAtLocation( int slot_, double& rate_mmPerHour_rain, double& rate_mmPerHour_drySnow, double& rate_mmPerHour_wetSnow, double& rate_mmPerHour_sleet, double lat_, double lon_, double height_ ) |
---|
| 610 | { |
---|
| 611 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 612 | { |
---|
| 613 | if( cloudLayerSlots[slot_].used ) // IF used, Pointer should be valid |
---|
| 614 | { |
---|
| 615 | double x = 0; |
---|
| 616 | double y = 0; |
---|
| 617 | double z = 0; |
---|
| 618 | rate_mmPerHour_rain = 0; |
---|
| 619 | rate_mmPerHour_drySnow = 0; |
---|
| 620 | rate_mmPerHour_wetSnow = 0; |
---|
| 621 | rate_mmPerHour_sleet = 0; |
---|
| 622 | //// If -1 : Use sky internal values |
---|
| 623 | if ( lat_ == -1 ) |
---|
| 624 | lat_ = lat; |
---|
| 625 | if ( lon_ == -1 ) |
---|
| 626 | lon_ = lon; |
---|
| 627 | if ( height_ == -1 ) |
---|
| 628 | height_ = height; |
---|
| 629 | |
---|
| 630 | // Get global position |
---|
| 631 | util::calculateXYZAtWGS84Coordinate(lat_, lon_, height_, sceneRoot, x, y, z); |
---|
| 632 | |
---|
| 633 | // Check for precipitation |
---|
| 634 | if( cloudLayerSlots[slot_].cloudLayerPointer->HasPrecipitationAtPosition(x, y, z) ) |
---|
| 635 | { |
---|
[130] | 636 | SL_MAP (int, double) precipitationMap = cloudLayerSlots[slot_].cloudLayerPointer->GetPrecipitation(); |
---|
| 637 | for( SL_MAP (int, double)::iterator it = precipitationMap.begin(); it != precipitationMap.end(); it++ ) |
---|
[31] | 638 | { |
---|
| 639 | switch(it->first) |
---|
| 640 | { |
---|
| 641 | case SilverLining::CloudLayer::RAIN : rate_mmPerHour_rain = it->second; |
---|
| 642 | break; |
---|
| 643 | case SilverLining::CloudLayer::DRY_SNOW : rate_mmPerHour_drySnow = it->second; |
---|
| 644 | break; |
---|
| 645 | case SilverLining::CloudLayer::WET_SNOW : rate_mmPerHour_wetSnow = it->second; |
---|
| 646 | break; |
---|
| 647 | case SilverLining::CloudLayer::SLEET : rate_mmPerHour_sleet = it->second; |
---|
| 648 | break; |
---|
| 649 | default: OSG_NOTIFY( osg::FATAL ) << "ERROR: visual_skySilverLining::getSlotPrecipitationAtLocation() : Wrong precipitation type in map!" << std::endl; |
---|
| 650 | break; |
---|
| 651 | }; |
---|
| 652 | } // FOR END |
---|
| 653 | OSG_NOTIFY( osg::ALWAYS ) << "Rain: " << rate_mmPerHour_rain << ", dry snow: " << rate_mmPerHour_drySnow << ", wet snow: " << rate_mmPerHour_wetSnow << ", sleet: " << rate_mmPerHour_sleet << std::endl; |
---|
| 654 | return true; |
---|
| 655 | } // If slot has Precipitation END |
---|
| 656 | else |
---|
| 657 | return false; |
---|
| 658 | } // If used END |
---|
| 659 | else |
---|
| 660 | return false; |
---|
| 661 | } // If initialized END |
---|
| 662 | return false; |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | bool visual_skySilverLining::getSlotPrecipitation( int slot_, double& rate_mmPerHour_rain, double& rate_mmPerHour_drySnow, double& rate_mmPerHour_wetSnow, double& rate_mmPerHour_sleet ) |
---|
| 666 | { |
---|
| 667 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 668 | { |
---|
| 669 | if( cloudLayerSlots[slot_].used ) // IF used, Pointer should be valid |
---|
| 670 | { |
---|
| 671 | rate_mmPerHour_rain = 0; |
---|
| 672 | rate_mmPerHour_drySnow = 0; |
---|
| 673 | rate_mmPerHour_wetSnow = 0; |
---|
| 674 | rate_mmPerHour_sleet = 0; |
---|
| 675 | |
---|
| 676 | // Check for precipitation |
---|
| 677 | |
---|
[130] | 678 | SL_MAP (int, double) precipitationMap = cloudLayerSlots[slot_].cloudLayerPointer->GetPrecipitation(); |
---|
| 679 | for( SL_MAP (int, double)::iterator it = precipitationMap.begin(); it != precipitationMap.end(); it++ ) |
---|
[31] | 680 | { |
---|
| 681 | switch(it->first) |
---|
| 682 | { |
---|
| 683 | case SilverLining::CloudLayer::RAIN : rate_mmPerHour_rain = it->second; |
---|
| 684 | break; |
---|
| 685 | case SilverLining::CloudLayer::DRY_SNOW : rate_mmPerHour_drySnow = it->second; |
---|
| 686 | break; |
---|
| 687 | case SilverLining::CloudLayer::WET_SNOW : rate_mmPerHour_wetSnow = it->second; |
---|
| 688 | break; |
---|
| 689 | case SilverLining::CloudLayer::SLEET : rate_mmPerHour_sleet = it->second; |
---|
| 690 | break; |
---|
| 691 | default: OSG_NOTIFY( osg::FATAL ) << "ERROR: visual_skySilverLining::getSlotPrecipitation() : Wrong precipitation type in map!" << std::endl; |
---|
| 692 | break; |
---|
| 693 | }; |
---|
| 694 | } // FOR END |
---|
| 695 | |
---|
| 696 | if ( rate_mmPerHour_rain>0 || rate_mmPerHour_drySnow>0 || rate_mmPerHour_wetSnow>0 || rate_mmPerHour_sleet>0) |
---|
| 697 | { |
---|
| 698 | OSG_NOTIFY( osg::ALWAYS ) << "Rain: " << rate_mmPerHour_rain << ", dry snow: " << rate_mmPerHour_drySnow << ", wet snow: " << rate_mmPerHour_wetSnow << ", sleet: " << rate_mmPerHour_sleet << std::endl; |
---|
| 699 | return true; |
---|
| 700 | } |
---|
| 701 | else |
---|
| 702 | return false; |
---|
| 703 | } // If used END |
---|
| 704 | else |
---|
| 705 | return false; |
---|
| 706 | } // If initialized END |
---|
| 707 | return false; |
---|
| 708 | } |
---|
| 709 | |
---|
| 710 | void visual_skySilverLining::clearAllPrecipitation( int slot_ ) |
---|
| 711 | { |
---|
| 712 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 713 | { |
---|
| 714 | if( cloudLayerSlots[slot_].used ) // IF used, Pointer should be valid |
---|
| 715 | { |
---|
| 716 | cloudLayerSlots[slot_].cloudLayerPointer->SetPrecipitation( SilverLining::CloudLayer::NONE, 0.0 ); |
---|
| 717 | cloudLayerSlots[slot_].cloudLayerPointer->SetPrecipitation( SilverLining::CloudLayer::NONE, 0.0 ); // Second Call to clear precipitation rate. |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | } |
---|
| 721 | |
---|
| 722 | void visual_skySilverLining::setSlotPrecipitation( int slot_, double rate_mmPerHour_rain_, double rate_mmPerHour_drySnow_, double rate_mmPerHour_wetSnow_, double rate_mmPerHour_sleet_ ) |
---|
| 723 | { |
---|
| 724 | if (isInitialized() && slot_ >= 0 && slot_ < MAX_CLOUDLAYER_SLOTS) |
---|
| 725 | { |
---|
| 726 | if( cloudLayerSlots[slot_].used ) // IF used, Pointer should be valid |
---|
| 727 | { |
---|
| 728 | cloudLayerSlots[slot_].cloudLayerPointer->SetPrecipitation( SilverLining::CloudLayer::RAIN, rate_mmPerHour_rain_ ); |
---|
| 729 | cloudLayerSlots[slot_].cloudLayerPointer->SetPrecipitation( SilverLining::CloudLayer::DRY_SNOW, rate_mmPerHour_drySnow_ ); |
---|
| 730 | cloudLayerSlots[slot_].cloudLayerPointer->SetPrecipitation( SilverLining::CloudLayer::WET_SNOW, rate_mmPerHour_wetSnow_ ); |
---|
| 731 | cloudLayerSlots[slot_].cloudLayerPointer->SetPrecipitation( SilverLining::CloudLayer::SLEET, rate_mmPerHour_sleet_ ); |
---|
| 732 | } |
---|
| 733 | } |
---|
| 734 | } |
---|