Changeset 6948 for OpenSceneGraph/trunk/examples/osgmovie/osgmovie.cpp
 Timestamp:
 06/12/07 20:56:52 (8 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/examples/osgmovie/osgmovie.cpp
r6947 r6948 309 309 } 310 310 311 osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, 312 osg::ArgumentParser& arguments) 313 { 314 double sphere_radius = 1.0; 315 if (arguments.read("radius", sphere_radius)) {} 316 317 double collar_radius = 0.45; 318 if (arguments.read("collar", collar_radius)) {} 319 320 double rotationDegrees = 180.0; 321 if (arguments.read("rotation", rotationDegrees)) {} 322 311 class DomeModel 312 { 313 public: 314 315 DomeModel(osg::ArgumentParser& arguments): 316 sphere_radius(1.0), 317 collar_radius(0.45), 318 rotationDegrees(180.0), 319 distance(0.0), 320 flip(false), 321 texcoord_flip(false) 322 { 323 if (arguments.read("radius", sphere_radius)) {} 324 if (arguments.read("collar", collar_radius)) {} 325 if (arguments.read("rotation", rotationDegrees)) {} 326 327 distance = sqrt(sphere_radius*sphere_radius  collar_radius*collar_radius); 328 if (arguments.read("distance", distance)) {} 329 330 if (arguments.read("flip")) { flip = true; } 331 } 332 333 double sphere_radius; 334 double collar_radius; 335 double rotationDegrees; 336 double distance; 337 bool flip; 338 bool texcoord_flip; 339 340 }; 341 342 343 osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, DomeModel& domeModel) 344 { 323 345 osg::Vec3d center(0.0,0.0,0.0); 324 346 osg::Vec3d eye(0.0,0.0,0.0); 325 347 326 double distance = sqrt(sphere_radius*sphere_radius  collar_radius*collar_radius);327 if (arguments.read("distance", distance)) {}328 329 348 bool centerProjection = false; 330 349 331 osg::Vec3d projector = eye  osg::Vec3d(0.0,0.0, d istance);350 osg::Vec3d projector = eye  osg::Vec3d(0.0,0.0, domeModel.distance); 332 351 333 352 334 353 osg::notify(osg::NOTICE)<<"Projector position = "<<projector<<std::endl; 335 osg::notify(osg::NOTICE)<<"distance = "<<d istance<<std::endl;354 osg::notify(osg::NOTICE)<<"distance = "<<domeModel.distance<<std::endl; 336 355 337 356 … … 364 383 float screenRadius = heightVector.length() * 0.5f; 365 384 366 double rotation = osg::DegreesToRadians( rotationDegrees);385 double rotation = osg::DegreesToRadians(domeModel.rotationDegrees); 367 386 368 387 osg::Vec3 cursor = bottom; … … 370 389 371 390 int midSteps = noSteps/2; 372 373 bool flip = false;374 if (arguments.read("flip")) { flip = true; }375 391 376 392 for(i=0;i<midSteps;++i) … … 386 402 if (phi > osg::PI_2) phi = osg::PI_2; 387 403 388 double f = d istance * sin(phi);389 double e = d istance * cos(phi) + sqrt( sphere_radius*sphere_radius  f*f);404 double f = domeModel.distance * sin(phi); 405 double e = domeModel.distance * cos(phi) + sqrt( domeModel.sphere_radius*domeModel.sphere_radius  f*f); 390 406 double l = e * cos(phi); 391 407 double h = e * sin(phi); 392 double gamma = atan2(h, ld istance);408 double gamma = atan2(h, ldomeModel.distance); 393 409 394 410 osg::Vec2 texcoord(theta/(2.0*osg::PI), 1.0gamma/osg::PI); … … 396 412 // osg::notify(osg::NOTICE)<<"cursor = "<<cursor<< " theta = "<<theta<< "phi="<<phi<<" gamma = "<<gamma<<" texcoord="<<texcoord<<std::endl; 397 413 398 if ( flip)414 if (domeModel.flip) 399 415 vertices>push_back(osg::Vec3(cursor.x(), top.y()(cursor.y()origin.y()),cursor.z())); 400 416 else … … 402 418 403 419 colors>push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 404 texcoords>push_back( texcoord);420 texcoords>push_back( domeModel.texcoord_flip ? osg::Vec2(texcoord.x(), 1.0f  texcoord.y()) : texcoord); 405 421 406 422 if (j+1<midSteps) cursor += dx; … … 414 430 if (phi > osg::PI_2) phi = osg::PI_2; 415 431 416 double f = d istance * sin(phi);417 double e = d istance * cos(phi) + sqrt( sphere_radius*sphere_radius  f*f);432 double f = domeModel.distance * sin(phi); 433 double e = domeModel.distance * cos(phi) + sqrt( domeModel.sphere_radius*domeModel.sphere_radius  f*f); 418 434 double l = e * cos(phi); 419 435 double h = e * sin(phi); 420 double gamma = atan2(h, ld istance);436 double gamma = atan2(h, ldomeModel.distance); 421 437 422 438 osg::Vec2 texcoord(theta/(2.0*osg::PI), 1.0gamma/osg::PI); … … 424 440 // osg::notify(osg::NOTICE)<<"cursor = "<<cursor<< " theta = "<<theta<< "phi="<<phi<<" gamma = "<<gamma<<" texcoord="<<texcoord<<std::endl; 425 441 426 if ( flip)442 if (domeModel.flip) 427 443 vertices>push_back(osg::Vec3(cursor.x(), top.y()(cursor.y()origin.y()),cursor.z())); 428 444 else … … 430 446 431 447 colors>push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 432 texcoords>push_back( texcoord);448 texcoords>push_back( domeModel.texcoord_flip ? osg::Vec2(texcoord.x(), 1.0f  texcoord.y()) : texcoord); 433 449 434 450 cursor += dx; … … 448 464 if (phi > osg::PI_2) phi = osg::PI_2; 449 465 450 double f = d istance * sin(phi);451 double e = d istance * cos(phi) + sqrt( sphere_radius*sphere_radius  f*f);466 double f = domeModel.distance * sin(phi); 467 double e = domeModel.distance * cos(phi) + sqrt( domeModel.sphere_radius*domeModel.sphere_radius  f*f); 452 468 double l = e * cos(phi); 453 469 double h = e * sin(phi); 454 double gamma = atan2(h, ld istance);470 double gamma = atan2(h, ldomeModel.distance); 455 471 456 472 osg::Vec2 texcoord(theta/(2.0*osg::PI), 1.0gamma/osg::PI); … … 458 474 // osg::notify(osg::NOTICE)<<"cursor = "<<cursor<< " theta = "<<theta<< "phi="<<phi<<" gamma = "<<gamma<<" texcoord="<<texcoord<<std::endl; 459 475 460 if ( flip)476 if (domeModel.flip) 461 477 vertices>push_back(osg::Vec3(cursor.x(), top.y()(cursor.y()origin.y()),cursor.z())); 462 478 else … … 464 480 465 481 colors>push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 466 texcoords>push_back( texcoord);482 texcoords>push_back( domeModel.texcoord_flip ? osg::Vec2(texcoord.x(), 1.0f  texcoord.y()) : texcoord); 467 483 468 484 cursor += dx; … … 516 532 while (arguments.read("width",width)) {} 517 533 while (arguments.read("height",height)) {} 534 535 DomeModel domeModel(arguments); 518 536 519 537 osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; … … 536 554 } 537 555 538 osg::ref_ptr<osg::Drawable> distortionCorrectionMash = createDomeDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), arguments);539 540 556 osg::Texture* texture = 0; 541 557 for(int i=1;i<arguments.argc() && !texture;++i) … … 549 565 if (image) 550 566 { 567 domeModel.texcoord_flip = image>getOrigin()==osg::Image::TOP_LEFT; 568 551 569 #if 1 552 570 texture = new osg::TextureRectangle(image); … … 566 584 { 567 585 osg::Geode* geode = new osg::Geode(); 568 geode>addDrawable( distortionCorrectionMash.get());586 geode>addDrawable( createDomeDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), domeModel) ); 569 587 570 588 // new we need to add the texture to the mesh, we do so by creating a