Show
Ignore:
Timestamp:
02/22/07 17:42:59 (8 years ago)
Author:
robert
Message:

Implement basic full dome correction with projecto pointing upwards and at center
of dome.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgdistortion/osgdistortion.cpp

    r6260 r6261  
    284284} 
    285285 
    286 osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, osg::ArgumentParser& arguments) 
     286osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, 
     287                                        osg::ArgumentParser& arguments) 
    287288{ 
     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 
    288300    // create the quad to visualize. 
    289301    osg::Geometry* geometry = new osg::Geometry(); 
     
    299311    yAxis /= height; 
    300312     
    301     int noSteps = 50; 
     313    int noSteps = 100; 
    302314 
    303315    osg::Vec3Array* vertices = new osg::Vec3Array; 
     
    308320    osg::Vec3 dx = xAxis*(width/((float)(noSteps-1))); 
    309321    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; 
    314325 
    315326    osg::Vec3 cursor = bottom; 
    316     osg::Vec3 texcoord = bottom_texcoord; 
    317327    int i,j; 
    318328    for(i=0;i<noSteps;++i) 
    319329    { 
    320330        osg::Vec3 cursor = bottom+dy*(float)i; 
    321         osg::Vec3 texcoord = bottom_texcoord+dy_texcoord*(float)i; 
    322331        for(j=0;j<noSteps;++j) 
    323332        { 
     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         
    324346            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)); 
    326347            colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 
    327  
     348            texcoords->push_back(texcoord); 
     349             
    328350            cursor += dx; 
    329             texcoord += dx_texcoord; 
    330351        } 
     352        // osg::notify(osg::NOTICE)<<std::endl; 
    331353    } 
    332354 
     
    416438 
    417439        // 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); 
    419441 
    420442        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); 
     
    437459 
    438460        // 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); 
    444462 
    445463        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0)); 
     
    462480        camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X); 
    463481 
    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)); 
    465483    } 
    466484 
     
    479497 
    480498        // 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)); 
    484502    } 
    485503 
     
    498516 
    499517        // 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)); 
    503521    } 
    504522 
     
    517535 
    518536        // 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)); 
    522540    } 
    523541     
     
    562580        viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); 
    563581    } 
     582     
     583    viewer.getCamera()->setNearFarRatio(0.0001f); 
    564584} 
    565585