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