root/OpenSceneGraph/trunk/examples/osgstereoimage/osgstereoimage.cpp @ 9967

Revision 9967, 22.2 kB (checked in by robert, 5 years ago)

Added support for image streams

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* OpenSceneGraph example, osgstereoimage.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
17*/
18
19#include <osgViewer/Viewer>
20#include <osgDB/fstream>
21#include <osgDB/ReadFile>
22#include <osgDB/WriteFile>
23#include <osgUtil/Optimizer>
24
25#include <osg/ImageStream>
26#include <osg/Geode>
27#include <osg/Notify>
28#include <osg/MatrixTransform>
29#include <osg/Switch>
30#include <osg/TexMat>
31#include <osg/Texture2D>
32
33#include <iostream>
34
35typedef std::vector<std::string> FileList;
36
37osg::Geode* createSectorForImage(osg::Image* image, osg::TexMat* texmat, float s,float t, float radius, float height, float length)
38{
39    bool flip = image->getOrigin()==osg::Image::TOP_LEFT;
40
41    int numSegments = 20;
42    float Theta = length/radius;
43    float dTheta = Theta/(float)(numSegments-1);
44   
45    float ThetaZero = height*s/(t*radius);
46   
47    // set up the texture.
48    osg::Texture2D* texture = new osg::Texture2D;
49    texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
50    texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
51    texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER);
52    texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER);
53    texture->setResizeNonPowerOfTwoHint(false);
54    texture->setImage(image);
55
56    // set up the drawstate.
57    osg::StateSet* dstate = new osg::StateSet;
58    dstate->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
59    dstate->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
60    dstate->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
61    dstate->setTextureAttribute(0, texmat);
62
63    // set up the geoset.
64    osg::Geometry* geom = new osg::Geometry;
65    geom->setStateSet(dstate);
66
67    osg::Vec3Array* coords = new osg::Vec3Array();
68    osg::Vec2Array* tcoords = new osg::Vec2Array();
69   
70    int i;
71    float angle = -Theta/2.0f;
72    for(i=0;
73        i<numSegments;
74        ++i, angle+=dTheta)
75    {
76        coords->push_back(osg::Vec3(sinf(angle)*radius,cosf(angle)*radius,height*0.5f)); // top
77        coords->push_back(osg::Vec3(sinf(angle)*radius,cosf(angle)*radius,-height*0.5f)); // bottom.
78       
79        tcoords->push_back(osg::Vec2(angle/ThetaZero+0.5f, flip ? 0.0f : 1.0f)); // top
80        tcoords->push_back(osg::Vec2(angle/ThetaZero+0.5f, flip ? 1.0f : 0.0f)); // bottom.
81
82    }
83
84    osg::Vec4Array* colors = new osg::Vec4Array();
85    colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
86
87    osg::DrawArrays* elements = new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,coords->size());
88
89   
90
91    geom->setVertexArray(coords);
92    geom->setTexCoordArray(0,tcoords);
93    geom->setColorArray(colors);
94    geom->setColorBinding(osg::Geometry::BIND_OVERALL);
95
96    geom->addPrimitiveSet(elements);
97
98    // set up the geode.
99    osg::Geode* geode = new osg::Geode;
100    geode->addDrawable(geom);
101
102    return geode;
103
104}
105
106osg::Group * loadImages(std::string image1, std::string image2, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float radius, float height, float length) {
107        osg::ref_ptr<osg::Image> imageLeft = osgDB::readImageFile(image1);
108        osg::ref_ptr<osg::Image> imageRight = osgDB::readImageFile(image2);
109        if (imageLeft.valid() && imageRight.valid())
110        {
111            osg::ImageStream* streamLeft = dynamic_cast<osg::ImageStream*>(imageLeft.get());
112            if (streamLeft) streamLeft->play();
113       
114            osg::ImageStream* streamRight = dynamic_cast<osg::ImageStream*>(imageRight.get());
115            if (streamRight) streamRight->play();
116           
117       
118            float average_s = (imageLeft->s()+imageRight->s())*0.5f;
119            float average_t = (imageLeft->t()+imageRight->t())*0.5f;
120            osg::Geode* geodeLeft = createSectorForImage(imageLeft.get(),texmatLeft,average_s,average_t, radius, height, length);
121            geodeLeft->setNodeMask(0x01);
122
123            osg::Geode* geodeRight = createSectorForImage(imageRight.get(),texmatRight,average_s,average_t, radius, height, length);
124            geodeRight->setNodeMask(0x02);
125
126            osg::Group * imageGroup = new osg::Group;
127           
128            imageGroup->addChild(geodeLeft);
129            imageGroup->addChild(geodeRight);
130            return imageGroup;
131        }
132        else
133        {
134            std::cout << "Warning: Unable to load both image files, '"<<image1<<"' & '"<<image2<<"', required for stereo imaging."<<std::endl;
135            return 0;
136        }
137}
138
139// create a switch containing a set of child each containing a
140// stereo image pair.
141osg::Switch* createScene(FileList fileList, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float radius, float height, float length)
142{
143    osg::Switch* sw = new osg::Switch;
144
145    // load the images.
146    for(unsigned int i=0;i+1<fileList.size();i+=2)
147    {
148        osg::Group * imageGroup = loadImages(fileList[i],fileList[i+1],texmatLeft,texmatRight, radius,  height, length);
149        if (imageGroup) sw->addChild(imageGroup);
150    }
151
152
153    if (sw->getNumChildren()>0)
154    {
155        // select first child.
156        sw->setSingleChildOn(0);
157    }
158
159    return sw;
160}
161
162class SlideEventHandler : public osgGA::GUIEventHandler
163{
164public:
165
166    SlideEventHandler();
167   
168    META_Object(osgStereImageApp,SlideEventHandler);
169
170
171    void set(osg::Switch* sw, float offsetX, float offsetY, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float timePerSlide, bool autoSteppingActive);
172
173    void set(FileList fileList, osg::Switch* sw, float offsetX, float offsetY, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float radius, float height, float length, float timePerSlide, bool autoSteppingActive);
174
175
176    virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
177   
178    virtual void getUsage(osg::ApplicationUsage& usage) const;
179
180    virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
181   
182    void nextSlide();
183   
184    void previousSlide();
185   
186    void scaleImage(float s);
187   
188    void offsetImage(float ds,float dt);
189
190    void rotateImage(float rx,float ry);
191
192    void initTexMatrices();
193
194protected:
195
196    ~SlideEventHandler() {}
197    SlideEventHandler(const SlideEventHandler&,const osg::CopyOp&) {}
198
199    osg::ref_ptr<osg::Switch>   _switch;
200    osg::ref_ptr<osg::TexMat>   _texmatLeft;
201    osg::ref_ptr<osg::TexMat>   _texmatRight;
202    float                        _radius;
203    float                        _height;
204    float                        _length;
205    bool                        _firstTraversal;
206    unsigned int                _activeSlide;
207    double                      _previousTime;
208    double                      _timePerSlide;
209    bool                        _autoSteppingActive;
210    float                       _initSeperationX;
211    float                       _currentSeperationX;
212    float                       _initSeperationY;
213    float                       _currentSeperationY;
214    FileList                     _fileList;
215       
216};
217
218SlideEventHandler::SlideEventHandler():
219    _switch(0),
220    _texmatLeft(0),
221    _texmatRight(0),
222    _firstTraversal(true),
223    _activeSlide(0),
224    _previousTime(-1.0f),
225    _timePerSlide(5.0),
226    _autoSteppingActive(false)
227{
228}
229
230void SlideEventHandler::set(osg::Switch* sw, float offsetX, float offsetY, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float timePerSlide, bool autoSteppingActive)
231{
232    _switch = sw;
233    _switch->setUpdateCallback(this);
234
235    _texmatLeft = texmatLeft;
236    _texmatRight = texmatRight;
237
238    _timePerSlide = timePerSlide;
239    _autoSteppingActive = autoSteppingActive;   
240   
241    _initSeperationX = offsetX;
242    _currentSeperationX = _initSeperationX;
243
244    _initSeperationY = offsetY;
245    _currentSeperationY = _initSeperationY;
246
247    initTexMatrices();
248
249}
250
251void SlideEventHandler::set(FileList fileList, osg::Switch* sw, float offsetX, float offsetY, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float radius, float height, float length, float timePerSlide, bool autoSteppingActive)
252{
253    _switch = sw;
254    _switch->setUpdateCallback(this);
255    _fileList=FileList(fileList);
256
257    osg::ref_ptr<osg::Group> imageGroup = loadImages(fileList[0],fileList[1],texmatLeft,texmatRight, radius,  height, length);
258    if (imageGroup.get())_switch->addChild(imageGroup.get());
259
260    _texmatLeft = texmatLeft;
261    _texmatRight = texmatRight;
262
263    _radius=radius;
264    _height=height;
265    _length=length;
266
267    _timePerSlide = timePerSlide;
268    _autoSteppingActive = autoSteppingActive;   
269   
270    _initSeperationX = offsetX;
271    _currentSeperationX = _initSeperationX;
272
273    _initSeperationY = offsetY;
274    _currentSeperationY = _initSeperationY;
275
276    initTexMatrices();
277}
278
279
280bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
281{
282    switch(ea.getEventType())
283    {
284        case(osgGA::GUIEventAdapter::KEYDOWN):
285        {
286            if (ea.getKey()=='a')
287            {
288                _autoSteppingActive = !_autoSteppingActive;
289                _previousTime = ea.getTime();
290                return true;
291            }
292            else if ((ea.getKey()=='n') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_Right))
293            {
294                nextSlide();
295                return true;
296            }
297            else if ((ea.getKey()=='p') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left))
298            {
299                previousSlide();
300                return true;
301            }
302            else if ((ea.getKey()=='w') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Add))
303            {
304                scaleImage(0.99f);
305                return true;
306            }
307            else if ((ea.getKey()=='s') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Subtract))
308            {
309                scaleImage(1.01f);
310                return true;
311            }
312            else if (ea.getKey()=='j')
313            {
314                offsetImage(-0.001f,0.0f);
315                return true;
316            }
317            else if (ea.getKey()=='k')
318            {
319                offsetImage(0.001f,0.0f);
320                return true;
321            }
322            else if (ea.getKey()=='i')
323            {
324                offsetImage(0.0f,-0.001f);
325                return true;
326            }
327            else if (ea.getKey()=='m')
328            {
329                offsetImage(0.0f,0.001f);
330                return true;
331            }
332            else if (ea.getKey()==' ')
333            {
334                initTexMatrices();
335                return true;
336            }
337            return false;
338        }
339        case(osgGA::GUIEventAdapter::DRAG):
340        case(osgGA::GUIEventAdapter::MOVE):
341        {
342            static float px = ea.getXnormalized();
343            static float py = ea.getYnormalized();
344           
345            float dx = ea.getXnormalized()-px;
346            float dy = ea.getYnormalized()-py;
347           
348            px = ea.getXnormalized();
349            py = ea.getYnormalized();
350           
351            rotateImage(dx,dy);
352           
353            return true;
354        }
355
356        default:
357            return false;
358    }
359}
360
361void SlideEventHandler::getUsage(osg::ApplicationUsage& usage) const
362{
363    usage.addKeyboardMouseBinding("Space","Reset the image position to center");
364    usage.addKeyboardMouseBinding("a","Toggle on/off the automatic advancement for image to image");
365    usage.addKeyboardMouseBinding("n","Advance to next image");
366    usage.addKeyboardMouseBinding("p","Move to previous image");
367    usage.addKeyboardMouseBinding("q","Zoom into the image");
368    usage.addKeyboardMouseBinding("a","Zoom out of the image");
369    usage.addKeyboardMouseBinding("j","Reduce horizontal offset");
370    usage.addKeyboardMouseBinding("k","Increase horizontal offset");
371    usage.addKeyboardMouseBinding("m","Reduce vertical offset");
372    usage.addKeyboardMouseBinding("i","Increase vertical offset");
373}
374
375void SlideEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
376{
377    if (_autoSteppingActive && nv->getFrameStamp())
378    {
379        double time = nv->getFrameStamp()->getSimulationTime();
380       
381        if (_firstTraversal)
382        {
383            _firstTraversal = false;
384            _previousTime = time;
385        }
386        else if (time-_previousTime>_timePerSlide)
387        {
388            _previousTime = time;
389           
390            nextSlide();
391        }
392       
393    }
394
395    traverse(node,nv);
396}
397
398void SlideEventHandler::nextSlide()
399{
400
401    if (_switch->getNumChildren()==0) return;
402
403    ++_activeSlide;
404
405    if (_fileList.size()>0) {
406        if (_activeSlide>= _fileList.size()/2 ) _activeSlide = 0;
407        osg::ref_ptr<osg::Group> images = loadImages(_fileList[2*_activeSlide],_fileList[2*_activeSlide+1],_texmatLeft.get(),_texmatRight.get(),_radius,_height,_length);
408        if (images.valid()) _switch->replaceChild(_switch->getChild(0),images.get());
409
410    } else {
411        if (_activeSlide>=_switch->getNumChildren()) _activeSlide = 0;
412
413        _switch->setSingleChildOn(_activeSlide);
414    }
415}
416
417void SlideEventHandler::previousSlide()
418{
419    if (_switch->getNumChildren()==0) return;
420
421    if (_fileList.size()>0) {
422        if (_activeSlide==0) _activeSlide = _fileList.size()/2-1;
423        else --_activeSlide;
424        osg::ref_ptr<osg::Group> images = loadImages(_fileList[2*_activeSlide],_fileList[2*_activeSlide+1],_texmatLeft.get(),_texmatRight.get(),_radius,_height,_length);
425        if (images.valid()) _switch->replaceChild(_switch->getChild(0),images.get());
426    } else {   
427        if (_activeSlide==0) _activeSlide = _switch->getNumChildren()-1;
428        else --_activeSlide;
429
430        _switch->setSingleChildOn(_activeSlide);
431    }
432}
433
434void SlideEventHandler::scaleImage(float s)
435{
436    _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));
437    _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));
438}
439
440void SlideEventHandler::offsetImage(float ds,float dt)
441{
442    _currentSeperationX+=ds;
443    _currentSeperationY+=dt;
444    osg::notify(osg::NOTICE)<<"image offset x = "<<_currentSeperationX<<"  y ="<<_currentSeperationY<<std::endl;
445    _texmatLeft->setMatrix(_texmatLeft->getMatrix()*osg::Matrix::translate(ds,dt,0.0f));
446    _texmatRight->setMatrix(_texmatRight->getMatrix()*osg::Matrix::translate(-ds,-dt,0.0f));
447}
448
449void SlideEventHandler::rotateImage(float rx,float ry)
450{
451    const float scale = 0.5f;
452    _texmatLeft->setMatrix(_texmatLeft->getMatrix()*osg::Matrix::translate(-rx*scale,-ry*scale,0.0f));
453    _texmatRight->setMatrix(_texmatRight->getMatrix()*osg::Matrix::translate(-rx*scale,-ry*scale,0.0f));
454}
455
456void SlideEventHandler::initTexMatrices()
457{
458    _texmatLeft->setMatrix(osg::Matrix::translate(_initSeperationX,_initSeperationY,0.0f));
459    _texmatRight->setMatrix(osg::Matrix::translate(-_initSeperationX,-_initSeperationY,0.0f));
460}
461
462
463
464int main( int argc, char **argv )
465{
466    // use an ArgumentParser object to manage the program arguments.
467    osg::ArgumentParser arguments(&argc,argv);
468   
469    // set up the usage document, in case we need to print out how to use this program.
470    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use node masks to create stereo images.");
471    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye");
472    arguments.getApplicationUsage()->addCommandLineOption("-d <float>","Time delay in seconds between the display of successive image pairs when in auto advance mode.");
473    arguments.getApplicationUsage()->addCommandLineOption("-a","Enter auto advance of image pairs on start up.");
474    arguments.getApplicationUsage()->addCommandLineOption("-x <float>","Horizontal offset of left and right images.");
475    arguments.getApplicationUsage()->addCommandLineOption("-y <float>","Vertical offset of left and right images.");
476    arguments.getApplicationUsage()->addCommandLineOption("--disk","Keep images on disk");
477    arguments.getApplicationUsage()->addCommandLineOption("-files <filename>","Load filenames from a file");
478    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
479    arguments.getApplicationUsage()->addCommandLineOption("--SingleThreaded","Select SingleThreaded threading model for viewer.");
480    arguments.getApplicationUsage()->addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer.");
481    arguments.getApplicationUsage()->addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer.");
482    arguments.getApplicationUsage()->addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer.");
483   
484
485    // construct the viewer.
486    osgViewer::Viewer viewer;
487
488    // register the handler to add keyboard and mouse handling.
489    SlideEventHandler* seh = new SlideEventHandler();
490    viewer.addEventHandler(seh);
491
492    // read any time delay argument.
493    float timeDelayBetweenSlides = 5.0f;
494    while (arguments.read("-d",timeDelayBetweenSlides)) {}
495
496    bool autoSteppingActive = false;
497    while (arguments.read("-a")) autoSteppingActive = true;
498
499    float offsetX=0.0f;
500    while (arguments.read("-x",offsetX)) {}
501
502    float offsetY=0.0f;
503    while (arguments.read("-y",offsetY)) {}
504
505    bool onDisk=false;
506    while (arguments.read("--disk")) { onDisk=true;}
507
508    std::string filename="";
509    FileList fileList;
510    // extract the filenames from the a file, one filename per line.
511    while (arguments.read("-files",filename)) {
512        osgDB::ifstream is(filename.c_str());
513        if (is) {
514                std::string line;
515                while (std::getline(is,line,'\n')) fileList.push_back(line);
516                is.close();
517            }
518   
519    }
520
521    // if user request help write it out to cout.
522    if (arguments.read("-h") || arguments.read("--help"))
523    {
524        arguments.getApplicationUsage()->write(std::cout);
525        return 1;
526    }
527
528    osgViewer::Viewer::ThreadingModel threading = osgViewer::Viewer::SingleThreaded;
529    while (arguments.read("--SingleThreaded")) threading = osgViewer::Viewer::SingleThreaded;
530    while (arguments.read("--CullDrawThreadPerContext")) threading = osgViewer::Viewer::CullDrawThreadPerContext;
531    while (arguments.read("--DrawThreadPerContext")) threading = osgViewer::Viewer::DrawThreadPerContext;
532    while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) threading = osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext;
533
534    viewer.setThreadingModel(threading);
535
536    // any option left unread are converted into errors to write out later.
537    arguments.reportRemainingOptionsAsUnrecognized();
538
539    // report any errors if they have occurred when parsing the program arguments.
540    if (arguments.errors())
541    {
542        arguments.writeErrorMessages(std::cout);
543        return 1;
544    }
545   
546    // extract the filenames from the arguments list.
547    for(int pos=1;pos<arguments.argc();++pos)
548    {
549        if (arguments.isString(pos)) fileList.push_back(arguments[pos]);
550    }
551
552    if (fileList.empty())
553    {
554        fileList.push_back("Images/dog_left_eye.jpg");
555         fileList.push_back("Images/dog_right_eye.jpg");
556    }
557    else if (fileList.size()<2)
558    {
559        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
560        return 1;
561    }
562
563    // now the windows have been realized we switch off the cursor to prevent it
564    // distracting the people seeing the stereo images.
565    double fovy, aspectRatio, zNear, zFar;
566    viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
567
568    float radius = 1.0f;
569    float height = 2*radius*tan(osg::DegreesToRadians(fovy)*0.5f);
570    float length = osg::PI*radius;  // half a cylinder.
571
572    // use a texture matrix to control the placement of the image.
573    osg::TexMat* texmatLeft = new osg::TexMat;
574    osg::TexMat* texmatRight = new osg::TexMat;
575
576    // creat the scene from the file list.
577    osg::ref_ptr<osg::Switch> rootNode;
578    if (!onDisk)  rootNode = createScene(fileList,texmatLeft,texmatRight,radius,height,length);
579    else rootNode=new osg::Switch();
580
581    //osgDB::writeNodeFile(*rootNode,"test.osg");
582
583
584    viewer.getCamera()->setCullMask(0xffffffff);
585    viewer.getCamera()->setCullMaskLeft(0x00000001);
586    viewer.getCamera()->setCullMaskRight(0x00000002);
587
588    // set up the use of stereo by default.
589    osg::DisplaySettings::instance()->setStereo(true);
590
591    // set the scene to render
592    viewer.setSceneData(rootNode.get());
593
594
595    // create the windows and run the threads.
596    viewer.realize();
597
598
599    // switch off the cursor
600    osgViewer::Viewer::Windows windows;
601    viewer.getWindows(windows);
602    for(osgViewer::Viewer::Windows::iterator itr = windows.begin();
603        itr != windows.end();
604        ++itr)
605    {
606        (*itr)->useCursor(false);
607    }
608
609    viewer.setFusionDistance(osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE,radius);
610
611    // set up the SlideEventHandler.
612    if (onDisk) seh->set(fileList,rootNode.get(),offsetX,offsetY,texmatLeft,texmatRight,radius,height,length,timeDelayBetweenSlides,autoSteppingActive);
613    else seh->set(rootNode.get(),offsetX,offsetY,texmatLeft,texmatRight,timeDelayBetweenSlides,autoSteppingActive);
614   
615    osg::Matrix homePosition;
616    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));
617       
618    while( !viewer.done() )
619    {
620        viewer.getCamera()->setViewMatrix(homePosition);
621
622        // fire off the cull and draw traversals of the scene.
623        viewer.frame();
624       
625    }
626   
627    return 0;
628}
Note: See TracBrowser for help on using the browser.