- Timestamp:
- 02/22/07 17:42:59 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgdistortion/osgdistortion.cpp
r6260 r6261 284 284 } 285 285 286 osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, osg::ArgumentParser& arguments) 286 osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, 287 osg::ArgumentParser& arguments) 287 288 { 289 double sphere_radius = 1.0; 290 double collar_radius = 0.45; 291 osg::Vec3d center(0.0,0.0,0.0); 292 osg::Vec3d eye(0.0,0.0,0.0); 293 294 double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); 295 osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); 296 297 osg::notify(osg::NOTICE)<<"Projector position = "<<projector<<std::endl; 298 299 288 300 // create the quad to visualize. 289 301 osg::Geometry* geometry = new osg::Geometry(); … … 299 311 yAxis /= height; 300 312 301 int noSteps = 50;313 int noSteps = 100; 302 314 303 315 osg::Vec3Array* vertices = new osg::Vec3Array; … … 308 320 osg::Vec3 dx = xAxis*(width/((float)(noSteps-1))); 309 321 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); 322 323 osg::Vec3d screenCenter = origin + widthVector*0.5f + heightVector*0.5f; 324 float screenRadius = heightVector.length() * 0.5f; 314 325 315 326 osg::Vec3 cursor = bottom; 316 osg::Vec3 texcoord = bottom_texcoord;317 327 int i,j; 318 328 for(i=0;i<noSteps;++i) 319 329 { 320 330 osg::Vec3 cursor = bottom+dy*(float)i; 321 osg::Vec3 texcoord = bottom_texcoord+dy_texcoord*(float)i;322 331 for(j=0;j<noSteps;++j) 323 332 { 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 324 346 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 347 colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 327 348 texcoords->push_back(texcoord); 349 328 350 cursor += dx; 329 texcoord += dx_texcoord;330 351 } 352 // osg::notify(osg::NOTICE)<<std::endl; 331 353 } 332 354 … … 416 438 417 439 // attach the texture and use it as the color buffer. 418 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_ Z);440 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y); 419 441 420 442 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); … … 437 459 438 460 // attach the texture and use it as the color buffer. 439 #ifdef CUBE_MAP 440 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y); 441 #else 442 camera->attach(osg::Camera::COLOR_BUFFER, texture); 443 #endif 461 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Z); 444 462 445 463 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0)); … … 462 480 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X); 463 481 464 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0) );482 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,0.0,1.0)); 465 483 } 466 484 … … 479 497 480 498 // attach the texture and use it as the color buffer. 481 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap:: NEGATIVE_X);482 483 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0 ));499 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_X); 500 501 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0 ) * osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,0.0,1.0)); 484 502 } 485 503 … … 498 516 499 517 // attach the texture and use it as the color buffer. 500 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_ Y);501 502 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0) );518 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Z); 519 520 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(180.0f), 0.0,0.0,1.0)); 503 521 } 504 522 … … 517 535 518 536 // attach the texture and use it as the color buffer. 519 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_ Z);520 521 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees( -180.0f), 1.0,0.0,0.0));537 camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Y); 538 539 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0)); 522 540 } 523 541 … … 562 580 viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); 563 581 } 582 583 viewer.getCamera()->setNearFarRatio(0.0001f); 564 584 } 565 585
