Added osgsimpleviewerQT3 example
This commit is contained in:
parent
1da298f919
commit
75391ceb16
@ -21,6 +21,8 @@ FREETYPE_INSTALLED ?= yes
|
|||||||
|
|
||||||
XINE_INSTALLED ?= no
|
XINE_INSTALLED ?= no
|
||||||
|
|
||||||
|
QT3_INSTALLED ?= no
|
||||||
|
|
||||||
ifeq ($(OS),Darwin)
|
ifeq ($(OS),Darwin)
|
||||||
DARWIN_QUICKTIME ?= yes
|
DARWIN_QUICKTIME ?= yes
|
||||||
endif
|
endif
|
||||||
|
@ -288,3 +288,9 @@ ifeq ($(GLUT_INSTALLED),yes)
|
|||||||
EXAMPLE_DIRS += osgGLUTkeyboardmouse
|
EXAMPLE_DIRS += osgGLUTkeyboardmouse
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(QT3_INSTALLED),yes)
|
||||||
|
|
||||||
|
EXAMPLE_DIRS += osgsimpleviewerQT3
|
||||||
|
|
||||||
|
endif
|
||||||
|
23
examples/osgsimpleviewerQT3/GNUmakefile
Normal file
23
examples/osgsimpleviewerQT3/GNUmakefile
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
TOPDIR = ../..
|
||||||
|
include $(TOPDIR)/Make/makedefs
|
||||||
|
|
||||||
|
CXXFILES =\
|
||||||
|
osgsimpleviewerQT3.cpp\
|
||||||
|
|
||||||
|
LIBS += -losgGA -losgDB -losgUtil -losg -lqt-mt $(GL_LIBS) $(OTHER_LIBS)
|
||||||
|
|
||||||
|
INSTFILES = \
|
||||||
|
$(CXXFILES)\
|
||||||
|
GNUmakefile.inst=GNUmakefile
|
||||||
|
|
||||||
|
EXEC = osgsimpleviewerQT3
|
||||||
|
|
||||||
|
INC += -I/usr/lib/qt3/include
|
||||||
|
|
||||||
|
ifeq ($(ARCH),64)
|
||||||
|
LDFLAGS += -L/usr/lib/qt3/lib64
|
||||||
|
else
|
||||||
|
LDFLAGS += -L/usr/lib/qt3/lib
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(TOPDIR)/Make/makerules
|
19
examples/osgsimpleviewerQT3/GNUmakefile.inst
Normal file
19
examples/osgsimpleviewerQT3/GNUmakefile.inst
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
TOPDIR = ../..
|
||||||
|
include $(TOPDIR)/Make/makedefs
|
||||||
|
|
||||||
|
CXXFILES =\
|
||||||
|
osgsimpleviewerQT3.cpp\
|
||||||
|
|
||||||
|
LIBS += -losgDB -losgUtil -losg -lglut $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||||
|
|
||||||
|
EXEC = osgsimpleviewerQT3
|
||||||
|
|
||||||
|
INC += -I/usr/lib/qt3/include
|
||||||
|
|
||||||
|
ifeq ($(ARCH),64)
|
||||||
|
LDFLAGS += -L/usr/lib/qt3/lib64
|
||||||
|
else
|
||||||
|
LDFLAGS += -L/usr/lib/qt3/lib
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(TOPDIR)/Make/makerules
|
134
examples/osgsimpleviewerQT3/osgsimpleviewerQT3.cpp
Normal file
134
examples/osgsimpleviewerQT3/osgsimpleviewerQT3.cpp
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
// C++ source file - (C) 2003 Robert Osfield, released under the OSGPL.
|
||||||
|
// (C) 2005 Mike Weiblen http://mew.cx/ released under the OSGPL.
|
||||||
|
// Simple example using GLUT to create an OpenGL window and OSG for rendering.
|
||||||
|
// Derived from osgGLUTsimple.cpp and osgkeyboardmouse.cpp
|
||||||
|
|
||||||
|
#include <osgGA/SimpleViewer>
|
||||||
|
#include <osgGA/TrackballManipulator>
|
||||||
|
#include <osgDB/ReadFile>
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
#include <qtimer.h>
|
||||||
|
#include <qgl.h>
|
||||||
|
#include <qapplication.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class OSGWidget : public QGLWidget, public osgGA::SimpleViewer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
OSGWidget( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 );
|
||||||
|
virtual ~OSGWidget() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void initializeGL();
|
||||||
|
virtual void paintGL();
|
||||||
|
|
||||||
|
virtual void resizeGL( int width, int height );
|
||||||
|
virtual void keyPressEvent( QKeyEvent* event );
|
||||||
|
virtual void keyReleaseEvent( QKeyEvent* event );
|
||||||
|
virtual void mousePressEvent( QMouseEvent* event );
|
||||||
|
virtual void mouseReleaseEvent( QMouseEvent* event );
|
||||||
|
virtual void mouseMoveEvent( QMouseEvent* event );
|
||||||
|
|
||||||
|
QTimer _timer;
|
||||||
|
};
|
||||||
|
|
||||||
|
OSGWidget::OSGWidget( QWidget * parent, const char * name, const QGLWidget * shareWidget, WFlags f):
|
||||||
|
QGLWidget(parent, name, shareWidget, f)
|
||||||
|
{
|
||||||
|
connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
|
||||||
|
_timer.start(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSGWidget::initializeGL()
|
||||||
|
{
|
||||||
|
QGLWidget::initializeGL();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSGWidget::paintGL()
|
||||||
|
{
|
||||||
|
frame();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSGWidget::resizeGL( int width, int height )
|
||||||
|
{
|
||||||
|
getEventQueue()->windowResize(0, 0, width, height );
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSGWidget::keyPressEvent( QKeyEvent* event )
|
||||||
|
{
|
||||||
|
getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) event->ascii() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSGWidget::keyReleaseEvent( QKeyEvent* event )
|
||||||
|
{
|
||||||
|
getEventQueue()->keyRelease( (osgGA::GUIEventAdapter::KeySymbol) event->ascii() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSGWidget::mousePressEvent( QMouseEvent* event )
|
||||||
|
{
|
||||||
|
int button = 0;
|
||||||
|
switch(event->button())
|
||||||
|
{
|
||||||
|
case(Qt::LeftButton): button = 1; break;
|
||||||
|
case(Qt::MidButton): button = 2; break;
|
||||||
|
case(Qt::RightButton): button = 3; break;
|
||||||
|
case(Qt::NoButton): button = 0; break;
|
||||||
|
default: button = 0; break;
|
||||||
|
}
|
||||||
|
getEventQueue()->mouseButtonPress(event->x(), event->y(), button);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSGWidget::mouseReleaseEvent( QMouseEvent* event )
|
||||||
|
{
|
||||||
|
int button = 0;
|
||||||
|
switch(event->button())
|
||||||
|
{
|
||||||
|
case(Qt::LeftButton): button = 1; break;
|
||||||
|
case(Qt::MidButton): button = 2; break;
|
||||||
|
case(Qt::RightButton): button = 3; break;
|
||||||
|
case(Qt::NoButton): button = 0; break;
|
||||||
|
default: button = 0; break;
|
||||||
|
}
|
||||||
|
getEventQueue()->mouseButtonRelease(event->x(), event->y(), button);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSGWidget::mouseMoveEvent( QMouseEvent* event )
|
||||||
|
{
|
||||||
|
getEventQueue()->mouseMotion(event->x(), event->y());
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int argc, char **argv )
|
||||||
|
{
|
||||||
|
QApplication a( argc, argv );
|
||||||
|
|
||||||
|
if (argc<2)
|
||||||
|
{
|
||||||
|
std::cout << argv[0] <<": requires filename argument." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// load the scene.
|
||||||
|
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(argv[1]);
|
||||||
|
if (!loadedModel)
|
||||||
|
{
|
||||||
|
std::cout << argv[0] <<": No data loaded." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OSGWidget* viewerWindow = new OSGWidget;
|
||||||
|
|
||||||
|
viewerWindow->setSceneData(loadedModel.get());
|
||||||
|
viewerWindow->setCameraManipulator(new osgGA::TrackballManipulator);
|
||||||
|
|
||||||
|
viewerWindow->show();
|
||||||
|
a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*EOF*/
|
Loading…
Reference in New Issue
Block a user