Port of osghangglide to use osg producer. Default build still uses GLUT.
This commit is contained in:
parent
4c4735a586
commit
fa70860427
@ -19,6 +19,7 @@ HEADERFILES = \
|
|||||||
terrain_texcoords.h\
|
terrain_texcoords.h\
|
||||||
|
|
||||||
LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||||
|
#LIBS += -losgProducer -l Producer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||||
|
|
||||||
INSTFILES = \
|
INSTFILES = \
|
||||||
$(CXXFILES)\
|
$(CXXFILES)\
|
||||||
@ -27,4 +28,8 @@ INSTFILES = \
|
|||||||
|
|
||||||
EXEC = osghangglide
|
EXEC = osghangglide
|
||||||
|
|
||||||
|
CXXFLAGS += -DUSE_GLUT
|
||||||
|
#CXXFLAGS += $(PRODUCER_INCLUDE_DIR)
|
||||||
|
#LDFLAGS += $(PRODUCER_LIB_DIR)
|
||||||
|
|
||||||
include $(TOPDIR)/Make/makerules
|
include $(TOPDIR)/Make/makerules
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
#include <osgDB/Registry>
|
#include <osgDB/Registry>
|
||||||
#include <osgDB/ReadFile>
|
#include <osgDB/ReadFile>
|
||||||
|
|
||||||
#include <osgGLUT/glut>
|
#include <osgGA/AnimationPathManipulator>
|
||||||
#include <osgGLUT/Viewer>
|
|
||||||
|
|
||||||
#include "GliderManipulator.h"
|
#include "GliderManipulator.h"
|
||||||
|
|
||||||
@ -52,6 +51,58 @@ struct MoveEarthySkyWithEyePointCallback : public osg::Transform::ComputeTransfo
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
osg::Group* createModel()
|
||||||
|
{
|
||||||
|
// no database loaded so automatically create Ed Levin Park..
|
||||||
|
osg::Group* group = new osg::Group;
|
||||||
|
|
||||||
|
// the base and sky subgraphs go to set the earth sky of the
|
||||||
|
// model and clear the color and depth buffer for us, by using
|
||||||
|
// osg::Depth, and setting their bin numbers to less than 0,
|
||||||
|
// to force them to draw before the rest of the scene.
|
||||||
|
|
||||||
|
osg::ClearNode* clearNode = new osg::ClearNode;
|
||||||
|
clearNode->setRequiresClear(false); // we've got base and sky to do it.
|
||||||
|
|
||||||
|
// use a transform to make the sky and base around with the eye point.
|
||||||
|
osg::Transform* transform = new osg::Transform;
|
||||||
|
|
||||||
|
// transform's value isn't knowm until in the cull traversal so its bounding
|
||||||
|
// volume is can't be determined, therefore culling will be invalid,
|
||||||
|
// so switch it off, this cause all our paresnts to switch culling
|
||||||
|
// off as well. But don't worry culling will be back on once underneath
|
||||||
|
// this node or any other branch above this transform.
|
||||||
|
transform->setCullingActive(false);
|
||||||
|
|
||||||
|
// set the compute transform callback to do all the work of
|
||||||
|
// determining the transform according to the current eye point.
|
||||||
|
transform->setComputeTransformCallback(new MoveEarthySkyWithEyePointCallback);
|
||||||
|
|
||||||
|
// add the sky and base layer.
|
||||||
|
transform->addChild(makeSky()); // bin number -2 so drawn first.
|
||||||
|
transform->addChild(makeBase()); // bin number -1 so draw second.
|
||||||
|
|
||||||
|
// add the transform to the earth sky.
|
||||||
|
clearNode->addChild(transform);
|
||||||
|
|
||||||
|
// add to earth sky to the scene.
|
||||||
|
group->addChild(clearNode);
|
||||||
|
|
||||||
|
// the rest of the scene drawn after the base and sky above.
|
||||||
|
group->addChild(makeTrees()); // will drop into a transparent, depth sorted bin (1)
|
||||||
|
group->addChild(makeTerrain()); // will drop into default bin - state sorted 0
|
||||||
|
group->addChild(makeTank()); // will drop into default bin - state sorted 0
|
||||||
|
// add the following in the future...
|
||||||
|
// makeGliders
|
||||||
|
// makeClouds
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USE_GLUT
|
||||||
|
|
||||||
|
#include <osgGLUT/glut>
|
||||||
|
#include <osgGLUT/Viewer>
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
@ -75,53 +126,7 @@ int main( int argc, char **argv )
|
|||||||
|
|
||||||
// load the nodes from the commandline arguments.
|
// load the nodes from the commandline arguments.
|
||||||
osg::Node* rootnode = osgDB::readNodeFiles(commandLine);
|
osg::Node* rootnode = osgDB::readNodeFiles(commandLine);
|
||||||
if (!rootnode)
|
if (!rootnode) rootnode = createModel();
|
||||||
{
|
|
||||||
// no database loaded so automatically create Ed Levin Park..
|
|
||||||
osg::Group* group = new osg::Group;
|
|
||||||
rootnode = group;
|
|
||||||
|
|
||||||
// the base and sky subgraphs go to set the earth sky of the
|
|
||||||
// model and clear the color and depth buffer for us, by using
|
|
||||||
// osg::Depth, and setting their bin numbers to less than 0,
|
|
||||||
// to force them to draw before the rest of the scene.
|
|
||||||
|
|
||||||
osg::ClearNode* clearNode = new osg::ClearNode;
|
|
||||||
clearNode->setRequiresClear(false); // we've got base and sky to do it.
|
|
||||||
|
|
||||||
// use a transform to make the sky and base around with the eye point.
|
|
||||||
osg::Transform* transform = new osg::Transform;
|
|
||||||
|
|
||||||
// transform's value isn't knowm until in the cull traversal so its bounding
|
|
||||||
// volume is can't be determined, therefore culling will be invalid,
|
|
||||||
// so switch it off, this cause all our paresnts to switch culling
|
|
||||||
// off as well. But don't worry culling will be back on once underneath
|
|
||||||
// this node or any other branch above this transform.
|
|
||||||
transform->setCullingActive(false);
|
|
||||||
|
|
||||||
// set the compute transform callback to do all the work of
|
|
||||||
// determining the transform according to the current eye point.
|
|
||||||
transform->setComputeTransformCallback(new MoveEarthySkyWithEyePointCallback);
|
|
||||||
|
|
||||||
// add the sky and base layer.
|
|
||||||
transform->addChild(makeSky()); // bin number -2 so drawn first.
|
|
||||||
transform->addChild(makeBase()); // bin number -1 so draw second.
|
|
||||||
|
|
||||||
// add the transform to the earth sky.
|
|
||||||
clearNode->addChild(transform);
|
|
||||||
|
|
||||||
// add to earth sky to the scene.
|
|
||||||
group->addChild(clearNode);
|
|
||||||
|
|
||||||
// the rest of the scene drawn after the base and sky above.
|
|
||||||
group->addChild(makeTrees()); // will drop into a transparent, depth sorted bin (1)
|
|
||||||
group->addChild(makeTerrain()); // will drop into default bin - state sorted 0
|
|
||||||
group->addChild(makeTank()); // will drop into default bin - state sorted 0
|
|
||||||
// add the following in the future...
|
|
||||||
// makeGliders
|
|
||||||
// makeClouds
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
viewer.addViewport( rootnode );
|
viewer.addViewport( rootnode );
|
||||||
|
|
||||||
@ -136,3 +141,94 @@ int main( int argc, char **argv )
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <osgProducer/Viewer>
|
||||||
|
|
||||||
|
int main( int argc, char **argv )
|
||||||
|
{
|
||||||
|
// create the commandline args.
|
||||||
|
std::string pathfile;
|
||||||
|
std::string configfile;
|
||||||
|
std::vector<std::string> commandLine;
|
||||||
|
for(int i=1;i<argc;++i) {
|
||||||
|
if( std::string(argv[i]) == "-p" ) {
|
||||||
|
if( (i+1) >= argc ) {
|
||||||
|
std::cout << "path argument required for -p option."<<std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
pathfile = std::string(argv[++i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( std::string(argv[i]) == "-c" ) {
|
||||||
|
if( (i+1) >= argc ) {
|
||||||
|
std::cout << "path argument required for -c option."<<std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
configfile = std::string(argv[++i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
commandLine.push_back(argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::DisplaySettings::instance()->readCommandLine(commandLine);
|
||||||
|
osgDB::readCommandLine(commandLine);
|
||||||
|
|
||||||
|
osgProducer::Viewer* viewer = 0;
|
||||||
|
if (!configfile.empty()) viewer = new osgProducer::Viewer(configfile);
|
||||||
|
else viewer = new osgProducer::Viewer;
|
||||||
|
|
||||||
|
// configure the plugin registry from the commandline arguments, and
|
||||||
|
// eat any parameters that have been matched.
|
||||||
|
osgDB::readCommandLine(commandLine);
|
||||||
|
|
||||||
|
// load the nodes from the commandline arguments.
|
||||||
|
osg::Node* rootnode = osgDB::readNodeFiles(commandLine);
|
||||||
|
if (!rootnode) rootnode = createModel();
|
||||||
|
|
||||||
|
|
||||||
|
// set the scene to render
|
||||||
|
viewer->setSceneData(rootnode);
|
||||||
|
|
||||||
|
// set up the value with sensible defaults.
|
||||||
|
viewer->setUpViewer();
|
||||||
|
|
||||||
|
unsigned int pos = viewer->addCameraManipulator(new GliderManipulator());
|
||||||
|
viewer->selectCameraManipulator(pos);
|
||||||
|
|
||||||
|
if( !pathfile.empty() ) {
|
||||||
|
osg::ref_ptr<osgGA::AnimationPathManipulator> apm = new osgGA::AnimationPathManipulator(pathfile);
|
||||||
|
if( apm.valid() && apm->valid() )
|
||||||
|
{
|
||||||
|
unsigned int num = viewer->addCameraManipulator(apm.get());
|
||||||
|
viewer->selectCameraManipulator(num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// set up the stack size
|
||||||
|
viewer->setStackSize( 20* 1024 * 1024);
|
||||||
|
|
||||||
|
// create the windows and run the threads.
|
||||||
|
viewer->realize(Producer::CameraGroup::ThreadPerCamera);
|
||||||
|
|
||||||
|
while( !viewer->done() )
|
||||||
|
{
|
||||||
|
// wait for all cull and draw threads to complete.
|
||||||
|
viewer->sync();
|
||||||
|
|
||||||
|
// update the scene by traversing it with the the update visitor which will
|
||||||
|
// call all node update callbacks and animations.
|
||||||
|
viewer->update();
|
||||||
|
|
||||||
|
// fire off the cull and draw traversals of the scene.
|
||||||
|
viewer->frame();
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
|
|
||||||
// create the camera group.
|
|
||||||
|
|
||||||
// create the commandline args.
|
// create the commandline args.
|
||||||
std::string pathfile;
|
std::string pathfile;
|
||||||
std::string configfile;
|
std::string configfile;
|
||||||
@ -43,11 +41,16 @@ int main( int argc, char **argv )
|
|||||||
commandLine.push_back(argv[i]);
|
commandLine.push_back(argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
osg::DisplaySettings::instance()->readCommandLine(commandLine);
|
||||||
|
osgDB::readCommandLine(commandLine);
|
||||||
|
|
||||||
osgProducer::Viewer* viewer = 0;
|
osgProducer::Viewer* viewer = 0;
|
||||||
if (!configfile.empty()) viewer = new osgProducer::Viewer(configfile);
|
if (!configfile.empty()) viewer = new osgProducer::Viewer(configfile);
|
||||||
else viewer = new osgProducer::Viewer;
|
else viewer = new osgProducer::Viewer;
|
||||||
|
|
||||||
osg::DisplaySettings::instance()->readCommandLine(commandLine);
|
|
||||||
|
// configure the plugin registry from the commandline arguments, and
|
||||||
|
// eat any parameters that have been matched.
|
||||||
osgDB::readCommandLine(commandLine);
|
osgDB::readCommandLine(commandLine);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user