| | 366 | if (j+1<midSteps) cursor += dx; |
| | 367 | } |
| | 368 | |
| | 369 | for(;j<noSteps;++j) |
| | 370 | { |
| | 371 | osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y()); |
| | 372 | double theta = atan2(delta.x(), -delta.y()); |
| | 373 | double phi = osg::PI_2 * delta.length() / screenRadius; |
| | 374 | if (phi > osg::PI_2) phi = osg::PI_2; |
| | 375 | |
| | 376 | double f = distance * sin(phi); |
| | 377 | double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f); |
| | 378 | double l = e * cos(phi); |
| | 379 | double h = e * sin(phi); |
| | 380 | double gamma = atan2(h, l-distance); |
| | 381 | |
| | 382 | osg::Vec2 texcoord(theta/(2.0*osg::PI), 1.0-gamma/osg::PI); |
| | 383 | |
| | 384 | // osg::notify(osg::NOTICE)<<"cursor = "<<cursor<< " theta = "<<theta<< "phi="<<phi<<" gamma = "<<gamma<<" texcoord="<<texcoord<<std::endl; |
| | 385 | |
| | 386 | vertices->push_back(cursor); |
| | 387 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| | 388 | texcoords->push_back(texcoord); |
| | 389 | |
| | 395 | for(;i<noSteps;++i) |
| | 396 | { |
| | 397 | osg::Vec3 cursor = bottom+dy*(float)i; |
| | 398 | for(j=0;j<noSteps;++j) |
| | 399 | { |
| | 400 | osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y()); |
| | 401 | double theta = atan2(delta.x(), -delta.y()); |
| | 402 | if (theta<0.0) theta += 2*osg::PI; |
| | 403 | double phi = osg::PI_2 * delta.length() / screenRadius; |
| | 404 | if (phi > osg::PI_2) phi = osg::PI_2; |
| | 405 | |
| | 406 | double f = distance * sin(phi); |
| | 407 | double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f); |
| | 408 | double l = e * cos(phi); |
| | 409 | double h = e * sin(phi); |
| | 410 | double gamma = atan2(h, l-distance); |
| | 411 | |
| | 412 | osg::Vec2 texcoord(theta/(2.0*osg::PI), 1.0-gamma/osg::PI); |
| | 413 | |
| | 414 | // osg::notify(osg::NOTICE)<<"cursor = "<<cursor<< " theta = "<<theta<< "phi="<<phi<<" gamma = "<<gamma<<" texcoord="<<texcoord<<std::endl; |
| | 415 | |
| | 416 | vertices->push_back(cursor); |
| | 417 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| | 418 | texcoords->push_back(texcoord); |
| | 419 | |
| | 420 | cursor += dx; |
| | 421 | } |
| | 422 | |
| | 423 | // osg::notify(osg::NOTICE)<<std::endl; |
| | 424 | } |
| | 425 | |
| 527 | | osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
| 528 | | osg::Vec3 pos(0.0f,0.0f,0.0f); |
| 529 | | |
| 530 | | osg::StateSet* stateset = geode->getOrCreateStateSet(); |
| 531 | | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
| 532 | | |
| 533 | | if (useShader) |
| 534 | | { |
| 535 | | //useTextureRectangle = false; |
| 536 | | |
| 537 | | static const char *shaderSourceTextureRec = { |
| 538 | | "uniform vec4 cutoff_color;\n" |
| 539 | | "uniform samplerRect movie_texture;\n" |
| 540 | | "void main(void)\n" |
| 541 | | "{\n" |
| 542 | | " vec4 texture_color = textureRect(movie_texture, gl_TexCoord[0]); \n" |
| 543 | | " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" |
| 544 | | " gl_FragColor = texture_color;\n" |
| 545 | | "}\n" |
| 546 | | }; |
| 547 | | |
| 548 | | static const char *shaderSourceTexture2D = { |
| 549 | | "uniform vec4 cutoff_color;\n" |
| 550 | | "uniform sampler2D movie_texture;\n" |
| 551 | | "void main(void)\n" |
| 552 | | "{\n" |
| 553 | | " vec4 texture_color = texture2D(movie_texture, gl_TexCoord[0]); \n" |
| 554 | | " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" |
| 555 | | " gl_FragColor = texture_color;\n" |
| 556 | | "}\n" |
| 557 | | }; |
| 558 | | |
| 559 | | osg::Program* program = new osg::Program; |
| 560 | | |
| 561 | | program->addShader(new osg::Shader(osg::Shader::FRAGMENT, |
| 562 | | useTextureRectangle ? shaderSourceTextureRec : shaderSourceTexture2D)); |
| 563 | | |
| 564 | | stateset->addUniform(new osg::Uniform("cutoff_color",osg::Vec4(0.1f,0.1f,0.1f,1.0f))); |
| 565 | | stateset->addUniform(new osg::Uniform("movie_texture",0)); |
| 566 | | |
| 567 | | stateset->setAttribute(program); |
| 568 | | |
| 569 | | } |
| | 602 | osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
| | 603 | osg::Vec3 pos(0.0f,0.0f,0.0f); |
| | 604 | |
| | 605 | osg::StateSet* stateset = geode->getOrCreateStateSet(); |
| | 606 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
| | 607 | |
| | 608 | if (useShader) |
| | 609 | { |
| | 610 | //useTextureRectangle = false; |
| | 611 | |
| | 612 | static const char *shaderSourceTextureRec = { |
| | 613 | "uniform vec4 cutoff_color;\n" |
| | 614 | "uniform samplerRect movie_texture;\n" |
| | 615 | "void main(void)\n" |
| | 616 | "{\n" |
| | 617 | " vec4 texture_color = textureRect(movie_texture, gl_TexCoord[0]); \n" |
| | 618 | " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" |
| | 619 | " gl_FragColor = texture_color;\n" |
| | 620 | "}\n" |
| | 621 | }; |
| | 622 | |
| | 623 | static const char *shaderSourceTexture2D = { |
| | 624 | "uniform vec4 cutoff_color;\n" |
| | 625 | "uniform sampler2D movie_texture;\n" |
| | 626 | "void main(void)\n" |
| | 627 | "{\n" |
| | 628 | " vec4 texture_color = texture2D(movie_texture, gl_TexCoord[0]); \n" |
| | 629 | " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" |
| | 630 | " gl_FragColor = texture_color;\n" |
| | 631 | "}\n" |
| | 632 | }; |
| | 633 | |
| | 634 | osg::Program* program = new osg::Program; |
| | 635 | |
| | 636 | program->addShader(new osg::Shader(osg::Shader::FRAGMENT, |
| | 637 | useTextureRectangle ? shaderSourceTextureRec : shaderSourceTexture2D)); |
| | 638 | |
| | 639 | stateset->addUniform(new osg::Uniform("cutoff_color",osg::Vec4(0.1f,0.1f,0.1f,1.0f))); |
| | 640 | stateset->addUniform(new osg::Uniform("movie_texture",0)); |
| | 641 | |
| | 642 | stateset->setAttribute(program); |
| | 643 | |
| | 644 | } |
| | 645 | |