| 333 | | osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y()); |
| 334 | | double theta = atan2(-delta.y(), delta.x()); |
| 335 | | double phi = osg::PI_2 * delta.length() / screenRadius; |
| 336 | | if (phi > osg::PI_2) phi = osg::PI_2; |
| 337 | | |
| 338 | | phi *= 2.0; |
| 339 | | |
| 340 | | // osg::notify(osg::NOTICE)<<"theta = "<<theta<< "phi="<<phi<<std::endl; |
| 341 | | |
| 342 | | osg::Vec3 texcoord(sin(phi) * cos(theta), |
| 343 | | sin(phi) * sin(theta), |
| 344 | | cos(phi)); |
| 345 | | |
| 346 | | vertices->push_back(cursor); |
| 347 | | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| 348 | | texcoords->push_back(texcoord); |
| 349 | | |
| 350 | | cursor += dx; |
| | 344 | osg::Vec3 cursor = bottom+dy*(float)i; |
| | 345 | for(j=0;j<noSteps;++j) |
| | 346 | { |
| | 347 | osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y()); |
| | 348 | double theta = atan2(-delta.y(), delta.x()); |
| | 349 | double phi = osg::PI_2 * delta.length() / screenRadius; |
| | 350 | if (phi > osg::PI_2) phi = osg::PI_2; |
| | 351 | |
| | 352 | phi *= 2.0; |
| | 353 | |
| | 354 | // osg::notify(osg::NOTICE)<<"theta = "<<theta<< "phi="<<phi<<std::endl; |
| | 355 | |
| | 356 | osg::Vec3 texcoord(sin(phi) * cos(theta), |
| | 357 | sin(phi) * sin(theta), |
| | 358 | cos(phi)); |
| | 359 | |
| | 360 | vertices->push_back(cursor); |
| | 361 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| | 362 | texcoords->push_back(texcoord); |
| | 363 | |
| | 364 | cursor += dx; |
| | 365 | } |
| | 366 | // osg::notify(osg::NOTICE)<<std::endl; |
| 352 | | // osg::notify(osg::NOTICE)<<std::endl; |
| 353 | | } |
| 354 | | |
| | 368 | } |
| | 369 | else |
| | 370 | { |
| | 371 | for(i=0;i<noSteps;++i) |
| | 372 | { |
| | 373 | osg::Vec3 cursor = bottom+dy*(float)i; |
| | 374 | for(j=0;j<noSteps;++j) |
| | 375 | { |
| | 376 | osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y()); |
| | 377 | double theta = atan2(-delta.y(), delta.x()); |
| | 378 | double phi = osg::PI_2 * delta.length() / screenRadius; |
| | 379 | if (phi > osg::PI_2) phi = osg::PI_2; |
| | 380 | |
| | 381 | // osg::notify(osg::NOTICE)<<"theta = "<<theta<< "phi="<<phi<<std::endl; |
| | 382 | |
| | 383 | double f = distance * sin(phi); |
| | 384 | double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f); |
| | 385 | double l = e * cos(phi); |
| | 386 | double h = e * sin(phi); |
| | 387 | double z = l - distance; |
| | 388 | |
| | 389 | osg::Vec3 texcoord(h * cos(theta) / sphere_radius, |
| | 390 | h * sin(theta) / sphere_radius, |
| | 391 | z / sphere_radius); |
| | 392 | |
| | 393 | vertices->push_back(cursor); |
| | 394 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| | 395 | texcoords->push_back(texcoord); |
| | 396 | |
| | 397 | cursor += dx; |
| | 398 | } |
| | 399 | // osg::notify(osg::NOTICE)<<std::endl; |
| | 400 | } |
| | 401 | } |
| | 402 | |
| | 641 | |
| | 642 | if (arguments.read("--dome") || arguments.read("--puffer") ) |
| | 643 | { |
| | 644 | |
| | 645 | setDomeCorrection(viewer, arguments); |
| | 646 | |
| | 647 | viewer.setSceneData( osgDB::readNodeFiles(arguments) ); |
| | 648 | } |
| | 649 | else if (arguments.read("--faces")) |
| | 650 | { |
| | 651 | |
| | 652 | setDomeFaces(viewer, arguments); |
| | 653 | |
| | 654 | viewer.setSceneData( osgDB::readNodeFiles(arguments) ); |
| | 655 | } |
| | 656 | else |
| | 657 | { |
| | 658 | osg::Node* distortionNode = createDistortionSubgraph( osgDB::readNodeFiles(arguments), viewer.getCamera()->getClearColor()); |
| | 659 | } |
| | 660 | |
| | 661 | |
| 599 | | } |
| 600 | | |
| 601 | | if (arguments.read("--dome")) |
| 602 | | { |
| 603 | | |
| 604 | | setDomeCorrection(viewer, arguments); |
| 605 | | |
| 606 | | viewer.setSceneData( loadedModel ); |
| 607 | | } |
| 608 | | else if (arguments.read("--faces")) |
| 609 | | { |
| 610 | | |
| 611 | | setDomeFaces(viewer, arguments); |
| 612 | | |
| 613 | | viewer.setSceneData( loadedModel ); |
| 614 | | } |
| 615 | | else |
| 616 | | { |
| 617 | | osg::Node* distortionNode = createDistortionSubgraph(loadedModel, viewer.getCamera()->getClearColor()); |
| 618 | | |
| 619 | | // add model to the viewer. |
| 620 | | viewer.setSceneData( distortionNode ); |