From ade144ab0a013b62956b4c47f0e9ee727a4c95cd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 12 Jun 2007 18:56:52 +0000 Subject: [PATCH] Refactored the dome correction code to support movie flipping. --- examples/osgmovie/osgmovie.cpp | 88 ++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/examples/osgmovie/osgmovie.cpp b/examples/osgmovie/osgmovie.cpp index 0b0de6c9d..9e13987f4 100644 --- a/examples/osgmovie/osgmovie.cpp +++ b/examples/osgmovie/osgmovie.cpp @@ -308,31 +308,50 @@ osg::Geometry* myCreateTexturedQuadGeometry(const osg::Vec3& pos,float width,flo } } -osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, - osg::ArgumentParser& arguments) +class DomeModel { - double sphere_radius = 1.0; - if (arguments.read("--radius", sphere_radius)) {} +public: - double collar_radius = 0.45; - if (arguments.read("--collar", collar_radius)) {} + DomeModel(osg::ArgumentParser& arguments): + sphere_radius(1.0), + collar_radius(0.45), + rotationDegrees(180.0), + distance(0.0), + flip(false), + texcoord_flip(false) + { + if (arguments.read("--radius", sphere_radius)) {} + if (arguments.read("--collar", collar_radius)) {} + if (arguments.read("--rotation", rotationDegrees)) {} - double rotationDegrees = 180.0; - if (arguments.read("--rotation", rotationDegrees)) {} + distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); + if (arguments.read("--distance", distance)) {} + if (arguments.read("--flip")) { flip = true; } + } + + double sphere_radius; + double collar_radius; + double rotationDegrees; + double distance; + bool flip; + bool texcoord_flip; + +}; + + +osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, DomeModel& domeModel) +{ osg::Vec3d center(0.0,0.0,0.0); osg::Vec3d eye(0.0,0.0,0.0); - double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); - if (arguments.read("--distance", distance)) {} - bool centerProjection = false; - osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); + osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, domeModel.distance); osg::notify(osg::NOTICE)<<"Projector position = "< osg::PI_2) phi = osg::PI_2; - double f = distance * sin(phi); - double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f); + double f = domeModel.distance * sin(phi); + double e = domeModel.distance * cos(phi) + sqrt( domeModel.sphere_radius*domeModel.sphere_radius - f*f); double l = e * cos(phi); double h = e * sin(phi); - double gamma = atan2(h, l-distance); + double gamma = atan2(h, l-domeModel.distance); osg::Vec2 texcoord(theta/(2.0*osg::PI), 1.0-gamma/osg::PI); // osg::notify(osg::NOTICE)<<"cursor = "< traits = new osg::GraphicsContext::Traits; traits->screenNum = screenNum; traits->x = 0; @@ -535,8 +553,6 @@ void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments return; } - osg::ref_ptr 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); - osg::Texture* texture = 0; for(int i=1;igetOrigin()==osg::Image::TOP_LEFT; + #if 1 texture = new osg::TextureRectangle(image); #else @@ -565,7 +583,7 @@ void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments // distortion correction set up. { osg::Geode* geode = new osg::Geode(); - geode->addDrawable(distortionCorrectionMash.get()); + 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) ); // new we need to add the texture to the mesh, we do so by creating a // StateSet to contain the Texture StateAttribute.