2007-06-12 22:20:16 +08:00
|
|
|
/* OpenSceneGraph example, osgpick.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2003-04-13 21:26:41 +08:00
|
|
|
*/
|
2007-06-12 22:20:16 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
/* osgpick sample
|
|
|
|
* demonstrate use of osgUtil/PickVisitor for picking in a HUD or
|
|
|
|
* in a 3d scene,
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osgUtil/Optimizer>
|
|
|
|
#include <osgDB/ReadFile>
|
2007-01-10 21:52:22 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2008-03-04 22:19:03 +08:00
|
|
|
#include <osgViewer/CompositeViewer>
|
2003-04-13 21:26:41 +08:00
|
|
|
|
2008-07-10 03:28:00 +08:00
|
|
|
#include <osgGA/TerrainManipulator>
|
|
|
|
#include <osgGA/StateSetManipulator>
|
|
|
|
#include <osgGA/AnimationPathManipulator>
|
|
|
|
#include <osgGA/TrackballManipulator>
|
|
|
|
#include <osgGA/FlightManipulator>
|
|
|
|
#include <osgGA/DriveManipulator>
|
|
|
|
#include <osgGA/KeySwitchMatrixManipulator>
|
|
|
|
#include <osgGA/StateSetManipulator>
|
|
|
|
#include <osgGA/AnimationPathManipulator>
|
|
|
|
#include <osgGA/TerrainManipulator>
|
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
#include <osg/Material>
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/BlendFunc>
|
|
|
|
#include <osg/Depth>
|
|
|
|
#include <osg/Projection>
|
|
|
|
#include <osg/MatrixTransform>
|
2006-11-27 22:52:07 +08:00
|
|
|
#include <osg/Camera>
|
2005-04-08 17:51:56 +08:00
|
|
|
#include <osg/io_utils>
|
2008-10-28 00:16:28 +08:00
|
|
|
#include <osg/ShapeDrawable>
|
2003-04-13 21:26:41 +08:00
|
|
|
|
|
|
|
#include <osgText/Text>
|
|
|
|
|
2003-04-25 21:47:33 +08:00
|
|
|
#include <sstream>
|
2003-04-16 04:54:10 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
// class to handle events with a pick
|
|
|
|
class PickHandler : public osgGA::GUIEventHandler {
|
2013-06-27 17:54:12 +08:00
|
|
|
public:
|
2003-04-13 21:26:41 +08:00
|
|
|
|
2007-01-10 21:52:22 +08:00
|
|
|
PickHandler(osgText::Text* updateText):
|
2003-04-13 21:26:41 +08:00
|
|
|
_updateText(updateText) {}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
~PickHandler() {}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-01-10 21:52:22 +08:00
|
|
|
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
|
2003-04-13 21:26:41 +08:00
|
|
|
|
2008-03-04 22:19:03 +08:00
|
|
|
virtual void pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea);
|
2003-04-13 21:26:41 +08:00
|
|
|
|
|
|
|
void setLabel(const std::string& name)
|
|
|
|
{
|
|
|
|
if (_updateText.get()) _updateText->setText(name);
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
osg::ref_ptr<osgText::Text> _updateText;
|
|
|
|
};
|
|
|
|
|
2007-01-10 21:52:22 +08:00
|
|
|
bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
|
2003-04-13 21:26:41 +08:00
|
|
|
{
|
|
|
|
switch(ea.getEventType())
|
|
|
|
{
|
2008-03-04 22:19:03 +08:00
|
|
|
case(osgGA::GUIEventAdapter::PUSH):
|
2003-04-13 21:26:41 +08:00
|
|
|
{
|
2008-03-04 22:19:03 +08:00
|
|
|
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
|
|
|
|
if (view) pick(view,ea);
|
2007-01-10 21:52:22 +08:00
|
|
|
return false;
|
2013-06-27 17:54:12 +08:00
|
|
|
}
|
2008-07-10 03:28:00 +08:00
|
|
|
case(osgGA::GUIEventAdapter::KEYDOWN):
|
|
|
|
{
|
|
|
|
if (ea.getKey()=='c')
|
2013-06-27 17:54:12 +08:00
|
|
|
{
|
2008-07-10 03:28:00 +08:00
|
|
|
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
|
|
|
|
osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter(ea);
|
|
|
|
event->setX((ea.getXmin()+ea.getXmax())*0.5);
|
|
|
|
event->setY((ea.getYmin()+ea.getYmax())*0.5);
|
|
|
|
if (view) pick(view,*event);
|
|
|
|
}
|
|
|
|
return false;
|
2013-06-27 17:54:12 +08:00
|
|
|
}
|
2007-01-10 21:52:22 +08:00
|
|
|
default:
|
|
|
|
return false;
|
2003-04-13 21:26:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-04 22:19:03 +08:00
|
|
|
void PickHandler::pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea)
|
2003-04-13 21:26:41 +08:00
|
|
|
{
|
2007-01-10 21:52:22 +08:00
|
|
|
osgUtil::LineSegmentIntersector::Intersections intersections;
|
|
|
|
|
Added convinence methods to osgProducer::Viewer:
/** compute, from normalized mouse coords, for sepecified Camera, the pixel coords relative to that Camera's RenderSurface.*/
bool computePixelCoords(float x,float y,unsigned int cameraNum,float& pixel_x,float& pixel_y);
/** compute, from normalized mouse coords, for sepecified Camera, the near and far points in worlds coords.*/
bool computeNearFar(float x,float y,unsigned int cameraNum,osg::Vec3& near, osg::Vec3& far);
/** compute, from normalized mouse coords, for sepecified Camera, intersections with the scene.*/
bool computeIntersections(float x,float y,unsigned int cameraNum,osgUtil::IntersectVisitor::HitList& hits);
/** compute, from normalized mouse coords, for all Cameras, intersections with the scene.*/
bool computeIntersections(float x,float y,osgUtil::IntersectVisitor::HitList& hits);
2003-04-16 22:17:49 +08:00
|
|
|
std::string gdlist="";
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2013-05-04 03:26:27 +08:00
|
|
|
if (view->computeIntersections(ea,intersections))
|
2003-04-13 21:26:41 +08:00
|
|
|
{
|
2007-01-10 21:52:22 +08:00
|
|
|
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
|
|
|
|
hitr != intersections.end();
|
Added convinence methods to osgProducer::Viewer:
/** compute, from normalized mouse coords, for sepecified Camera, the pixel coords relative to that Camera's RenderSurface.*/
bool computePixelCoords(float x,float y,unsigned int cameraNum,float& pixel_x,float& pixel_y);
/** compute, from normalized mouse coords, for sepecified Camera, the near and far points in worlds coords.*/
bool computeNearFar(float x,float y,unsigned int cameraNum,osg::Vec3& near, osg::Vec3& far);
/** compute, from normalized mouse coords, for sepecified Camera, intersections with the scene.*/
bool computeIntersections(float x,float y,unsigned int cameraNum,osgUtil::IntersectVisitor::HitList& hits);
/** compute, from normalized mouse coords, for all Cameras, intersections with the scene.*/
bool computeIntersections(float x,float y,osgUtil::IntersectVisitor::HitList& hits);
2003-04-16 22:17:49 +08:00
|
|
|
++hitr)
|
2003-04-13 21:26:41 +08:00
|
|
|
{
|
2003-04-25 21:47:33 +08:00
|
|
|
std::ostringstream os;
|
2007-01-10 21:52:22 +08:00
|
|
|
if (!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty()))
|
2003-04-13 21:26:41 +08:00
|
|
|
{
|
2003-04-25 21:47:33 +08:00
|
|
|
// the geodes are identified by name.
|
2007-01-10 21:52:22 +08:00
|
|
|
os<<"Object \""<<hitr->nodePath.back()->getName()<<"\""<<std::endl;
|
2003-04-25 21:47:33 +08:00
|
|
|
}
|
2007-01-10 21:52:22 +08:00
|
|
|
else if (hitr->drawable.valid())
|
2003-04-25 21:47:33 +08:00
|
|
|
{
|
2007-01-10 21:52:22 +08:00
|
|
|
os<<"Object \""<<hitr->drawable->className()<<"\""<<std::endl;
|
2003-04-25 21:47:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
os<<" local coords vertex("<< hitr->getLocalIntersectPoint()<<")"<<" normal("<<hitr->getLocalIntersectNormal()<<")"<<std::endl;
|
|
|
|
os<<" world coords vertex("<< hitr->getWorldIntersectPoint()<<")"<<" normal("<<hitr->getWorldIntersectNormal()<<")"<<std::endl;
|
2007-01-10 21:52:22 +08:00
|
|
|
const osgUtil::LineSegmentIntersector::Intersection::IndexList& vil = hitr->indexList;
|
2003-04-25 21:47:33 +08:00
|
|
|
for(unsigned int i=0;i<vil.size();++i)
|
|
|
|
{
|
|
|
|
os<<" vertex indices ["<<i<<"] = "<<vil[i]<<std::endl;
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-25 21:47:33 +08:00
|
|
|
gdlist += os.str();
|
2003-04-13 21:26:41 +08:00
|
|
|
}
|
|
|
|
}
|
Added convinence methods to osgProducer::Viewer:
/** compute, from normalized mouse coords, for sepecified Camera, the pixel coords relative to that Camera's RenderSurface.*/
bool computePixelCoords(float x,float y,unsigned int cameraNum,float& pixel_x,float& pixel_y);
/** compute, from normalized mouse coords, for sepecified Camera, the near and far points in worlds coords.*/
bool computeNearFar(float x,float y,unsigned int cameraNum,osg::Vec3& near, osg::Vec3& far);
/** compute, from normalized mouse coords, for sepecified Camera, intersections with the scene.*/
bool computeIntersections(float x,float y,unsigned int cameraNum,osgUtil::IntersectVisitor::HitList& hits);
/** compute, from normalized mouse coords, for all Cameras, intersections with the scene.*/
bool computeIntersections(float x,float y,osgUtil::IntersectVisitor::HitList& hits);
2003-04-16 22:17:49 +08:00
|
|
|
setLabel(gdlist);
|
2003-04-13 21:26:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node* createHUD(osgText::Text* updateText)
|
2005-11-02 23:23:54 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
// create the hud. derived from osgHud.cpp
|
2003-04-13 21:26:41 +08:00
|
|
|
// adds a set of quads, each in a separate Geode - which can be picked individually
|
|
|
|
// eg to be used as a menuing/help system!
|
|
|
|
// Can pick texts too!
|
2005-11-02 23:23:54 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::Camera* hudCamera = new osg::Camera;
|
2005-11-02 23:23:54 +08:00
|
|
|
hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
|
|
|
hudCamera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
|
|
|
|
hudCamera->setViewMatrix(osg::Matrix::identity());
|
2006-11-27 22:52:07 +08:00
|
|
|
hudCamera->setRenderOrder(osg::Camera::POST_RENDER);
|
2005-11-02 23:23:54 +08:00
|
|
|
hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
std::string timesFont("fonts/times.ttf");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
// turn lighting off for the text and disable depth test to ensure its always ontop.
|
|
|
|
osg::Vec3 position(150.0f,800.0f,0.0f);
|
|
|
|
osg::Vec3 delta(0.0f,-60.0f,0.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
{
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
|
|
|
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
|
|
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
|
|
|
|
geode->setName("simple");
|
2005-11-02 23:23:54 +08:00
|
|
|
hudCamera->addChild(geode);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
geode->addDrawable( text );
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
text->setFont(timesFont);
|
2005-12-16 22:53:51 +08:00
|
|
|
text->setText("Picking in Head Up Displays is simple!");
|
2003-04-13 21:26:41 +08:00
|
|
|
text->setPosition(position);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
position += delta;
|
2013-06-27 17:54:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
for (int i=0; i<5; i++) {
|
|
|
|
osg::Vec3 dy(0.0f,-30.0f,0.0f);
|
|
|
|
osg::Vec3 dx(120.0f,0.0f,0.0f);
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
|
|
|
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
|
|
|
const char *opts[]={"One", "Two", "Three", "January", "Feb", "2003"};
|
|
|
|
osg::Geometry *quad=new osg::Geometry;
|
|
|
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
|
|
|
|
std::string name="subOption";
|
|
|
|
name += " ";
|
|
|
|
name += std::string(opts[i]);
|
|
|
|
geode->setName(name);
|
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array(4); // 1 quad
|
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array;
|
|
|
|
colors = new osg::Vec4Array;
|
|
|
|
colors->push_back(osg::Vec4(0.8-0.1*i,0.1*i,0.2*i, 1.0));
|
2013-06-27 17:54:12 +08:00
|
|
|
quad->setColorArray(colors, osg::Array::BIND_OVERALL);
|
2003-04-13 21:26:41 +08:00
|
|
|
(*vertices)[0]=position;
|
|
|
|
(*vertices)[1]=position+dx;
|
|
|
|
(*vertices)[2]=position+dx+dy;
|
|
|
|
(*vertices)[3]=position+dy;
|
|
|
|
quad->setVertexArray(vertices);
|
|
|
|
quad->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
|
|
|
|
geode->addDrawable(quad);
|
2005-11-02 23:23:54 +08:00
|
|
|
hudCamera->addChild(geode);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
position += delta;
|
2013-06-27 17:54:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
{ // this displays what has been selected
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
|
|
|
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
|
|
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
|
2003-04-25 21:47:33 +08:00
|
|
|
geode->setName("The text label");
|
2003-04-13 21:26:41 +08:00
|
|
|
geode->addDrawable( updateText );
|
2005-11-02 23:23:54 +08:00
|
|
|
hudCamera->addChild(geode);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-25 21:47:33 +08:00
|
|
|
updateText->setCharacterSize(20.0f);
|
2003-04-13 21:26:41 +08:00
|
|
|
updateText->setFont(timesFont);
|
2003-04-25 21:47:33 +08:00
|
|
|
updateText->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
|
|
|
|
updateText->setText("");
|
2003-04-13 21:26:41 +08:00
|
|
|
updateText->setPosition(position);
|
2007-02-14 20:42:10 +08:00
|
|
|
updateText->setDataVariance(osg::Object::DYNAMIC);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-04-13 21:26:41 +08:00
|
|
|
position += delta;
|
2013-06-27 17:54:12 +08:00
|
|
|
}
|
|
|
|
|
2005-11-02 23:23:54 +08:00
|
|
|
return hudCamera;
|
2003-04-13 21:26:41 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
// use an ArgumentParser object to manage the program arguments.
|
|
|
|
osg::ArgumentParser arguments(&argc,argv);
|
|
|
|
|
|
|
|
// read the scene from the list of file specified commandline args.
|
2015-10-22 22:14:53 +08:00
|
|
|
osg::ref_ptr<osg::Node> scene = osgDB::readRefNodeFiles(arguments);
|
2008-10-28 00:16:28 +08:00
|
|
|
|
2008-10-28 03:59:05 +08:00
|
|
|
if (!scene && arguments.read("--relative-camera-scene"))
|
2008-10-28 00:16:28 +08:00
|
|
|
{
|
2008-10-28 03:59:05 +08:00
|
|
|
// Create a test scene with a camera that has a relative reference frame.
|
2008-10-28 00:16:28 +08:00
|
|
|
osg::Group* group = new osg::Group();
|
|
|
|
|
|
|
|
osg::Geode* sphere = new osg::Geode();
|
|
|
|
sphere->setName("Sphere");
|
|
|
|
sphere->addDrawable(new osg::ShapeDrawable(new osg::Sphere()));
|
|
|
|
|
|
|
|
osg::Geode* cube = new osg::Geode();
|
|
|
|
cube->setName("Cube");
|
|
|
|
cube->addDrawable(new osg::ShapeDrawable(new osg::Box()));
|
|
|
|
|
|
|
|
osg::Camera* camera = new osg::Camera();
|
|
|
|
camera->setRenderOrder(osg::Camera::POST_RENDER);
|
|
|
|
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
|
2008-10-28 03:59:05 +08:00
|
|
|
camera->setReferenceFrame(osg::Transform::RELATIVE_RF);
|
2008-11-06 21:36:25 +08:00
|
|
|
camera->setViewMatrix(osg::Matrix::translate(-2, 0, 0));
|
|
|
|
|
|
|
|
osg::MatrixTransform* xform = new osg::MatrixTransform(osg::Matrix::translate(1, 1, 1));
|
|
|
|
xform->addChild(camera);
|
2008-10-28 00:16:28 +08:00
|
|
|
|
|
|
|
group->addChild(sphere);
|
2008-11-06 21:36:25 +08:00
|
|
|
group->addChild(xform);
|
2008-10-28 00:16:28 +08:00
|
|
|
camera->addChild(cube);
|
|
|
|
|
|
|
|
scene = group;
|
|
|
|
}
|
|
|
|
|
2007-06-08 23:37:20 +08:00
|
|
|
// if not loaded assume no arguments passed in, try use default mode instead.
|
2015-10-22 22:14:53 +08:00
|
|
|
if (!scene) scene = osgDB::readRefNodeFile("fountain.osgt");
|
2003-04-13 21:26:41 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::Group> group = dynamic_cast<osg::Group*>(scene.get());
|
|
|
|
if (!group)
|
|
|
|
{
|
|
|
|
group = new osg::Group;
|
|
|
|
group->addChild(scene.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<osgText::Text> updateText = new osgText::Text;
|
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
// add the HUD subgraph.
|
2003-04-13 21:26:41 +08:00
|
|
|
group->addChild(createHUD(updateText.get()));
|
|
|
|
|
2008-03-04 22:19:03 +08:00
|
|
|
if (arguments.read("--CompositeViewer"))
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osgViewer::View> view = new osgViewer::View;
|
|
|
|
// add the handler for doing the picking
|
|
|
|
view->addEventHandler(new PickHandler(updateText.get()));
|
|
|
|
|
|
|
|
// set the scene to render
|
|
|
|
view->setSceneData(group.get());
|
|
|
|
|
|
|
|
view->setUpViewAcrossAllScreens();
|
|
|
|
|
|
|
|
osgViewer::CompositeViewer viewer;
|
|
|
|
viewer.addView(view.get());
|
|
|
|
|
|
|
|
return viewer.run();
|
2003-04-13 21:26:41 +08:00
|
|
|
|
2008-03-04 22:19:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osgViewer::Viewer viewer;
|
|
|
|
|
2008-07-10 03:28:00 +08:00
|
|
|
|
|
|
|
// add all the camera manipulators
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
|
|
|
|
|
|
|
|
keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
|
|
|
|
keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
|
|
|
|
keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
|
|
|
|
|
|
|
|
unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
|
|
|
|
keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
|
|
|
|
|
|
|
|
std::string pathfile;
|
|
|
|
char keyForAnimationPath = '5';
|
|
|
|
while (arguments.read("-p",pathfile))
|
|
|
|
{
|
|
|
|
osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
|
2013-06-27 17:54:12 +08:00
|
|
|
if (apm || !apm->valid())
|
2008-07-10 03:28:00 +08:00
|
|
|
{
|
|
|
|
num = keyswitchManipulator->getNumMatrixManipulators();
|
|
|
|
keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
|
|
|
|
++keyForAnimationPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
keyswitchManipulator->selectMatrixManipulator(num);
|
|
|
|
|
|
|
|
viewer.setCameraManipulator( keyswitchManipulator.get() );
|
|
|
|
}
|
|
|
|
|
2008-03-04 22:19:03 +08:00
|
|
|
// add the handler for doing the picking
|
|
|
|
viewer.addEventHandler(new PickHandler(updateText.get()));
|
|
|
|
|
|
|
|
// set the scene to render
|
|
|
|
viewer.setSceneData(group.get());
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2008-03-04 22:19:03 +08:00
|
|
|
return viewer.run();
|
|
|
|
}
|
2003-04-13 21:26:41 +08:00
|
|
|
|
|
|
|
}
|