Changeset 136 for osgVisual/src/sky_Silverlining
- Timestamp:
- Oct 18, 2010, 8:43:42 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
osgVisual/src/sky_Silverlining/visual_skySilverLining.cpp
r134 r136 251 251 void visual_skySilverLining::updateUpVector() 252 252 { 253 // Allowed deltaLat and deltaLon between Updating the upvector 254 double deltaLatToUpdate = osg::DegreesToRadians( 0.1 ); // 0.5 deg 255 double deltaLonToUpdate = osg::DegreesToRadians( 0.1 ); // 0.5 deg 256 257 if ( fabs(lat-upVectorLat) > deltaLatToUpdate || fabs(lon-upVectorLon) > deltaLonToUpdate ) 258 { 259 // Get ellipsoid model 260 osg::EllipsoidModel* ellipsoid = sceneRoot->getEllipsoidModel(); 261 if ( !ellipsoid ) 262 return; 263 264 //OSG_NOTIFY( osg::ALWAYS ) << "update Upvector.." << std::endl; 265 266 // Calculate up vector 267 double x,y,z; 268 util::getXYZofCamera(sceneCamera, x, y, z); 269 osg::Vec3d upVector = ellipsoid->computeLocalUpVector( x, y, z ); 270 upVector.normalize(); 271 272 // Calculate side vector 273 osg::Matrixd localToWorld; 274 ellipsoid->computeLocalToWorldTransformFromLatLongHeight(lat, lon, height, localToWorld); 275 276 osg::Vec3d sideVector(localToWorld(0, 0), localToWorld(0, 1), localToWorld(0, 2)); 277 sideVector.normalize(); 278 279 // Update silverlining vectors 280 //std::cout << "upVector: X: " << upVector.x() << ", Y: "<< upVector.y() << ", Z: "<< upVector.z() << std::endl; 281 //std::cout << "sideVector: X: " << sideVector.x() << ", Y: "<< sideVector.y() << ", Z: "<< sideVector.z() << std::endl; 282 atmosphere->SetUpVector( upVector.x(), upVector.y(), upVector.z() ); 283 atmosphere->SetRightVector( sideVector.x(), sideVector.y(), sideVector.z() ); 284 285 // Note new upvector lat/lon 286 upVectorLon = lon; 287 upVectorLat = lat; 288 } // If update requiered END 253 //// Allowed deltaLat and deltaLon between Updating the upvector 254 //double deltaLatToUpdate = osg::DegreesToRadians( 0.1 ); // 0.5 deg 255 //double deltaLonToUpdate = osg::DegreesToRadians( 0.1 ); // 0.5 deg 256 257 //if ( fabs(lat-upVectorLat) > deltaLatToUpdate || fabs(lon-upVectorLon) > deltaLonToUpdate ) 258 //{ 259 // // Get ellipsoid model 260 // osg::EllipsoidModel* ellipsoid = sceneRoot->getEllipsoidModel(); 261 // if ( !ellipsoid ) 262 // return; 263 264 // //OSG_NOTIFY( osg::ALWAYS ) << "update Upvector.." << std::endl; 265 266 // // Calculate up vector 267 // double x,y,z; 268 // util::getXYZofCamera(sceneCamera, x, y, z); 269 // osg::Vec3d upVector = ellipsoid->computeLocalUpVector( x, y, z ); 270 // upVector.normalize(); 271 // 272 // // Calculate side vector 273 // osg::Matrixd localToWorld; 274 // ellipsoid->computeLocalToWorldTransformFromLatLongHeight(lat, lon, height, localToWorld); 275 276 // osg::Vec3d sideVector(localToWorld(0, 0), localToWorld(0, 1), localToWorld(0, 2)); 277 // sideVector.normalize(); 278 279 // // Update silverlining vectors 280 // //std::cout << "upVector: X: " << upVector.x() << ", Y: "<< upVector.y() << ", Z: "<< upVector.z() << std::endl; 281 // //std::cout << "sideVector: X: " << sideVector.x() << ", Y: "<< sideVector.y() << ", Z: "<< sideVector.z() << std::endl; 282 // atmosphere->SetUpVector( upVector.x(), upVector.y(), upVector.z() ); 283 // atmosphere->SetRightVector( sideVector.x(), sideVector.y(), sideVector.z() ); 284 285 // // Note new upvector lat/lon 286 // upVectorLon = lon; 287 // upVectorLat = lat; 288 //} // If update requiered END 289 290 double x,y,z; 291 util::getXYZofCamera(sceneCamera, x, y, z); 292 293 osg::Vec3d up(x, y, z); 294 295 up.normalize(); 296 osg::Vec3d north(0, 0, 1); // Z is north 297 osg::Vec3d east = north ^ up; // Cross product 298 east.normalize(); 299 300 atmosphere->SetUpVector(up.x(), up.y(), up.z()); 301 atmosphere->SetRightVector(east.x(), east.y(), east.z()); 302 303 osg::Matrixd view = sceneCamera->getViewMatrix(); 304 osg::Matrixd proj = sceneCamera->getProjectionMatrix(); 305 306 double dView[16], dProj[16]; 307 308 int i = 0; 309 for (int row = 0; row < 4; row++) 310 { 311 for (int col = 0; col < 4; col++) 312 { 313 dView[i] = view(row, col); 314 dProj[i] = proj(row, col); 315 i++; 316 } 317 } 318 atmosphere->SetCameraMatrix(dView); 319 atmosphere->SetProjectionMatrix(dProj); 289 320 } 290 321
Note: See TracChangeset
for help on using the changeset viewer.