Ported following examples to osgViewer:

osgparticleeffects
osgphotoalbum
osgpick
osgpoints
osgpointsprite
osgprecipitation
osgprerender
osgprerendercubemap
osgreflect
osgscalarbar
osgscribe
osgsequence
osgplanets
This commit is contained in:
Robert Osfield
2007-01-10 13:52:22 +00:00
parent c5082cb85c
commit c4279bd5f1
57 changed files with 290 additions and 883 deletions

View File

@@ -17,7 +17,7 @@
#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osgProducer/Viewer>
#include <osgViewer/Viewer>
#include <osg/Material>
#include <osg/Geode>
@@ -36,15 +36,14 @@
class PickHandler : public osgGA::GUIEventHandler {
public:
PickHandler(osgProducer::Viewer* viewer,osgText::Text* updateText):
_viewer(viewer),
PickHandler(osgText::Text* updateText):
_updateText(updateText) {}
~PickHandler() {}
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
virtual void pick(const osgGA::GUIEventAdapter& ea);
virtual void pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea);
void setLabel(const std::string& name)
{
@@ -53,50 +52,49 @@ public:
protected:
osgProducer::Viewer* _viewer;
osg::ref_ptr<osgText::Text> _updateText;
};
bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::FRAME):
case(osgGA::GUIEventAdapter::FRAME):
{
pick(ea);
}
return false;
default:
return false;
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
if (viewer) pick(viewer,ea);
return false;
}
default:
return false;
}
}
void PickHandler::pick(const osgGA::GUIEventAdapter& ea)
void PickHandler::pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea)
{
osgUtil::IntersectVisitor::HitList hlist;
osgUtil::LineSegmentIntersector::Intersections intersections;
std::string gdlist="";
if (_viewer->computeIntersections(ea.getX(),ea.getY(),hlist))
if (viewer->computeIntersections(ea.getX(),ea.getY(),intersections))
{
for(osgUtil::IntersectVisitor::HitList::iterator hitr=hlist.begin();
hitr!=hlist.end();
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
hitr != intersections.end();
++hitr)
{
std::ostringstream os;
if (hitr->_geode.valid() && !hitr->_geode->getName().empty())
if (!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty()))
{
// the geodes are identified by name.
os<<"Object \""<<hitr->_geode->getName()<<"\""<<std::endl;
os<<"Object \""<<hitr->nodePath.back()->getName()<<"\""<<std::endl;
}
else if (hitr->_drawable.valid())
else if (hitr->drawable.valid())
{
os<<"Object \""<<hitr->_drawable->className()<<"\""<<std::endl;
os<<"Object \""<<hitr->drawable->className()<<"\""<<std::endl;
}
os<<" local coords vertex("<< hitr->getLocalIntersectPoint()<<")"<<" normal("<<hitr->getLocalIntersectNormal()<<")"<<std::endl;
os<<" world coords vertex("<< hitr->getWorldIntersectPoint()<<")"<<" normal("<<hitr->getWorldIntersectNormal()<<")"<<std::endl;
osgUtil::Hit::VecIndexList& vil = hitr->_vecIndexList;
const osgUtil::LineSegmentIntersector::Intersection::IndexList& vil = hitr->indexList;
for(unsigned int i=0;i<vil.size();++i)
{
os<<" vertex indices ["<<i<<"] = "<<vil[i]<<std::endl;
@@ -208,39 +206,10 @@ int main( int argc, char **argv )
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);
// set up the usage document, in case we need to print out how to use this program.
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates how to do Head Up Displays.");
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [filename] ...");
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
// construct the viewer.
osgProducer::Viewer viewer(arguments);
osgViewer::Viewer viewer;
// set up the value with sensible default event handlers.
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
// get details on keyboard and mouse bindings used by the viewer.
viewer.getUsage(*arguments.getApplicationUsage());
// if user request help write it out to cout.
if (arguments.read("-h") || arguments.read("--help"))
{
arguments.getApplicationUsage()->write(std::cout);
return 1;
}
// any option left unread are converted into errors to write out later.
arguments.reportRemainingOptionsAsUnrecognized();
// report any errors if they have occured when parsing the program aguments.
if (arguments.errors())
{
arguments.writeErrorMessages(std::cout);
return 1;
}
// read the scene from the list of file specified commandline args.
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
@@ -257,36 +226,10 @@ int main( int argc, char **argv )
group->addChild(createHUD(updateText.get()));
// add the handler for doing the picking
viewer.getEventHandlerList().push_front(new PickHandler(&viewer,updateText.get()));
viewer.addEventHandler(new PickHandler(updateText.get()));
// set the scene to render
viewer.setSceneData(group.get());
// create the windows and run the threads.
viewer.realize();
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();
}
// wait for all cull and draw threads to complete.
viewer.sync();
// run a clean up frame to delete all OpenGL objects.
viewer.cleanup_frame();
// wait for all the clean up frame to complete.
viewer.sync();
return 0;
return viewer.run();
}