hi!
Yes, I got it! thanks a lot... I'm attaching a sample code (very
small) as to how I did it. Please do tell me if there's a better way than
this.
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osgDB/ReadFile>
#include <iostream>
using namespace std;
osg::ref_ptr<osg::Node> model;
osgViewer::CompositeViewer* cViewer;
int composite = 0;
class Keyboard : public osgGA::GUIEventHandler{
public:
Keyboard():
_mx(0.0f), _my(0.0f){}
virtual bool handle(const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& aa){
osgViewer::Viewer* viewer =
dynamic_cast<osgViewer::Viewer*> (&aa);
if (ea.getEventType() ==
osgGA::GUIEventAdapter::KEYDOWN){
if (ea.getKey() == 'c'){
cout << "Viewer changed!!" << endl;
cViewer = new
osgViewer::CompositeViewer;
cViewer->addView(viewer);
composite = 1;
viewer->setDone(true);
}
}
}
private:
float _mx, _my;
};
int main(int argc, char **argv){
osgViewer::Viewer* viewer = new osgViewer::Viewer;
model = osgDB::readNodeFile(argv[1]);
viewer->setSceneData(model.get());
viewer->addEventHandler(new Keyboard);
viewer->run();
if (composite)
return cViewer->run();
return 0;
}
thanks a lot.
bye!
Sashidhar
On Dec 16, 2007 6:37 AM, Robert Osfield <[EMAIL PROTECTED]> wrote:
> HI Sashidhar,
>
> On Dec 16, 2007 7:04 AM, Sashidhar Guntury <[EMAIL PROTECTED]>
> wrote:
> > We have written an app in terms of modules where all the
> modules
> > except one use a normal viewer. One module uses Composite Viewer. Now
> the
> > problem is while the program is running, is it possible to switch over
> from
> > Normal Viewer to Composite Viewer and vice versa? I mean, is it
> possible,
> > (by pressing a key) to switch from Normal Viewer to Composite Viewer?
>
> You could if you want, but there is huge scope for managing different
> views/viewers so its without more info one can't really say whether
> what you want to do is the best way to tackle it. Viewer and
> CompositeViewer are very simila in many ways - in 2.2 they even share
> most of the viewer code via a ViewerBase class.
>
> As for stopping a viewer/composite view you simply exit the frameloop
> and call stopThreading() on the viewer. If you are using the run()
> method to wrap up the frame loop then just set the viewer's done flag
> to true and the run() method will exit.
>
> Robert.
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org