2007-06-12 22:20:16 +08:00
|
|
|
/* OpenSceneGraph example, osgspheresegment.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-01-11 19:47:01 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2016-08-25 03:09:52 +08:00
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2005-03-22 20:11:03 +08:00
|
|
|
|
|
|
|
#include <osg/Group>
|
2003-09-01 17:36:03 +08:00
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/ShapeDrawable>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <osg/PositionAttitudeTransform>
|
2005-03-22 20:11:03 +08:00
|
|
|
#include <osg/MatrixTransform>
|
2005-09-07 04:28:53 +08:00
|
|
|
#include <osg/Geometry>
|
2003-09-01 17:36:03 +08:00
|
|
|
|
2005-09-09 19:13:40 +08:00
|
|
|
#include <osgUtil/SmoothingVisitor>
|
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
#include <osgDB/ReadFile>
|
2003-09-01 17:36:03 +08:00
|
|
|
|
|
|
|
#include <osgText/Text>
|
|
|
|
|
|
|
|
#include <osgSim/SphereSegment>
|
2005-09-06 23:48:18 +08:00
|
|
|
#include <osgSim/OverlayNode>
|
2003-09-01 17:36:03 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
#include <osgParticle/ExplosionEffect>
|
|
|
|
#include <osgParticle/SmokeEffect>
|
|
|
|
#include <osgParticle/FireEffect>
|
|
|
|
#include <osgParticle/ParticleSystemUpdater>
|
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
#include <osg/io_utils>
|
|
|
|
|
2007-01-11 19:47:01 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
// for the grid data..
|
|
|
|
#include "../osghangglide/terrain_coords.h"
|
2003-09-01 17:36:03 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime)
|
2003-09-01 17:36:03 +08:00
|
|
|
{
|
2013-06-27 17:54:12 +08:00
|
|
|
// set up the animation path
|
2005-03-22 20:11:03 +08:00
|
|
|
osg::AnimationPath* animationPath = new osg::AnimationPath;
|
|
|
|
animationPath->setLoopMode(osg::AnimationPath::LOOP);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
int numSamples = 40;
|
|
|
|
float yaw = 0.0f;
|
|
|
|
float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f);
|
|
|
|
float roll = osg::inDegrees(30.0f);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
double time=0.0f;
|
|
|
|
double time_delta = looptime/(double)numSamples;
|
|
|
|
for(int i=0;i<numSamples;++i)
|
|
|
|
{
|
|
|
|
osg::Vec3 position(center+osg::Vec3(sinf(yaw)*radius,cosf(yaw)*radius,0.0f));
|
|
|
|
osg::Quat rotation(osg::Quat(roll,osg::Vec3(0.0,1.0,0.0))*osg::Quat(-(yaw+osg::inDegrees(90.0f)),osg::Vec3(0.0,0.0,1.0)));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
|
|
|
|
|
|
|
|
yaw += yaw_delta;
|
|
|
|
time += time_delta;
|
|
|
|
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
return animationPath;
|
2005-03-22 20:11:03 +08:00
|
|
|
}
|
|
|
|
|
2006-03-15 20:26:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
class IntersectionUpdateCallback : public osg::NodeCallback
|
|
|
|
{
|
|
|
|
virtual void operator()(osg::Node* /*node*/, osg::NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
if (!root_ || !terrain_ || !ss_ || !intersectionGroup_)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"IntersectionUpdateCallback not set up correctly."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-03-15 20:26:10 +08:00
|
|
|
//traverse(node,nv);
|
|
|
|
frameCount_++;
|
|
|
|
if (frameCount_ > 200)
|
|
|
|
{
|
|
|
|
// first we need find the transformation matrix that takes
|
|
|
|
// the terrain into the coordinate frame of the sphere segment.
|
|
|
|
osg::Matrixd terrainLocalToWorld;
|
|
|
|
osg::MatrixList terrain_worldMatrices = terrain_->getWorldMatrices(root_.get());
|
|
|
|
if (terrain_worldMatrices.empty()) terrainLocalToWorld.makeIdentity();
|
|
|
|
else if (terrain_worldMatrices.size()==1) terrainLocalToWorld = terrain_worldMatrices.front();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"IntersectionUpdateCallback: warning cannot interestect with multiple terrain instances, just uses first one."<<std::endl;
|
|
|
|
terrainLocalToWorld = terrain_worldMatrices.front();
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-03-15 20:26:10 +08:00
|
|
|
// sphere segment is easier as this callback is attached to the node, so the node visitor has the unique path to it already.
|
|
|
|
osg::Matrixd ssWorldToLocal = osg::computeWorldToLocal(nv->getNodePath());
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-03-15 20:26:10 +08:00
|
|
|
// now we can compute the terrain to ss transform
|
|
|
|
osg::Matrixd possie = terrainLocalToWorld*ssWorldToLocal;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-03-15 20:26:10 +08:00
|
|
|
osgSim::SphereSegment::LineList lines = ss_->computeIntersection(possie, terrain_.get());
|
|
|
|
if (!lines.empty())
|
|
|
|
{
|
|
|
|
if (intersectionGroup_.valid())
|
|
|
|
{
|
|
|
|
// now we need to place the intersections which are in the SphereSegmenet's coordinate frame into
|
|
|
|
// to the final position.
|
|
|
|
osg::MatrixTransform* mt = new osg::MatrixTransform;
|
|
|
|
mt->setMatrix(osg::computeLocalToWorld(nv->getNodePath()));
|
|
|
|
intersectionGroup_->addChild(mt);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
// std::cout<<"matrix = "<<mt->getMatrix()<<std::endl;
|
2006-03-15 20:26:10 +08:00
|
|
|
|
|
|
|
osg::Geode* geode = new osg::Geode;
|
|
|
|
mt->addChild(geode);
|
|
|
|
|
|
|
|
geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
|
|
|
for(osgSim::SphereSegment::LineList::iterator itr=lines.begin();
|
|
|
|
itr!=lines.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
osg::Geometry* geom = new osg::Geometry;
|
|
|
|
geode->addDrawable(geom);
|
|
|
|
|
|
|
|
osg::Vec3Array* vertices = itr->get();
|
|
|
|
geom->setVertexArray(vertices);
|
|
|
|
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, vertices->getNumElements()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"No intersections found"<<std::endl;
|
|
|
|
}
|
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-03-15 20:26:10 +08:00
|
|
|
frameCount_ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
osg::observer_ptr<osg::Group> root_;
|
|
|
|
osg::observer_ptr<osg::Geode> terrain_;
|
|
|
|
osg::observer_ptr<osgSim::SphereSegment> ss_;
|
|
|
|
osg::observer_ptr<osg::Group> intersectionGroup_;
|
|
|
|
unsigned frameCount_;
|
|
|
|
};
|
|
|
|
|
2010-06-15 00:30:43 +08:00
|
|
|
class RotateUpdateCallback : public osg::NodeCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RotateUpdateCallback() { i=0;}
|
2016-06-08 19:09:00 +08:00
|
|
|
virtual void operator()(osg::Node* node, osg::NodeVisitor* /*nv*/)
|
2010-06-15 00:30:43 +08:00
|
|
|
{
|
|
|
|
osgSim::SphereSegment * ss = dynamic_cast<osgSim::SphereSegment *>(node);
|
|
|
|
if (ss)
|
|
|
|
{
|
|
|
|
ss->setArea(osg::Vec3(cos(i/(2*osg::PI)),sin(i/(2*osg::PI)),0), osg::PI_2, osg::PI_2);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2010-06-15 00:30:43 +08:00
|
|
|
i += 0.1f;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
float i;
|
|
|
|
};
|
2006-03-15 20:26:10 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * terrainGeode, osg::Group * root, bool createMovingRadar = false)
|
2003-09-01 17:36:03 +08:00
|
|
|
{
|
2005-03-22 20:11:03 +08:00
|
|
|
float animationLength = 10.0f;
|
|
|
|
|
|
|
|
osg::AnimationPath* animationPath = createAnimationPath(center,radius,animationLength);
|
|
|
|
|
|
|
|
osg::Group* model = new osg::Group;
|
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::Node> glider = osgDB::readRefNodeFile("glider.osgt");
|
2005-03-22 20:11:03 +08:00
|
|
|
if (glider)
|
|
|
|
{
|
|
|
|
const osg::BoundingSphere& bs = glider->getBound();
|
|
|
|
|
|
|
|
float size = radius/bs.radius()*0.3f;
|
|
|
|
osg::MatrixTransform* positioned = new osg::MatrixTransform;
|
|
|
|
positioned->setDataVariance(osg::Object::STATIC);
|
|
|
|
positioned->setMatrix(osg::Matrix::translate(-bs.center())*
|
|
|
|
osg::Matrix::scale(size,size,size)*
|
|
|
|
osg::Matrix::rotate(osg::inDegrees(-90.0f),0.0f,0.0f,1.0f));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
positioned->addChild(glider);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform;
|
2005-03-22 20:11:03 +08:00
|
|
|
xform->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
|
|
|
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0,1.0));
|
|
|
|
xform->addChild(positioned);
|
2006-03-15 20:26:10 +08:00
|
|
|
model->addChild(xform);
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
if (createMovingRadar)
|
2006-03-15 20:26:10 +08:00
|
|
|
{
|
|
|
|
// The IntersectionUpdateCallback has to have a safe place to put all its generated geometry into,
|
|
|
|
// and this group can't be in the parental chain of the callback otherwise we will end up invalidating
|
|
|
|
// traversal iterators.
|
|
|
|
osg::Group* intersectionGroup = new osg::Group;
|
|
|
|
root->addChild(intersectionGroup);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform;
|
2006-03-15 20:26:10 +08:00
|
|
|
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0,1.0));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-03-15 20:26:10 +08:00
|
|
|
osgSim::SphereSegment * ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0),
|
|
|
|
700.0f, // radius
|
|
|
|
osg::DegreesToRadians(135.0f),
|
|
|
|
osg::DegreesToRadians(240.0f),
|
2006-06-06 00:25:01 +08:00
|
|
|
osg::DegreesToRadians(-60.0f),
|
|
|
|
osg::DegreesToRadians(-40.0f),
|
2006-03-15 20:26:10 +08:00
|
|
|
60);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-03-15 20:26:10 +08:00
|
|
|
IntersectionUpdateCallback * iuc = new IntersectionUpdateCallback;
|
|
|
|
iuc->frameCount_ = 0;
|
|
|
|
iuc->root_ = root;
|
|
|
|
iuc->terrain_ = terrainGeode;
|
|
|
|
iuc->ss_ = ss;
|
|
|
|
iuc->intersectionGroup_ = intersectionGroup;
|
|
|
|
ss->setUpdateCallback(iuc);
|
|
|
|
ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,0.5f));
|
|
|
|
ss->setSideColor(osg::Vec4(0.5f,1.0f,1.0f,0.1f));
|
|
|
|
xform->addChild(ss);
|
2005-03-22 20:11:03 +08:00
|
|
|
model->addChild(xform);
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::Node> cessna = osgDB::readRefNodeFile("cessna.osgt");
|
2005-03-22 20:11:03 +08:00
|
|
|
if (cessna)
|
2004-02-12 09:15:37 +08:00
|
|
|
{
|
2005-03-22 20:11:03 +08:00
|
|
|
const osg::BoundingSphere& bs = cessna->getBound();
|
|
|
|
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
float size = radius/bs.radius()*0.3f;
|
|
|
|
|
|
|
|
text->setPosition(bs.center());
|
|
|
|
text->setText("Cessna");
|
|
|
|
text->setAlignment(osgText::Text::CENTER_CENTER);
|
|
|
|
text->setAxisAlignment(osgText::Text::SCREEN);
|
|
|
|
text->setCharacterSize(40.0f);
|
2005-10-13 18:29:40 +08:00
|
|
|
text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
osg::Geode* geode = new osg::Geode;
|
|
|
|
geode->addDrawable(text);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
osg::LOD* lod = new osg::LOD;
|
|
|
|
lod->setRangeMode(osg::LOD::PIXEL_SIZE_ON_SCREEN);
|
2006-06-28 18:00:54 +08:00
|
|
|
lod->setRadius(cessna->getBound().radius());
|
2005-03-22 20:11:03 +08:00
|
|
|
lod->addChild(geode,0.0f,100.0f);
|
|
|
|
lod->addChild(cessna,100.0f,10000.0f);
|
|
|
|
|
2003-09-01 17:36:03 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
osg::MatrixTransform* positioned = new osg::MatrixTransform;
|
|
|
|
positioned->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
|
|
|
positioned->setDataVariance(osg::Object::STATIC);
|
|
|
|
positioned->setMatrix(osg::Matrix::translate(-bs.center())*
|
|
|
|
osg::Matrix::scale(size,size,size)*
|
|
|
|
osg::Matrix::rotate(osg::inDegrees(180.0f),0.0f,0.0f,1.0f));
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
//positioned->addChild(cessna);
|
|
|
|
positioned->addChild(lod);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
osg::MatrixTransform* xform = new osg::MatrixTransform;
|
|
|
|
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0));
|
|
|
|
xform->addChild(positioned);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
model->addChild(xform);
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2005-09-07 04:28:53 +08:00
|
|
|
osg::Group* createOverlay(const osg::Vec3& center, float radius)
|
|
|
|
{
|
|
|
|
osg::Group* group = new osg::Group;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-09-07 04:28:53 +08:00
|
|
|
// create a grid of lines.
|
|
|
|
{
|
|
|
|
osg::Geometry* geom = new osg::Geometry;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-09-07 04:28:53 +08:00
|
|
|
unsigned int num_rows = 10;
|
|
|
|
|
|
|
|
osg::Vec3 left = center+osg::Vec3(-radius,-radius,0.0f);
|
|
|
|
osg::Vec3 right = center+osg::Vec3(radius,-radius,0.0f);
|
|
|
|
osg::Vec3 delta_row = osg::Vec3(0.0f,2.0f*radius/float(num_rows-1),0.0f);
|
|
|
|
|
|
|
|
osg::Vec3 top = center+osg::Vec3(-radius,radius,0.0f);
|
|
|
|
osg::Vec3 bottom = center+osg::Vec3(-radius,-radius,0.0f);
|
|
|
|
osg::Vec3 delta_column = osg::Vec3(2.0f*radius/float(num_rows-1),0.0f,0.0f);
|
|
|
|
|
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array;
|
|
|
|
for(unsigned int i=0; i<num_rows; ++i)
|
|
|
|
{
|
|
|
|
vertices->push_back(left);
|
|
|
|
vertices->push_back(right);
|
|
|
|
left += delta_row;
|
|
|
|
right += delta_row;
|
|
|
|
|
|
|
|
vertices->push_back(top);
|
|
|
|
vertices->push_back(bottom);
|
|
|
|
top += delta_column;
|
|
|
|
bottom += delta_column;
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-09-07 04:28:53 +08:00
|
|
|
geom->setVertexArray(vertices);
|
2005-09-26 19:24:14 +08:00
|
|
|
|
|
|
|
osg::Vec4ubArray& color = *(new osg::Vec4ubArray(1));
|
|
|
|
color[0].set(0,0,0,255);
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->setColorArray(&color, osg::Array::BIND_OVERALL);
|
2005-09-26 19:24:14 +08:00
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINES,0,vertices->getNumElements()));
|
2005-09-07 04:28:53 +08:00
|
|
|
|
2005-09-26 19:24:14 +08:00
|
|
|
geom->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
2005-09-07 04:28:53 +08:00
|
|
|
osg::Geode* geode = new osg::Geode;
|
|
|
|
geode->addDrawable(geom);
|
2013-06-27 17:54:12 +08:00
|
|
|
group->addChild(geode);
|
2005-09-07 04:28:53 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-09-07 04:28:53 +08:00
|
|
|
return group;
|
|
|
|
}
|
2005-03-22 20:11:03 +08:00
|
|
|
|
|
|
|
osg::Vec3 computeTerrainIntersection(osg::Node* subgraph,float x,float y)
|
|
|
|
{
|
|
|
|
const osg::BoundingSphere& bs = subgraph->getBound();
|
|
|
|
float zMax = bs.center().z()+bs.radius();
|
|
|
|
float zMin = bs.center().z()-bs.radius();
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
|
2008-10-07 22:01:14 +08:00
|
|
|
new osgUtil::LineSegmentIntersector(osg::Vec3(x,y,zMin),osg::Vec3(x,y,zMax));
|
|
|
|
|
|
|
|
osgUtil::IntersectionVisitor iv(intersector.get());
|
2003-09-01 17:36:03 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
subgraph->accept(iv);
|
|
|
|
|
2008-10-07 22:01:14 +08:00
|
|
|
if (intersector->containsIntersections())
|
2005-03-22 20:11:03 +08:00
|
|
|
{
|
2008-10-07 22:01:14 +08:00
|
|
|
return intersector->getFirstIntersection().getWorldIntersectPoint();
|
2004-02-12 09:15:37 +08:00
|
|
|
}
|
2005-03-22 20:11:03 +08:00
|
|
|
|
|
|
|
return osg::Vec3(x,y,0.0f);
|
2003-09-01 17:36:03 +08:00
|
|
|
}
|
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
|
2016-08-25 17:25:49 +08:00
|
|
|
class AdjustSphereSegmentCallback : public osgGA::GUIEventHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void scaleSphereSegment(osgSim::SphereSegment* ss, float scale)
|
|
|
|
{
|
|
|
|
if (!ss) return;
|
|
|
|
|
|
|
|
|
|
|
|
osg::Vec3 direction_vec;
|
|
|
|
float azRange, elevRange;
|
|
|
|
ss->getArea(direction_vec, azRange, elevRange);
|
|
|
|
|
|
|
|
ss->setArea(direction_vec, azRange*scale, elevRange*scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& /*aa*/, osg::Object* object, osg::NodeVisitor* /*nv*/)
|
|
|
|
{
|
|
|
|
if (ea.getHandled()) return false;
|
|
|
|
|
|
|
|
switch(ea.getEventType())
|
|
|
|
{
|
|
|
|
case(osgGA::GUIEventAdapter::KEYDOWN):
|
|
|
|
{
|
|
|
|
if (ea.getKey()=='>')
|
|
|
|
{
|
|
|
|
scaleSphereSegment(dynamic_cast<osgSim::SphereSegment*>(object), 1.1f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ea.getKey()=='<')
|
|
|
|
{
|
|
|
|
scaleSphereSegment(dynamic_cast<osgSim::SphereSegment*>(object), 1.0f/1.1f);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// MAIN SCENE GRAPH BUILDING FUNCTION
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-05-28 23:44:37 +08:00
|
|
|
void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSim::OverlayNode::OverlayTechnique technique)
|
2003-09-01 17:36:03 +08:00
|
|
|
{
|
2005-03-22 20:11:03 +08:00
|
|
|
|
|
|
|
// create terrain
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::Geode> terrainGeode;
|
2005-03-22 20:11:03 +08:00
|
|
|
{
|
2005-09-06 23:48:18 +08:00
|
|
|
terrainGeode = new osg::Geode;
|
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();
|
|
|
|
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("Images/lz.rgb");
|
2005-03-22 20:11:03 +08:00
|
|
|
if (image)
|
|
|
|
{
|
2005-11-18 04:22:55 +08:00
|
|
|
osg::Texture2D* texture = new osg::Texture2D;
|
|
|
|
texture->setImage(image);
|
|
|
|
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
|
2005-03-22 20:11:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
terrainGeode->setStateSet( stateset );
|
|
|
|
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
{
|
2005-09-09 19:13:40 +08:00
|
|
|
unsigned int numColumns = 38;
|
|
|
|
unsigned int numRows = 39;
|
|
|
|
unsigned int r, c;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-09-09 19:13:40 +08:00
|
|
|
osg::Vec3 origin(0.0f,0.0f,0.0f);
|
|
|
|
osg::Vec3 size(1000.0f,1000.0f,250.0f);
|
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
|
2005-09-09 19:13:40 +08:00
|
|
|
|
|
|
|
osg::Vec3Array& v = *(new osg::Vec3Array(numColumns*numRows));
|
|
|
|
osg::Vec2Array& tc = *(new osg::Vec2Array(numColumns*numRows));
|
|
|
|
osg::Vec4ubArray& color = *(new osg::Vec4ubArray(1));
|
|
|
|
|
|
|
|
color[0].set(255,255,255,255);
|
|
|
|
|
|
|
|
float rowCoordDelta = size.y()/(float)(numRows-1);
|
|
|
|
float columnCoordDelta = size.x()/(float)(numColumns-1);
|
|
|
|
|
|
|
|
float rowTexDelta = 1.0f/(float)(numRows-1);
|
|
|
|
float columnTexDelta = 1.0f/(float)(numColumns-1);
|
|
|
|
|
|
|
|
// compute z range of z values of grid data so we can scale it.
|
|
|
|
float min_z = FLT_MAX;
|
|
|
|
float max_z = -FLT_MAX;
|
|
|
|
for(r=0;r<numRows;++r)
|
|
|
|
{
|
2005-11-18 04:22:55 +08:00
|
|
|
for(c=0;c<numColumns;++c)
|
|
|
|
{
|
|
|
|
min_z = osg::minimum(min_z,vertex[r+c*numRows][2]);
|
|
|
|
max_z = osg::maximum(max_z,vertex[r+c*numRows][2]);
|
|
|
|
}
|
2005-09-09 19:13:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float scale_z = size.z()/(max_z-min_z);
|
|
|
|
|
|
|
|
osg::Vec3 pos = origin;
|
|
|
|
osg::Vec2 tex(0.0f,0.0f);
|
|
|
|
int vi=0;
|
|
|
|
for(r=0;r<numRows;++r)
|
|
|
|
{
|
|
|
|
pos.x() = origin.x();
|
|
|
|
tex.x() = 0.0f;
|
2005-11-18 04:22:55 +08:00
|
|
|
for(c=0;c<numColumns;++c)
|
|
|
|
{
|
|
|
|
v[vi].set(pos.x(),pos.y(),pos.z()+(vertex[r+c*numRows][2]-min_z)*scale_z);
|
|
|
|
tc[vi] = tex;
|
2005-09-09 19:13:40 +08:00
|
|
|
pos.x()+=columnCoordDelta;
|
|
|
|
tex.x()+=columnTexDelta;
|
|
|
|
++vi;
|
2005-11-18 04:22:55 +08:00
|
|
|
}
|
2005-09-09 19:13:40 +08:00
|
|
|
pos.y() += rowCoordDelta;
|
|
|
|
tex.y() += rowTexDelta;
|
|
|
|
}
|
|
|
|
|
|
|
|
geometry->setVertexArray(&v);
|
|
|
|
geometry->setTexCoordArray(0, &tc);
|
2013-06-27 17:54:12 +08:00
|
|
|
geometry->setColorArray(&color, osg::Array::BIND_OVERALL);
|
2005-09-09 19:13:40 +08:00
|
|
|
|
|
|
|
for(r=0;r<numRows-1;++r)
|
|
|
|
{
|
|
|
|
osg::DrawElementsUShort& drawElements = *(new osg::DrawElementsUShort(GL_QUAD_STRIP,2*numColumns));
|
|
|
|
geometry->addPrimitiveSet(&drawElements);
|
|
|
|
int ei=0;
|
2005-11-18 04:22:55 +08:00
|
|
|
for(c=0;c<numColumns;++c)
|
|
|
|
{
|
|
|
|
drawElements[ei++] = (r+1)*numColumns+c;
|
|
|
|
drawElements[ei++] = (r)*numColumns+c;
|
|
|
|
}
|
2005-09-09 19:13:40 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-09-09 19:13:40 +08:00
|
|
|
osgUtil::SmoothingVisitor smoother;
|
|
|
|
smoother.smooth(*geometry);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-09-09 19:13:40 +08:00
|
|
|
terrainGeode->addDrawable(geometry);
|
2005-03-22 20:11:03 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
}
|
2005-03-22 20:11:03 +08:00
|
|
|
|
2005-09-06 23:48:18 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
// create sphere segment
|
2005-09-06 23:48:18 +08:00
|
|
|
osg::ref_ptr<osgSim::SphereSegment> ss = 0;
|
2005-03-22 20:11:03 +08:00
|
|
|
{
|
2005-10-02 03:28:34 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
osg::Matrix terrainToSS;
|
|
|
|
|
2005-10-02 03:28:34 +08:00
|
|
|
switch(testCase)
|
|
|
|
{
|
2013-06-27 17:54:12 +08:00
|
|
|
case(0):
|
2005-10-02 03:28:34 +08:00
|
|
|
ss = new osgSim::SphereSegment(
|
|
|
|
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
|
|
|
510.0f, // radius
|
|
|
|
osg::DegreesToRadians(135.0f),
|
|
|
|
osg::DegreesToRadians(240.0f),
|
|
|
|
osg::DegreesToRadians(-10.0f),
|
|
|
|
osg::DegreesToRadians(30.0f),
|
|
|
|
60);
|
2006-06-06 00:25:01 +08:00
|
|
|
root->addChild(ss.get());
|
2005-10-02 03:28:34 +08:00
|
|
|
break;
|
2013-06-27 17:54:12 +08:00
|
|
|
case(1):
|
2005-10-02 03:28:34 +08:00
|
|
|
ss = new osgSim::SphereSegment(
|
|
|
|
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
|
|
|
510.0f, // radius
|
|
|
|
osg::DegreesToRadians(45.0f),
|
|
|
|
osg::DegreesToRadians(240.0f),
|
|
|
|
osg::DegreesToRadians(-10.0f),
|
|
|
|
osg::DegreesToRadians(30.0f),
|
|
|
|
60);
|
2006-06-06 00:25:01 +08:00
|
|
|
root->addChild(ss.get());
|
2005-10-02 03:28:34 +08:00
|
|
|
break;
|
2013-06-27 17:54:12 +08:00
|
|
|
case(2):
|
2005-10-02 03:28:34 +08:00
|
|
|
ss = new osgSim::SphereSegment(
|
|
|
|
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
|
|
|
510.0f, // radius
|
|
|
|
osg::DegreesToRadians(5.0f),
|
|
|
|
osg::DegreesToRadians(355.0f),
|
|
|
|
osg::DegreesToRadians(-10.0f),
|
|
|
|
osg::DegreesToRadians(30.0f),
|
|
|
|
60);
|
2006-06-06 00:25:01 +08:00
|
|
|
root->addChild(ss.get());
|
2005-10-02 03:28:34 +08:00
|
|
|
break;
|
2013-06-27 17:54:12 +08:00
|
|
|
case(3):
|
2005-10-02 03:28:34 +08:00
|
|
|
ss = new osgSim::SphereSegment(
|
|
|
|
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
|
|
|
510.0f, // radius
|
|
|
|
osg::DegreesToRadians(0.0f),
|
|
|
|
osg::DegreesToRadians(360.0f),
|
|
|
|
osg::DegreesToRadians(-10.0f),
|
|
|
|
osg::DegreesToRadians(30.0f),
|
|
|
|
60);
|
2006-06-06 00:25:01 +08:00
|
|
|
root->addChild(ss.get());
|
|
|
|
break;
|
2013-06-27 17:54:12 +08:00
|
|
|
case(4):
|
2006-06-06 00:25:01 +08:00
|
|
|
{
|
|
|
|
ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0),
|
|
|
|
700.0f, // radius
|
|
|
|
osg::DegreesToRadians(135.0f),
|
|
|
|
osg::DegreesToRadians(240.0f),
|
|
|
|
osg::DegreesToRadians(-60.0f),
|
|
|
|
osg::DegreesToRadians(-40.0f),
|
|
|
|
60);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
mt->setMatrix(osg::Matrix(-0.851781, 0.156428, -0.5, 0,
|
|
|
|
-0.180627, -0.983552, -6.93889e-18, 0,
|
|
|
|
-0.491776, 0.0903136, 0.866025, 0,
|
|
|
|
598.217, 481.957, 100, 1));
|
|
|
|
mt->addChild(ss.get());
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
terrainToSS.invert(mt->getMatrix());
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
root->addChild(mt.get());
|
|
|
|
break;
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
case(5):
|
2006-06-06 00:25:01 +08:00
|
|
|
{
|
|
|
|
ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0),
|
|
|
|
700.0f, // radius
|
|
|
|
osg::DegreesToRadians(35.0f),
|
|
|
|
osg::DegreesToRadians(135.0f),
|
|
|
|
osg::DegreesToRadians(-60.0f),
|
|
|
|
osg::DegreesToRadians(-40.0f),
|
|
|
|
60);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
mt->setMatrix(osg::Matrix(-0.851781, 0.156428, -0.5, 0,
|
|
|
|
-0.180627, -0.983552, -6.93889e-18, 0,
|
|
|
|
-0.491776, 0.0903136, 0.866025, 0,
|
|
|
|
598.217, 481.957, 100, 1));
|
|
|
|
mt->addChild(ss.get());
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
terrainToSS.invert(mt->getMatrix());
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
root->addChild(mt.get());
|
|
|
|
break;
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
case(6):
|
2006-06-06 00:25:01 +08:00
|
|
|
{
|
|
|
|
ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0),
|
|
|
|
700.0f, // radius
|
|
|
|
osg::DegreesToRadians(-45.0f),
|
|
|
|
osg::DegreesToRadians(45.0f),
|
|
|
|
osg::DegreesToRadians(-60.0f),
|
|
|
|
osg::DegreesToRadians(-40.0f),
|
|
|
|
60);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
mt->setMatrix(osg::Matrix(-0.851781, 0.156428, -0.5, 0,
|
|
|
|
-0.180627, -0.983552, -6.93889e-18, 0,
|
|
|
|
-0.491776, 0.0903136, 0.866025, 0,
|
|
|
|
598.217, 481.957, 100, 1));
|
|
|
|
mt->addChild(ss.get());
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
terrainToSS.invert(mt->getMatrix());
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
root->addChild(mt.get());
|
2005-10-02 03:28:34 +08:00
|
|
|
break;
|
2006-06-06 00:25:01 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
case(7):
|
2010-06-15 00:30:43 +08:00
|
|
|
{
|
|
|
|
ss = new osgSim::SphereSegment(
|
|
|
|
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
|
|
|
510.0f, // radius
|
|
|
|
osg::DegreesToRadians(-240.0f),
|
|
|
|
osg::DegreesToRadians(-135.0f),
|
|
|
|
osg::DegreesToRadians(-10.0f),
|
|
|
|
osg::DegreesToRadians(30.0f),
|
|
|
|
60);
|
|
|
|
ss->setUpdateCallback(new RotateUpdateCallback());
|
|
|
|
root->addChild(ss.get());
|
|
|
|
break;
|
|
|
|
}
|
2005-10-02 03:28:34 +08:00
|
|
|
};
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
if (ss.valid())
|
2005-09-16 04:03:37 +08:00
|
|
|
{
|
2006-06-06 00:25:01 +08:00
|
|
|
ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,0.5f));
|
|
|
|
ss->setSideColor(osg::Vec4(0.0f,1.0f,1.0f,0.1f));
|
|
|
|
|
|
|
|
if (!ss->getParents().empty())
|
|
|
|
{
|
|
|
|
ss->getParent(0)->addChild(ss->computeIntersectionSubgraph(terrainToSS, terrainGeode.get()));
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2016-08-25 17:25:49 +08:00
|
|
|
ss->setEventCallback(new AdjustSphereSegmentCallback);
|
|
|
|
|
2005-09-16 04:03:37 +08:00
|
|
|
}
|
2005-09-08 21:10:04 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-09-06 23:48:18 +08:00
|
|
|
|
2007-05-28 23:44:37 +08:00
|
|
|
if (useOverlay)
|
|
|
|
{
|
|
|
|
osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode(technique);
|
|
|
|
overlayNode->getOrCreateStateSet()->setTextureAttribute(1, new osg::TexEnv(osg::TexEnv::DECAL));
|
|
|
|
|
|
|
|
const osg::BoundingSphere& bs = terrainGeode->getBound();
|
|
|
|
osg::Group* overlaySubgraph = createOverlay(bs.center(), bs.radius()*0.5f);
|
|
|
|
overlaySubgraph->addChild(ss.get());
|
|
|
|
overlayNode->setOverlaySubgraph(overlaySubgraph);
|
|
|
|
overlayNode->setOverlayTextureSizeHint(1024);
|
|
|
|
overlayNode->setOverlayBaseHeight(0.0);
|
|
|
|
overlayNode->addChild(terrainGeode.get());
|
|
|
|
|
|
|
|
root->addChild(overlayNode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root->addChild(terrainGeode.get());
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
// create particle effects
|
2013-06-27 17:54:12 +08:00
|
|
|
{
|
2005-09-06 23:48:18 +08:00
|
|
|
osg::Vec3 position = computeTerrainIntersection(terrainGeode.get(),100.0f,100.0f);
|
2005-03-22 20:11:03 +08:00
|
|
|
|
2005-03-24 01:05:21 +08:00
|
|
|
osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect(position, 10.0f);
|
|
|
|
osgParticle::SmokeEffect* smoke = new osgParticle::SmokeEffect(position, 10.0f);
|
|
|
|
osgParticle::FireEffect* fire = new osgParticle::FireEffect(position, 10.0f);
|
2005-03-22 20:11:03 +08:00
|
|
|
|
2005-03-24 01:05:21 +08:00
|
|
|
root->addChild(explosion);
|
|
|
|
root->addChild(smoke);
|
|
|
|
root->addChild(fire);
|
2005-03-22 20:11:03 +08:00
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-24 01:05:21 +08:00
|
|
|
// create particle effects
|
2013-06-27 17:54:12 +08:00
|
|
|
{
|
2005-09-06 23:48:18 +08:00
|
|
|
osg::Vec3 position = computeTerrainIntersection(terrainGeode.get(),200.0f,100.0f);
|
2005-03-24 01:05:21 +08:00
|
|
|
|
|
|
|
osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect(position, 1.0f);
|
|
|
|
osgParticle::SmokeEffect* smoke = new osgParticle::SmokeEffect(position, 1.0f);
|
|
|
|
osgParticle::FireEffect* fire = new osgParticle::FireEffect(position, 1.0f);
|
|
|
|
|
|
|
|
root->addChild(explosion);
|
|
|
|
root->addChild(smoke);
|
|
|
|
root->addChild(fire);
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
|
|
|
|
2006-06-06 00:25:01 +08:00
|
|
|
bool createMovingRadar = true;
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
// create the moving models.
|
|
|
|
{
|
2006-06-06 00:25:01 +08:00
|
|
|
root->addChild(createMovingModel(osg::Vec3(500.0f,500.0f,500.0f),100.0f, terrainGeode.get(), root, createMovingRadar));
|
2005-03-22 20:11:03 +08:00
|
|
|
}
|
2003-09-01 17:36:03 +08:00
|
|
|
}
|
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// main()
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
2003-09-01 17:36:03 +08:00
|
|
|
{
|
|
|
|
// use an ArgumentParser object to manage the program arguments.
|
|
|
|
osg::ArgumentParser arguments(&argc,argv);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-09-01 17:36:03 +08:00
|
|
|
// set up the usage document, in case we need to print out how to use this program.
|
2005-03-22 20:11:03 +08:00
|
|
|
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of particle systems.");
|
|
|
|
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye");
|
2003-09-01 17:36:03 +08:00
|
|
|
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2003-09-01 17:36:03 +08:00
|
|
|
|
|
|
|
// construct the viewer.
|
2007-06-23 19:21:54 +08:00
|
|
|
osgViewer::Viewer viewer(arguments);
|
2003-09-01 17:36:03 +08:00
|
|
|
|
2005-10-02 03:28:34 +08:00
|
|
|
// if user request help write it out to cout.
|
|
|
|
unsigned int testCase = 0;
|
2007-05-28 23:44:37 +08:00
|
|
|
while (arguments.read("-t", testCase)) {}
|
2005-10-02 03:28:34 +08:00
|
|
|
|
2007-05-28 23:44:37 +08:00
|
|
|
bool useOverlay = false;
|
2007-05-28 01:29:29 +08:00
|
|
|
osgSim::OverlayNode::OverlayTechnique technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY;
|
2007-05-28 23:44:37 +08:00
|
|
|
while (arguments.read("--object")) { useOverlay = true; technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; }
|
|
|
|
while (arguments.read("--ortho") || arguments.read("--orthographic")) { useOverlay = true; technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; }
|
|
|
|
while (arguments.read("--persp") || arguments.read("--perspective")) { useOverlay = true; technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY; }
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-10-02 03:28:34 +08:00
|
|
|
|
2003-09-01 17:36:03 +08:00
|
|
|
// 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();
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
// report any errors if they have occurred when parsing the program arguments.
|
2003-09-01 17:36:03 +08:00
|
|
|
if (arguments.errors())
|
|
|
|
{
|
|
|
|
arguments.writeErrorMessages(std::cout);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
osg::Group *root = new osg::Group;
|
2007-05-28 23:44:37 +08:00
|
|
|
build_world(root, testCase, useOverlay, technique);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2016-08-25 03:09:52 +08:00
|
|
|
|
|
|
|
viewer.addEventHandler(new osgViewer::StatsHandler);
|
|
|
|
|
2005-03-22 20:11:03 +08:00
|
|
|
// add a viewport to the viewer and attach the scene graph.
|
|
|
|
viewer.setSceneData(root);
|
2013-06-27 17:54:12 +08:00
|
|
|
|
2007-01-11 19:47:01 +08:00
|
|
|
return viewer.run();
|
2003-09-01 17:36:03 +08:00
|
|
|
}
|