Moved SimpleViewer and GraphicsWindow into their own osgViewer library, updated simpleviewer examples to reflect this change

This commit is contained in:
Robert Osfield
2006-11-02 12:27:15 +00:00
parent f9fb99dc43
commit e0f395fd07
35 changed files with 470 additions and 117 deletions

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgkeyboardmouse.cpp\
LIBS += -lProducer -losgFX -losgGA -losgDB -losgUtil -losg $(X_LIBS) $(OTHER_LIBS) -lOpenThreads
LIBS += -lProducer -losgFX -losgViewer -losgGA -losgDB -losgUtil -losg $(X_LIBS) $(OTHER_LIBS) -lOpenThreads
INSTFILES = \
$(CXXFILES)\

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgkeyboardmouse.cpp\
LIBS += -lProducer -losgFX -losgDB --losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -lProducer -losgFX -losgViewer -losgGA -losgDB --losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgkeyboardmouse

View File

@@ -1,6 +1,6 @@
// C++ source file - (C) 2003 Robert Osfield, released under the OSGPL.
//
// Simple example of use of Producer::RenderSurface + KeyboardMouseCallback + SceneView
// Simple example of use of Producer::RenderSurface + KeyboardMouseCallback + SimpleViewer
// example that provides the user with control over view position with basic picking.
#include <Producer/RenderSurface>
@@ -11,17 +11,16 @@
#include <osg/io_utils>
#include <osg/observer_ptr>
#include <osgUtil/SceneView>
#include <osgUtil/IntersectVisitor>
#include <osgUtil/IntersectionVisitor>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgGA/SimpleViewer>
#include <osgGA/TrackballManipulator>
#include <osgGA/StateSetManipulator>
#include <osgViewer/SimpleViewer>
#include <osgFX/Scribe>
// ----------- Begining of glue classes to adapter Producer's keyboard mouse events to osgGA's abstraction events.
@@ -138,21 +137,22 @@ public:
class PickHandler : public osgGA::GUIEventHandler {
public:
PickHandler(osgUtil::SceneView* sceneView):
_sceneView(sceneView),
PickHandler():
_mx(0.0),_my(0.0) {}
~PickHandler() {}
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
osgViewer::SimpleViewer* viewer = dynamic_cast<osgViewer::SimpleViewer*>(&aa);
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYUP):
{
if (ea.getKey()=='s')
if (ea.getKey()=='s' && viewer)
{
saveSelectedModel();
saveSelectedModel(viewer->getSceneData());
}
return false;
}
@@ -168,7 +168,7 @@ public:
if (_mx == ea.getX() && _my == ea.getY())
{
// only do a pick if the mouse hasn't moved
pick(ea);
pick(ea,viewer);
}
return true;
}
@@ -178,39 +178,39 @@ public:
}
}
void pick(const osgGA::GUIEventAdapter& ea)
void pick(const osgGA::GUIEventAdapter& ea, osgViewer::SimpleViewer* viewer)
{
osg::Node* scene = _sceneView.valid() ? _sceneView->getSceneData() : 0;
osg::Node* scene = viewer->getSceneData();
if (!scene) return;
// remap the mouse x,y into viewport coordinates.
osg::notify(osg::NOTICE)<<std::endl;
#if 0
// use non dimension coordinates - in projection/clip space
osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::PROJECTION, osg::Vec3d(ea.getXnormalized(),ea.getYnormalized(),0.0), osg::Vec3d(ea.getXnormalized(),ea.getYnormalized(),1.0) );
osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::PROJECTION, osg::Vec3d(ea.getXnormalized(),ea.getYnormalized(),-1.0), osg::Vec3d(ea.getXnormalized(),ea.getYnormalized(),1.0) );
#else
// use window coordinates
float mx = _sceneView->getViewport()->x() + (int)((float)_sceneView->getViewport()->width()*(ea.getXnormalized()*0.5f+0.5f));
float my = _sceneView->getViewport()->y() + (int)((float)_sceneView->getViewport()->height()*(ea.getYnormalized()*0.5f+0.5f));
// remap the mouse x,y into viewport coordinates.
osg::Viewport* viewport = viewer->getCamera()->getViewport();
float mx = viewport->x() + (int)((float)viewport->width()*(ea.getXnormalized()*0.5f+0.5f));
float my = viewport->y() + (int)((float)viewport->height()*(ea.getYnormalized()*0.5f+0.5f));
osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, osg::Vec3d(mx,my,0.0), osg::Vec3d(mx,my,1.0) );
#endif
osgUtil::IntersectionVisitor iv(picker);
_sceneView->getCamera()->accept(iv);
osg::notify(osg::NOTICE)<<"Done pick, "<<picker->containsIntersections()<<std::endl;
viewer->getCamera()->accept(iv);
if (picker->containsIntersections())
{
osgUtil::LineSegmentIntersector::Intersection intersection = picker->getFirstIntersection();
osg::notify(osg::NOTICE)<<"Picking "<<intersection.localIntersectionPoint<<std::endl;
osg::notify(osg::NOTICE)<<"Picked "<<intersection.localIntersectionPoint<<std::endl;
#if 0
#if 1
osg::NodePath& nodePath = intersection.nodePath;
osg::Node* node = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
osg::Group* parent = (nodePath.size()>=2)?dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]):0;
@@ -247,37 +247,14 @@ public:
}
{
float mx = _sceneView->getViewport()->x() + (int)((float)_sceneView->getViewport()->width()*(ea.getXnormalized()*0.5f+0.5f));
float my = _sceneView->getViewport()->y() + (int)((float)_sceneView->getViewport()->height()*(ea.getYnormalized()*0.5f+0.5f));
// do the pick traversal use the other PickVisitor to double check results.
osgUtil::PickVisitor pick(_sceneView->getViewport(),
_sceneView->getProjectionMatrix(),
_sceneView->getViewMatrix(), mx, my);
scene->accept(pick);
osgUtil::PickVisitor::LineSegmentHitListMap& segHitList = pick.getSegHitList();
if (!segHitList.empty() && !segHitList.begin()->second.empty())
{
// get the hits for the first segment
osgUtil::PickVisitor::HitList& hits = segHitList.begin()->second;
// just take the first hit - nearest the eye point.
osgUtil::Hit& hit = hits.front();
std::cout<<"Got hits"<<hit.getLocalIntersectPoint()<<std::endl;
}
}
}
void saveSelectedModel()
void saveSelectedModel(osg::Node* scene)
{
if (!scene) return;
CreateModelToSaveVisitor cmtsv;
_sceneView->getSceneData()->accept(cmtsv);
scene->accept(cmtsv);
if (cmtsv._group->getNumChildren()>0)
{
@@ -288,7 +265,6 @@ public:
protected:
osg::observer_ptr<osgUtil::SceneView> _sceneView;
float _mx,_my;
};
@@ -317,7 +293,7 @@ int main( int argc, char **argv )
// create the view of the scene.
osgGA::SimpleViewer viewer;
osgViewer::SimpleViewer viewer;
viewer.setSceneData(loadedModel.get());
// set up a KeyboardMouse to manage the events comming in from the RenderSurface
@@ -334,7 +310,7 @@ int main( int argc, char **argv )
viewer.addEventHandler(statesetManipulator.get());
// add the pick handler
viewer.addEventHandler(new PickHandler(viewer.getSceneView()));
viewer.addEventHandler(new PickHandler());
// set the window dimensions
viewer.getEventQueue()->getCurrentEventState()->setWindowRectangle(100,100,800,600);

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimple.cpp\
LIBS += -lProducer -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) -lOpenThreads
LIBS += -lProducer -losgViewer -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) -lOpenThreads
INSTFILES = \
$(CXXFILES)\

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimple.cpp\
LIBS += -lProducer -losgDB --losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -lProducer -losgViewer -losgDB --losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgsimple

View File

@@ -7,7 +7,7 @@
#include <osgUtil/SceneView>
#include <osgDB/ReadFile>
#include <osgGA/SimpleViewer>
#include <osgViewer/SimpleViewer>
int main( int argc, char **argv )
@@ -34,7 +34,7 @@ int main( int argc, char **argv )
renderSurface->realize();
osgGA::SimpleViewer viewer;
osgViewer::SimpleViewer viewer;
viewer.setSceneData(loadedModel.get());
// initialize the view to look at the center of the scene graph

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerFLTK.cpp\
LIBS += -losgGA -losgDB -losgUtil -losg -lfltk -lfltk_gl $(GL_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg -lfltk -lfltk_gl $(GL_LIBS) $(OTHER_LIBS)
INSTFILES = \
$(CXXFILES)\

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerQT3.cpp\
LIBS += -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgsimpleviewerQT3

View File

@@ -3,7 +3,7 @@
// Simple example using GLUT to create an OpenGL window and OSG for rendering.
// Derived from osgGLUTsimple.cpp and osgkeyboardmouse.cpp
#include <osgGA/SimpleViewer>
#include <osgViewer/SimpleViewer>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>
@@ -12,7 +12,7 @@
#include <iostream>
class GraphicsWindowFLTK : public Fl_Gl_Window, virtual osgGA::GraphicsWindow
class GraphicsWindowFLTK : public Fl_Gl_Window, virtual osgViewer::GraphicsWindow
{
public:
@@ -70,7 +70,7 @@ void idle_cb()
}
class SimpleViewerFLTK : public osgGA::SimpleViewer, public GraphicsWindowFLTK
class SimpleViewerFLTK : public osgViewer::SimpleViewer, public GraphicsWindowFLTK
{
public:
SimpleViewerFLTK(int x, int y, int w, int h, const char *label=0):

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerGLUT.cpp\
LIBS += -losgGA -losgDB -losgUtil -losg $(GLUT_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg $(GLUT_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
INSTFILES = \
$(CXXFILES)\

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerGLUT.cpp\
LIBS += -losgGA -losgDB -losgUtil -losg -lglut $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg -lglut $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgsimpleviewerGLUT

View File

@@ -13,11 +13,11 @@
# include <GL/glut.h>
#endif
#include <osgGA/SimpleViewer>
#include <osgViewer/SimpleViewer>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>
osg::ref_ptr<osgGA::SimpleViewer> viewer;
osg::ref_ptr<osgViewer::SimpleViewer> viewer;
void display(void)
{
@@ -89,7 +89,7 @@ int main( int argc, char **argv )
glutKeyboardFunc( keyboard );
// create the view of the scene.
viewer = new osgGA::SimpleViewer;
viewer = new osgViewer::SimpleViewer;
viewer->setSceneData(loadedModel.get());
viewer->setCameraManipulator(new osgGA::TrackballManipulator);

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerProducer.cpp\
LIBS += -lProducer -losgGA -losgDB -losgUtil -losg $(X_LIBS) $(OTHER_LIBS) -lOpenThreads
LIBS += -lProducer -losgViewer -losgGA -losgDB -losgUtil -losg $(X_LIBS) $(OTHER_LIBS) -lOpenThreads
INSTFILES = \
$(CXXFILES)\

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerProducer.cpp\
LIBS += -lProducer -losgGA -losgDB --losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -lProducer -losgViewer -losgGA -losgDB --losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgsimpleviewerProducer

View File

@@ -8,7 +8,7 @@
#include <osgDB/ReadFile>
#include <osgGA/SimpleViewer>
#include <osgViewer/SimpleViewer>
#include <osgGA/TrackballManipulator>
#include <osgGA/StateSetManipulator>
@@ -81,7 +81,7 @@ private:
// first approach uses a custom GraphicsWindow
// then uses multiple inheritance to create a SimpleViewerWindowProducer
class GraphicsWindowProducer : public virtual osgGA::GraphicsWindow, public Producer::RenderSurface
class GraphicsWindowProducer : public virtual osgViewer::GraphicsWindow, public Producer::RenderSurface
{
public:
@@ -120,7 +120,7 @@ class GraphicsWindowProducer : public virtual osgGA::GraphicsWindow, public Prod
osg::ref_ptr<MyKeyboardMouseCallback> _kbmcb;
};
class SimplerViewerProducer : public osgGA::SimpleViewer, public GraphicsWindowProducer
class SimplerViewerProducer : public osgViewer::SimpleViewer, public GraphicsWindowProducer
{
public:
SimplerViewerProducer() {}
@@ -198,7 +198,7 @@ int main( int argc, char **argv )
// create the view of the scene.
osgGA::SimpleViewer viewer;
osgViewer::SimpleViewer viewer;
viewer.setSceneData(loadedModel.get());
// set up a KeyboardMouse to manage the events comming in from the RenderSurface

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerQT3.cpp\
LIBS += -losgGA -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(OTHER_LIBS)
INSTFILES = \
$(CXXFILES)\

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerQT3.cpp\
LIBS += -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgsimpleviewerQT3

View File

@@ -3,7 +3,7 @@
// Simple example using GLUT to create an OpenGL window and OSG for rendering.
// Derived from osgGLUTsimple.cpp and osgkeyboardmouse.cpp
#include <osgGA/SimpleViewer>
#include <osgViewer/SimpleViewer>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>
@@ -14,7 +14,7 @@ class QWidget;
#include <iostream>
class GraphicsWindowQT : public QGLWidget, virtual public osgGA::GraphicsWindow
class GraphicsWindowQT : public QGLWidget, virtual public osgViewer::GraphicsWindow
{
public:
@@ -89,7 +89,7 @@ void GraphicsWindowQT::mouseMoveEvent( QMouseEvent* event )
}
class SimpleViewerQT : public osgGA::SimpleViewer, public GraphicsWindowQT
class SimpleViewerQT : public osgViewer::SimpleViewer, public GraphicsWindowQT
{
public:
SimpleViewerQT() {}

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerQT4.cpp\
LIBS += -losgGA -losgDB -losgUtil -losg -lQtOpenGL -lQtGui -lQtCore $(GL_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg -lQtOpenGL -lQtGui -lQtCore $(GL_LIBS) $(OTHER_LIBS)
INSTFILES = \
$(CXXFILES)\

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerQT4.cpp\
LIBS += -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgsimpleviewerQT4

View File

@@ -3,7 +3,7 @@
// Simple example using GLUT to create an OpenGL window and OSG for rendering.
// Derived from osgGLUTsimple.cpp and osgkeyboardmouse.cpp
#include <osgGA/SimpleViewer>
#include <osgViewer/SimpleViewer>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>
@@ -14,7 +14,7 @@
#include <iostream>
class GraphicsWindowQT : public QGLWidget, virtual osgGA::GraphicsWindow
class GraphicsWindowQT : public QGLWidget, virtual osgViewer::GraphicsWindow
{
public:
@@ -89,7 +89,7 @@ void GraphicsWindowQT::mouseMoveEvent( QMouseEvent* event )
}
class SimpleViewerQT : public osgGA::SimpleViewer, public GraphicsWindowQT
class SimpleViewerQT : public osgViewer::SimpleViewer, public GraphicsWindowQT
{
public:
SimpleViewerQT() {}

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerSDL.cpp\
LIBS += -losgGA -losgDB -losgUtil -losg `sdl-config --libs` $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg `sdl-config --libs` $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
INSTFILES = \
$(CXXFILES)\

View File

@@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgsimpleviewerSDL.cpp\
LIBS += -losgGA -losgDB -losgUtil -losg `sdl-config --libs` $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgViewer -losgGA -losgDB -losgUtil -losg `sdl-config --libs` $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgsimpleviewerSDL

View File

@@ -3,7 +3,7 @@
// Simple example using GLUT to create an OpenGL window and OSG for rendering.
// Derived from osgGLUTsimple.cpp and osgkeyboardmouse.cpp
#include <osgGA/SimpleViewer>
#include <osgViewer/SimpleViewer>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>
@@ -90,7 +90,7 @@ int main( int argc, char **argv )
SDL_EnableUNICODE(1);
osgGA::SimpleViewer viewer;
osgViewer::SimpleViewer viewer;
viewer.setSceneData(loadedModel.get());
viewer.setCameraManipulator(new osgGA::TrackballManipulator);
viewer.getEventQueue()->windowResize(0, 0, windowWidth, windowHeight );