| 287 | | void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& /*arguments*/) |
| | 286 | osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, osg::ArgumentParser& arguments) |
| | 287 | { |
| | 288 | // create the quad to visualize. |
| | 289 | osg::Geometry* geometry = new osg::Geometry(); |
| | 290 | |
| | 291 | geometry->setSupportsDisplayList(false); |
| | 292 | |
| | 293 | osg::Vec3 xAxis(widthVector); |
| | 294 | float width = widthVector.length(); |
| | 295 | xAxis /= width; |
| | 296 | |
| | 297 | osg::Vec3 yAxis(heightVector); |
| | 298 | float height = heightVector.length(); |
| | 299 | yAxis /= height; |
| | 300 | |
| | 301 | int noSteps = 50; |
| | 302 | |
| | 303 | osg::Vec3Array* vertices = new osg::Vec3Array; |
| | 304 | osg::Vec3Array* texcoords = new osg::Vec3Array; |
| | 305 | osg::Vec4Array* colors = new osg::Vec4Array; |
| | 306 | |
| | 307 | osg::Vec3 bottom = origin; |
| | 308 | osg::Vec3 dx = xAxis*(width/((float)(noSteps-1))); |
| | 309 | osg::Vec3 dy = yAxis*(height/((float)(noSteps-1))); |
| | 310 | |
| | 311 | osg::Vec3 bottom_texcoord(0.0f,0.0f,0.0f); |
| | 312 | osg::Vec3 dx_texcoord(1.0f/(float)(noSteps-1),0.0f,0.0f); |
| | 313 | osg::Vec3 dy_texcoord(0.0f,1.0f/(float)(noSteps-1),0.0f); |
| | 314 | |
| | 315 | osg::Vec3 cursor = bottom; |
| | 316 | osg::Vec3 texcoord = bottom_texcoord; |
| | 317 | int i,j; |
| | 318 | for(i=0;i<noSteps;++i) |
| | 319 | { |
| | 320 | osg::Vec3 cursor = bottom+dy*(float)i; |
| | 321 | osg::Vec3 texcoord = bottom_texcoord+dy_texcoord*(float)i; |
| | 322 | for(j=0;j<noSteps;++j) |
| | 323 | { |
| | 324 | vertices->push_back(cursor); |
| | 325 | texcoords->push_back(osg::Vec3((sin(texcoord.x()*osg::PI-osg::PI*0.5)+1.0f)*0.5f,(1.0-sin(texcoord.y()*osg::PI-osg::PI*0.5))*0.5f,1.0)); |
| | 326 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| | 327 | |
| | 328 | cursor += dx; |
| | 329 | texcoord += dx_texcoord; |
| | 330 | } |
| | 331 | } |
| | 332 | |
| | 333 | // pass the created vertex array to the points geometry object. |
| | 334 | geometry->setVertexArray(vertices); |
| | 335 | |
| | 336 | geometry->setColorArray(colors); |
| | 337 | geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX); |
| | 338 | |
| | 339 | geometry->setTexCoordArray(0,texcoords); |
| | 340 | |
| | 341 | for(i=0;i<noSteps-1;++i) |
| | 342 | { |
| | 343 | osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::QUAD_STRIP); |
| | 344 | for(j=0;j<noSteps;++j) |
| | 345 | { |
| | 346 | elements->push_back(j+(i+1)*noSteps); |
| | 347 | elements->push_back(j+(i)*noSteps); |
| | 348 | } |
| | 349 | geometry->addPrimitiveSet(elements); |
| | 350 | } |
| | 351 | |
| | 352 | return geometry; |
| | 353 | }; |
| | 354 | |
| | 355 | void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments) |
| 496 | | |
| 497 | | // create the quad to visualize. |
| 498 | | osg::Geometry* polyGeom = new osg::Geometry(); |
| 499 | | |
| 500 | | polyGeom->setSupportsDisplayList(false); |
| 501 | | |
| 502 | | osg::Vec3 origin(0.0f,0.0f,0.0f); |
| 503 | | osg::Vec3 xAxis(1.0f,0.0f,0.0f); |
| 504 | | osg::Vec3 yAxis(0.0f,1.0f,0.0f); |
| 505 | | osg::Vec3 zAxis(0.0f,0.0f,1.0f); |
| 506 | | float height = 1024.0f; |
| 507 | | float width = 1280.0f; |
| 508 | | int noSteps = 50; |
| 509 | | |
| 510 | | osg::Vec3Array* vertices = new osg::Vec3Array; |
| 511 | | osg::Vec3Array* texcoords = new osg::Vec3Array; |
| 512 | | osg::Vec4Array* colors = new osg::Vec4Array; |
| 513 | | |
| 514 | | osg::Vec3 bottom = origin; |
| 515 | | osg::Vec3 dx = xAxis*(width/((float)(noSteps-1))); |
| 516 | | osg::Vec3 dy = yAxis*(height/((float)(noSteps-1))); |
| 517 | | |
| 518 | | osg::Vec3 bottom_texcoord(0.0f,0.0f,0.0f); |
| 519 | | osg::Vec3 dx_texcoord(1.0f/(float)(noSteps-1),0.0f,0.0f); |
| 520 | | osg::Vec3 dy_texcoord(0.0f,1.0f/(float)(noSteps-1),0.0f); |
| 521 | | |
| 522 | | osg::Vec3 cursor = bottom; |
| 523 | | osg::Vec3 texcoord = bottom_texcoord; |
| 524 | | int i,j; |
| 525 | | for(i=0;i<noSteps;++i) |
| 526 | | { |
| 527 | | osg::Vec3 cursor = bottom+dy*(float)i; |
| 528 | | osg::Vec3 texcoord = bottom_texcoord+dy_texcoord*(float)i; |
| 529 | | for(j=0;j<noSteps;++j) |
| 530 | | { |
| 531 | | vertices->push_back(cursor); |
| 532 | | texcoords->push_back(osg::Vec3((sin(texcoord.x()*osg::PI-osg::PI*0.5)+1.0f)*0.5f,(1.0-sin(texcoord.y()*osg::PI-osg::PI*0.5))*0.5f,1.0)); |
| 533 | | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| 534 | | |
| 535 | | cursor += dx; |
| 536 | | texcoord += dx_texcoord; |
| 537 | | } |
| 538 | | } |
| 539 | | |
| 540 | | // pass the created vertex array to the points geometry object. |
| 541 | | polyGeom->setVertexArray(vertices); |
| 542 | | |
| 543 | | polyGeom->setColorArray(colors); |
| 544 | | polyGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); |
| 545 | | |
| 546 | | polyGeom->setTexCoordArray(0,texcoords); |
| 547 | | |
| 548 | | for(i=0;i<noSteps-1;++i) |
| 549 | | { |
| 550 | | osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::QUAD_STRIP); |
| 551 | | for(j=0;j<noSteps;++j) |
| 552 | | { |
| 553 | | elements->push_back(j+(i+1)*noSteps); |
| 554 | | elements->push_back(j+(i)*noSteps); |
| 555 | | } |
| 556 | | polyGeom->addPrimitiveSet(elements); |
| 557 | | } |
| 558 | | |
| 559 | | |
| 560 | | // new we need to add the texture to the Drawable, we do so by creating a |
| | 532 | osg::Geode* geode = new osg::Geode(); |
| | 533 | 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), arguments)); |
| | 534 | |
| | 535 | // new we need to add the texture to the mesh, we do so by creating a |