| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgProducer/Viewer> |
|---|
| 15 | #include <osgDB/ReadFile> |
|---|
| 16 | #include <osgDB/WriteFile> |
|---|
| 17 | #include <osgUtil/Optimizer> |
|---|
| 18 | |
|---|
| 19 | #include <osg/Geode> |
|---|
| 20 | #include <osg/Notify> |
|---|
| 21 | #include <osg/MatrixTransform> |
|---|
| 22 | #include <osg/Switch> |
|---|
| 23 | #include <osg/TexMat> |
|---|
| 24 | #include <osg/Texture2D> |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | typedef std::vector<std::string> FileList; |
|---|
| 29 | |
|---|
| 30 | class SlideEventHandler : public osgGA::GUIEventHandler, public osg::NodeCallback |
|---|
| 31 | { |
|---|
| 32 | public: |
|---|
| 33 | |
|---|
| 34 | SlideEventHandler(); |
|---|
| 35 | |
|---|
| 36 | META_Object(osgStereImageApp,SlideEventHandler); |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | void set(osg::Switch* sw, float offsetX, float offsetY, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float timePerSlide, bool autoSteppingActive); |
|---|
| 40 | |
|---|
| 41 | virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); } |
|---|
| 42 | |
|---|
| 43 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); |
|---|
| 44 | |
|---|
| 45 | virtual void getUsage(osg::ApplicationUsage& usage) const; |
|---|
| 46 | |
|---|
| 47 | virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); |
|---|
| 48 | |
|---|
| 49 | void nextSlide(); |
|---|
| 50 | |
|---|
| 51 | void previousSlide(); |
|---|
| 52 | |
|---|
| 53 | void scaleImage(float s); |
|---|
| 54 | |
|---|
| 55 | void offsetImage(float ds,float dt); |
|---|
| 56 | |
|---|
| 57 | void rotateImage(float rx,float ry); |
|---|
| 58 | |
|---|
| 59 | void initTexMatrices(); |
|---|
| 60 | |
|---|
| 61 | protected: |
|---|
| 62 | |
|---|
| 63 | ~SlideEventHandler() {} |
|---|
| 64 | SlideEventHandler(const SlideEventHandler&,const osg::CopyOp&) {} |
|---|
| 65 | |
|---|
| 66 | osg::ref_ptr<osg::Switch> _switch; |
|---|
| 67 | osg::ref_ptr<osg::TexMat> _texmatLeft; |
|---|
| 68 | osg::ref_ptr<osg::TexMat> _texmatRight; |
|---|
| 69 | bool _firstTraversal; |
|---|
| 70 | unsigned int _activeSlide; |
|---|
| 71 | double _previousTime; |
|---|
| 72 | double _timePerSlide; |
|---|
| 73 | bool _autoSteppingActive; |
|---|
| 74 | float _initSeperationX; |
|---|
| 75 | float _currentSeperationX; |
|---|
| 76 | float _initSeperationY; |
|---|
| 77 | float _currentSeperationY; |
|---|
| 78 | |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | SlideEventHandler::SlideEventHandler(): |
|---|
| 82 | _switch(0), |
|---|
| 83 | _texmatLeft(0), |
|---|
| 84 | _texmatRight(0), |
|---|
| 85 | _firstTraversal(true), |
|---|
| 86 | _activeSlide(0), |
|---|
| 87 | _previousTime(-1.0f), |
|---|
| 88 | _timePerSlide(5.0), |
|---|
| 89 | _autoSteppingActive(false) |
|---|
| 90 | { |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | void SlideEventHandler::set(osg::Switch* sw, float offsetX, float offsetY, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float timePerSlide, bool autoSteppingActive) |
|---|
| 94 | { |
|---|
| 95 | _switch = sw; |
|---|
| 96 | _switch->setUpdateCallback(this); |
|---|
| 97 | |
|---|
| 98 | _texmatLeft = texmatLeft; |
|---|
| 99 | _texmatRight = texmatRight; |
|---|
| 100 | |
|---|
| 101 | _timePerSlide = timePerSlide; |
|---|
| 102 | _autoSteppingActive = autoSteppingActive; |
|---|
| 103 | |
|---|
| 104 | _initSeperationX = offsetX; |
|---|
| 105 | _currentSeperationX = _initSeperationX; |
|---|
| 106 | |
|---|
| 107 | _initSeperationY = offsetY; |
|---|
| 108 | _currentSeperationY = _initSeperationY; |
|---|
| 109 | |
|---|
| 110 | initTexMatrices(); |
|---|
| 111 | |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) |
|---|
| 115 | { |
|---|
| 116 | switch(ea.getEventType()) |
|---|
| 117 | { |
|---|
| 118 | case(osgGA::GUIEventAdapter::KEYDOWN): |
|---|
| 119 | { |
|---|
| 120 | if (ea.getKey()=='a') |
|---|
| 121 | { |
|---|
| 122 | _autoSteppingActive = !_autoSteppingActive; |
|---|
| 123 | _previousTime = ea.time(); |
|---|
| 124 | return true; |
|---|
| 125 | } |
|---|
| 126 | else if (ea.getKey()=='n') |
|---|
| 127 | { |
|---|
| 128 | nextSlide(); |
|---|
| 129 | return true; |
|---|
| 130 | } |
|---|
| 131 | else if (ea.getKey()=='p') |
|---|
| 132 | { |
|---|
| 133 | previousSlide(); |
|---|
| 134 | return true; |
|---|
| 135 | } |
|---|
| 136 | else if (ea.getKey()=='w') |
|---|
| 137 | { |
|---|
| 138 | scaleImage(0.99f); |
|---|
| 139 | return true; |
|---|
| 140 | } |
|---|
| 141 | else if (ea.getKey()=='s') |
|---|
| 142 | { |
|---|
| 143 | scaleImage(1.01f); |
|---|
| 144 | return true; |
|---|
| 145 | } |
|---|
| 146 | else if (ea.getKey()=='j') |
|---|
| 147 | { |
|---|
| 148 | offsetImage(-0.001f,0.0f); |
|---|
| 149 | return true; |
|---|
| 150 | } |
|---|
| 151 | else if (ea.getKey()=='k') |
|---|
| 152 | { |
|---|
| 153 | offsetImage(0.001f,0.0f); |
|---|
| 154 | return true; |
|---|
| 155 | } |
|---|
| 156 | else if (ea.getKey()=='i') |
|---|
| 157 | { |
|---|
| 158 | offsetImage(0.0f,-0.001f); |
|---|
| 159 | return true; |
|---|
| 160 | } |
|---|
| 161 | else if (ea.getKey()=='m') |
|---|
| 162 | { |
|---|
| 163 | offsetImage(0.0f,0.001f); |
|---|
| 164 | return true; |
|---|
| 165 | } |
|---|
| 166 | else if (ea.getKey()==' ') |
|---|
| 167 | { |
|---|
| 168 | initTexMatrices(); |
|---|
| 169 | return true; |
|---|
| 170 | } |
|---|
| 171 | return false; |
|---|
| 172 | } |
|---|
| 173 | case(osgGA::GUIEventAdapter::DRAG): |
|---|
| 174 | case(osgGA::GUIEventAdapter::MOVE): |
|---|
| 175 | { |
|---|
| 176 | static float px = ea.getX(); |
|---|
| 177 | static float py = ea.getY(); |
|---|
| 178 | |
|---|
| 179 | float dx = ea.getX()-px; |
|---|
| 180 | float dy = ea.getY()-py; |
|---|
| 181 | |
|---|
| 182 | px = ea.getX(); |
|---|
| 183 | py = ea.getY(); |
|---|
| 184 | |
|---|
| 185 | rotateImage((float)dx/(float)(ea.getXmax()-ea.getXmin()),(float)dy/(float)(ea.getYmax()-ea.getYmin())); |
|---|
| 186 | |
|---|
| 187 | return true; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | default: |
|---|
| 191 | return false; |
|---|
| 192 | } |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | void SlideEventHandler::getUsage(osg::ApplicationUsage& usage) const |
|---|
| 196 | { |
|---|
| 197 | usage.addKeyboardMouseBinding("Space","Reset the image position to center"); |
|---|
| 198 | usage.addKeyboardMouseBinding("a","Toggle on/off the automatic advancement for image to image"); |
|---|
| 199 | usage.addKeyboardMouseBinding("n","Advance to next image"); |
|---|
| 200 | usage.addKeyboardMouseBinding("p","Move to previous image"); |
|---|
| 201 | usage.addKeyboardMouseBinding("q","Zoom into the image"); |
|---|
| 202 | usage.addKeyboardMouseBinding("a","Zoom out of the image"); |
|---|
| 203 | usage.addKeyboardMouseBinding("j","Reduce horizontal offset"); |
|---|
| 204 | usage.addKeyboardMouseBinding("k","Increase horizontal offset"); |
|---|
| 205 | usage.addKeyboardMouseBinding("m","Reduce vertical offset"); |
|---|
| 206 | usage.addKeyboardMouseBinding("i","Increase vertical offset"); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | void SlideEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) |
|---|
| 210 | { |
|---|
| 211 | if (_autoSteppingActive && nv->getFrameStamp()) |
|---|
| 212 | { |
|---|
| 213 | double time = nv->getFrameStamp()->getReferenceTime(); |
|---|
| 214 | |
|---|
| 215 | if (_firstTraversal) |
|---|
| 216 | { |
|---|
| 217 | _firstTraversal = false; |
|---|
| 218 | _previousTime = time; |
|---|
| 219 | } |
|---|
| 220 | else if (time-_previousTime>_timePerSlide) |
|---|
| 221 | { |
|---|
| 222 | _previousTime = time; |
|---|
| 223 | |
|---|
| 224 | nextSlide(); |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | traverse(node,nv); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | void SlideEventHandler::nextSlide() |
|---|
| 233 | { |
|---|
| 234 | if (_switch->getNumChildren()==0) return; |
|---|
| 235 | |
|---|
| 236 | ++_activeSlide; |
|---|
| 237 | if (_activeSlide>=_switch->getNumChildren()) _activeSlide = 0; |
|---|
| 238 | |
|---|
| 239 | _switch->setSingleChildOn(_activeSlide); |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | void SlideEventHandler::previousSlide() |
|---|
| 243 | { |
|---|
| 244 | if (_switch->getNumChildren()==0) return; |
|---|
| 245 | |
|---|
| 246 | if (_activeSlide==0) _activeSlide = _switch->getNumChildren()-1; |
|---|
| 247 | else --_activeSlide; |
|---|
| 248 | |
|---|
| 249 | _switch->setSingleChildOn(_activeSlide); |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | void SlideEventHandler::scaleImage(float s) |
|---|
| 253 | { |
|---|
| 254 | _texmatLeft->setMatrix(_texmatLeft->getMatrix()*osg::Matrix::translate(-0.5f,-0.5f,0.0f)*osg::Matrix::scale(s,s,1.0f)*osg::Matrix::translate(0.5f,0.5f,0.0f)); |
|---|
| 255 | _texmatRight->setMatrix(_texmatRight->getMatrix()*osg::Matrix::translate(-0.5f,-0.5f,0.0f)*osg::Matrix::scale(s,s,1.0f)*osg::Matrix::translate(0.5f,0.5f,0.0f)); |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | void SlideEventHandler::offsetImage(float ds,float dt) |
|---|
| 259 | { |
|---|
| 260 | _currentSeperationX+=ds; |
|---|
| 261 | _currentSeperationY+=dt; |
|---|
| 262 | osg::notify(osg::NOTICE)<<"image offset x = "<<_currentSeperationX<<" y ="<<_currentSeperationY<<std::endl; |
|---|
| 263 | _texmatLeft->setMatrix(_texmatLeft->getMatrix()*osg::Matrix::translate(ds,dt,0.0f)); |
|---|
| 264 | _texmatRight->setMatrix(_texmatRight->getMatrix()*osg::Matrix::translate(-ds,-dt,0.0f)); |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | void SlideEventHandler::rotateImage(float rx,float ry) |
|---|
| 268 | { |
|---|
| 269 | const float scale = 0.5f; |
|---|
| 270 | _texmatLeft->setMatrix(_texmatLeft->getMatrix()*osg::Matrix::translate(-rx*scale,ry*scale,0.0f)); |
|---|
| 271 | _texmatRight->setMatrix(_texmatRight->getMatrix()*osg::Matrix::translate(-rx*scale,ry*scale,0.0f)); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | void SlideEventHandler::initTexMatrices() |
|---|
| 275 | { |
|---|
| 276 | _texmatLeft->setMatrix(osg::Matrix::translate(_initSeperationX,_initSeperationY,0.0f)); |
|---|
| 277 | _texmatRight->setMatrix(osg::Matrix::translate(-_initSeperationX,-_initSeperationY,0.0f)); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | osg::Geode* createSectorForImage(osg::Image* image, osg::TexMat* texmat, float s,float t, float radius, float height, float length) |
|---|
| 282 | { |
|---|
| 283 | |
|---|
| 284 | int numSegments = 20; |
|---|
| 285 | float Theta = length/radius; |
|---|
| 286 | float dTheta = Theta/(float)(numSegments-1); |
|---|
| 287 | |
|---|
| 288 | float ThetaZero = height*s/(t*radius); |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | osg::Texture2D* texture = new osg::Texture2D; |
|---|
| 292 | texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); |
|---|
| 293 | texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); |
|---|
| 294 | texture->setImage(image); |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | osg::StateSet* dstate = new osg::StateSet; |
|---|
| 298 | dstate->setMode(GL_CULL_FACE,osg::StateAttribute::OFF); |
|---|
| 299 | dstate->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
|---|
| 300 | dstate->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); |
|---|
| 301 | dstate->setTextureAttribute(0, texmat); |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | osg::Geometry* geom = new osg::Geometry; |
|---|
| 305 | geom->setStateSet(dstate); |
|---|
| 306 | |
|---|
| 307 | osg::Vec3Array* coords = new osg::Vec3Array(); |
|---|
| 308 | osg::Vec2Array* tcoords = new osg::Vec2Array(); |
|---|
| 309 | |
|---|
| 310 | int i; |
|---|
| 311 | float angle = -Theta/2.0f; |
|---|
| 312 | for(i=0; |
|---|
| 313 | i<numSegments; |
|---|
| 314 | ++i, angle+=dTheta) |
|---|
| 315 | { |
|---|
| 316 | coords->push_back(osg::Vec3(sinf(angle)*radius,cosf(angle)*radius,height*0.5f)); |
|---|
| 317 | coords->push_back(osg::Vec3(sinf(angle)*radius,cosf(angle)*radius,-height*0.5f)); |
|---|
| 318 | |
|---|
| 319 | tcoords->push_back(osg::Vec2(angle/ThetaZero+0.5f,1.0f)); |
|---|
| 320 | tcoords->push_back(osg::Vec2(angle/ThetaZero+0.5f,0.0f)); |
|---|
| 321 | |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | osg::Vec4Array* colors = new osg::Vec4Array(); |
|---|
| 325 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
|---|
| 326 | |
|---|
| 327 | osg::DrawArrays* elements = new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,coords->size()); |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | geom->setVertexArray(coords); |
|---|
| 332 | geom->setTexCoordArray(0,tcoords); |
|---|
| 333 | geom->setColorArray(colors); |
|---|
| 334 | geom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 335 | |
|---|
| 336 | geom->addPrimitiveSet(elements); |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | osg::Geode* geode = new osg::Geode; |
|---|
| 340 | geode->addDrawable(geom); |
|---|
| 341 | |
|---|
| 342 | return geode; |
|---|
| 343 | |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | osg::Switch* createScene(const FileList& fileList, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float radius, float height, float length) |
|---|
| 349 | { |
|---|
| 350 | osg::Switch* sw = new osg::Switch; |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | for(unsigned int i=0;i+1<fileList.size();i+=2) |
|---|
| 354 | { |
|---|
| 355 | osg::ref_ptr<osg::Image> imageLeft = osgDB::readImageFile(fileList[i]); |
|---|
| 356 | osg::ref_ptr<osg::Image> imageRight = osgDB::readImageFile(fileList[i+1]); |
|---|
| 357 | if (imageLeft.valid() && imageRight.valid()) |
|---|
| 358 | { |
|---|
| 359 | float average_s = (imageLeft->s()+imageRight->s())*0.5f; |
|---|
| 360 | float average_t = (imageLeft->t()+imageRight->t())*0.5f; |
|---|
| 361 | |
|---|
| 362 | osg::Geode* geodeLeft = createSectorForImage(imageLeft.get(),texmatLeft,average_s,average_t, radius, height, length); |
|---|
| 363 | geodeLeft->setNodeMask(0x01); |
|---|
| 364 | |
|---|
| 365 | osg::Geode* geodeRight = createSectorForImage(imageRight.get(),texmatRight,average_s,average_t, radius, height, length); |
|---|
| 366 | geodeRight->setNodeMask(0x02); |
|---|
| 367 | |
|---|
| 368 | osg::ref_ptr<osg::Group> imageGroup = new osg::Group; |
|---|
| 369 | |
|---|
| 370 | imageGroup->addChild(geodeLeft); |
|---|
| 371 | imageGroup->addChild(geodeRight); |
|---|
| 372 | |
|---|
| 373 | sw->addChild(imageGroup.get()); |
|---|
| 374 | } |
|---|
| 375 | else |
|---|
| 376 | { |
|---|
| 377 | std::cout << "Warning: Unable to load both image files, '"<<fileList[i]<<"' & '"<<fileList[i+1]<<"', required for stereo imaging."<<std::endl; |
|---|
| 378 | } |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | if (sw->getNumChildren()>0) |
|---|
| 383 | { |
|---|
| 384 | |
|---|
| 385 | sw->setSingleChildOn(0); |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | return sw; |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | int main( int argc, char **argv ) |
|---|
| 392 | { |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye"); |
|---|
| 399 | arguments.getApplicationUsage()->addCommandLineOption("-d <float>","Time delay in sceonds between the display of successive image pairs when in auto advance mode."); |
|---|
| 400 | arguments.getApplicationUsage()->addCommandLineOption("-a","Enter auto advance of image pairs on start up."); |
|---|
| 401 | arguments.getApplicationUsage()->addCommandLineOption("-x <float>","Horizontal offset of left and right images."); |
|---|
| 402 | arguments.getApplicationUsage()->addCommandLineOption("-y <float>","Vertical offset of left and right images."); |
|---|
| 403 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | osgProducer::Viewer viewer(arguments); |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | viewer.setUpViewer(osgProducer::Viewer::ESCAPE_SETS_DONE); |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | SlideEventHandler* seh = new SlideEventHandler(); |
|---|
| 414 | viewer.getEventHandlerList().push_front(seh); |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | float timeDelayBetweenSlides = 5.0f; |
|---|
| 422 | while (arguments.read("-d",timeDelayBetweenSlides)) {} |
|---|
| 423 | |
|---|
| 424 | bool autoSteppingActive = false; |
|---|
| 425 | while (arguments.read("-a")) autoSteppingActive = true; |
|---|
| 426 | |
|---|
| 427 | float offsetX=0.0f; |
|---|
| 428 | while (arguments.read("-x",offsetX)) {} |
|---|
| 429 | |
|---|
| 430 | float offsetY=0.0f; |
|---|
| 431 | while (arguments.read("-y",offsetY)) {} |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 435 | { |
|---|
| 436 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 437 | return 1; |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | if (arguments.errors()) |
|---|
| 445 | { |
|---|
| 446 | arguments.writeErrorMessages(std::cout); |
|---|
| 447 | return 1; |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | if (arguments.argc()<=1) |
|---|
| 451 | { |
|---|
| 452 | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
|---|
| 453 | return 1; |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | FileList fileList; |
|---|
| 458 | for(int pos=1;pos<arguments.argc();++pos) |
|---|
| 459 | { |
|---|
| 460 | if (arguments.isString(pos)) fileList.push_back(arguments[pos]); |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | if (fileList.size()<2) |
|---|
| 464 | { |
|---|
| 465 | return 1; |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | osg::DisplaySettings* ds = viewer.getDisplaySettings(); |
|---|
| 470 | if (!ds) ds = osg::DisplaySettings::instance(); |
|---|
| 471 | if (ds) ds->setStereo(true); |
|---|
| 472 | |
|---|
| 473 | |
|---|
| 474 | viewer.realize(Producer::CameraGroup::ThreadPerCamera); |
|---|
| 475 | |
|---|
| 476 | |
|---|
| 477 | |
|---|
| 478 | float fovy = 1.0f; |
|---|
| 479 | for( unsigned int i = 0; i < viewer.getCameraConfig()->getNumberOfCameras(); i++ ) |
|---|
| 480 | { |
|---|
| 481 | Producer::Camera* cam = viewer.getCameraConfig()->getCamera(i); |
|---|
| 482 | Producer::RenderSurface* rs = cam->getRenderSurface(); |
|---|
| 483 | rs->useCursor(false); |
|---|
| 484 | fovy = cam->getLensVerticalFov(); |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | float radius = 1.0f; |
|---|
| 488 | float height = 2*radius*tan(fovy*0.5f); |
|---|
| 489 | float length = osg::PI*radius; |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | osg::TexMat* texmatLeft = new osg::TexMat; |
|---|
| 493 | osg::TexMat* texmatRight = new osg::TexMat; |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | osg::ref_ptr<osg::Switch> rootNode = createScene(fileList,texmatLeft,texmatRight,radius,height,length); |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | viewer.setSceneData(rootNode.get()); |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | for(osgProducer::OsgCameraGroup::SceneHandlerList::iterator itr=viewer.getSceneHandlerList().begin(); |
|---|
| 507 | itr!=viewer.getSceneHandlerList().end(); |
|---|
| 508 | ++itr) |
|---|
| 509 | { |
|---|
| 510 | osgUtil::SceneView* sceneview = itr->get(); |
|---|
| 511 | sceneview->setCullMask(0xffffffff); |
|---|
| 512 | sceneview->setCullMaskLeft(0x00000001); |
|---|
| 513 | sceneview->setCullMaskRight(0x00000002); |
|---|
| 514 | sceneview->setFusionDistance(osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE,radius); |
|---|
| 515 | sceneview->setCamera(0); |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | |
|---|
| 520 | seh->set(rootNode.get(),offsetX,offsetY,texmatLeft,texmatRight,timeDelayBetweenSlides,autoSteppingActive); |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | osg::Matrix homePosition; |
|---|
| 524 | homePosition.makeLookAt(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f)); |
|---|
| 525 | |
|---|
| 526 | while( !viewer.done() ) |
|---|
| 527 | { |
|---|
| 528 | |
|---|
| 529 | viewer.sync(); |
|---|
| 530 | |
|---|
| 531 | |
|---|
| 532 | |
|---|
| 533 | viewer.update(); |
|---|
| 534 | |
|---|
| 535 | viewer.setView(homePosition); |
|---|
| 536 | |
|---|
| 537 | |
|---|
| 538 | viewer.frame(); |
|---|
| 539 | |
|---|
| 540 | } |
|---|
| 541 | |
|---|
| 542 | |
|---|
| 543 | viewer.sync(); |
|---|
| 544 | |
|---|
| 545 | return 0; |
|---|
| 546 | } |
|---|