Replaced deprecated osg::Geometry::set*Binding() usage.
This commit is contained in:
@@ -49,29 +49,29 @@
|
||||
|
||||
osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime)
|
||||
{
|
||||
// set up the animation path
|
||||
// set up the animation path
|
||||
osg::AnimationPath* animationPath = new osg::AnimationPath;
|
||||
animationPath->setLoopMode(osg::AnimationPath::LOOP);
|
||||
|
||||
|
||||
int numSamples = 40;
|
||||
float yaw = 0.0f;
|
||||
float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f);
|
||||
float roll = osg::inDegrees(30.0f);
|
||||
|
||||
|
||||
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)));
|
||||
|
||||
|
||||
animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
|
||||
|
||||
yaw += yaw_delta;
|
||||
time += time_delta;
|
||||
|
||||
}
|
||||
return animationPath;
|
||||
return animationPath;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class IntersectionUpdateCallback : public osg::NodeCallback
|
||||
osg::notify(osg::NOTICE)<<"IntersectionUpdateCallback not set up correctly."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//traverse(node,nv);
|
||||
frameCount_++;
|
||||
if (frameCount_ > 200)
|
||||
@@ -101,13 +101,13 @@ class IntersectionUpdateCallback : public osg::NodeCallback
|
||||
osg::notify(osg::NOTICE)<<"IntersectionUpdateCallback: warning cannot interestect with multiple terrain instances, just uses first one."<<std::endl;
|
||||
terrainLocalToWorld = terrain_worldMatrices.front();
|
||||
}
|
||||
|
||||
|
||||
// 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());
|
||||
|
||||
|
||||
// now we can compute the terrain to ss transform
|
||||
osg::Matrixd possie = terrainLocalToWorld*ssWorldToLocal;
|
||||
|
||||
|
||||
osgSim::SphereSegment::LineList lines = ss_->computeIntersection(possie, terrain_.get());
|
||||
if (!lines.empty())
|
||||
{
|
||||
@@ -118,7 +118,7 @@ class IntersectionUpdateCallback : public osg::NodeCallback
|
||||
osg::MatrixTransform* mt = new osg::MatrixTransform;
|
||||
mt->setMatrix(osg::computeLocalToWorld(nv->getNodePath()));
|
||||
intersectionGroup_->addChild(mt);
|
||||
|
||||
|
||||
// std::cout<<"matrix = "<<mt->getMatrix()<<std::endl;
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
@@ -144,7 +144,7 @@ class IntersectionUpdateCallback : public osg::NodeCallback
|
||||
osg::notify(osg::NOTICE)<<"No intersections found"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
frameCount_ = 0;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public:
|
||||
if (ss)
|
||||
{
|
||||
ss->setArea(osg::Vec3(cos(i/(2*osg::PI)),sin(i/(2*osg::PI)),0), osg::PI_2, osg::PI_2);
|
||||
|
||||
|
||||
i += 0.1f;
|
||||
}
|
||||
|
||||
@@ -194,16 +194,16 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode *
|
||||
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));
|
||||
|
||||
|
||||
positioned->addChild(glider);
|
||||
|
||||
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform;
|
||||
|
||||
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform;
|
||||
xform->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
||||
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0,1.0));
|
||||
xform->addChild(positioned);
|
||||
model->addChild(xform);
|
||||
}
|
||||
|
||||
|
||||
if (createMovingRadar)
|
||||
{
|
||||
// The IntersectionUpdateCallback has to have a safe place to put all its generated geometry into,
|
||||
@@ -211,10 +211,10 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode *
|
||||
// traversal iterators.
|
||||
osg::Group* intersectionGroup = new osg::Group;
|
||||
root->addChild(intersectionGroup);
|
||||
|
||||
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform;
|
||||
|
||||
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform;
|
||||
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0,1.0));
|
||||
|
||||
|
||||
osgSim::SphereSegment * ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0),
|
||||
700.0f, // radius
|
||||
osg::DegreesToRadians(135.0f),
|
||||
@@ -222,7 +222,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode *
|
||||
osg::DegreesToRadians(-60.0f),
|
||||
osg::DegreesToRadians(-40.0f),
|
||||
60);
|
||||
|
||||
|
||||
IntersectionUpdateCallback * iuc = new IntersectionUpdateCallback;
|
||||
iuc->frameCount_ = 0;
|
||||
iuc->root_ = root;
|
||||
@@ -235,7 +235,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode *
|
||||
xform->addChild(ss);
|
||||
model->addChild(xform);
|
||||
}
|
||||
|
||||
|
||||
osg::Node* cessna = osgDB::readNodeFile("cessna.osgt");
|
||||
if (cessna)
|
||||
{
|
||||
@@ -250,10 +250,10 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode *
|
||||
text->setAxisAlignment(osgText::Text::SCREEN);
|
||||
text->setCharacterSize(40.0f);
|
||||
text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS);
|
||||
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(text);
|
||||
|
||||
|
||||
osg::LOD* lod = new osg::LOD;
|
||||
lod->setRangeMode(osg::LOD::PIXEL_SIZE_ON_SCREEN);
|
||||
lod->setRadius(cessna->getBound().radius());
|
||||
@@ -267,28 +267,28 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode *
|
||||
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));
|
||||
|
||||
|
||||
//positioned->addChild(cessna);
|
||||
positioned->addChild(lod);
|
||||
|
||||
|
||||
osg::MatrixTransform* xform = new osg::MatrixTransform;
|
||||
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0));
|
||||
xform->addChild(positioned);
|
||||
|
||||
|
||||
model->addChild(xform);
|
||||
}
|
||||
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
osg::Group* createOverlay(const osg::Vec3& center, float radius)
|
||||
{
|
||||
osg::Group* group = new osg::Group;
|
||||
|
||||
|
||||
// create a grid of lines.
|
||||
{
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
|
||||
|
||||
unsigned int num_rows = 10;
|
||||
|
||||
osg::Vec3 left = center+osg::Vec3(-radius,-radius,0.0f);
|
||||
@@ -312,23 +312,22 @@ osg::Group* createOverlay(const osg::Vec3& center, float radius)
|
||||
top += delta_column;
|
||||
bottom += delta_column;
|
||||
}
|
||||
|
||||
|
||||
geom->setVertexArray(vertices);
|
||||
|
||||
osg::Vec4ubArray& color = *(new osg::Vec4ubArray(1));
|
||||
color[0].set(0,0,0,255);
|
||||
geom->setColorArray(&color);
|
||||
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
|
||||
geom->setColorArray(&color, osg::Array::BIND_OVERALL);
|
||||
|
||||
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINES,0,vertices->getNumElements()));
|
||||
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINES,0,vertices->getNumElements()));
|
||||
|
||||
geom->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(geom);
|
||||
group->addChild(geode);
|
||||
group->addChild(geode);
|
||||
}
|
||||
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
@@ -337,8 +336,8 @@ 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();
|
||||
|
||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
|
||||
|
||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
|
||||
new osgUtil::LineSegmentIntersector(osg::Vec3(x,y,zMin),osg::Vec3(x,y,zMax));
|
||||
|
||||
osgUtil::IntersectionVisitor iv(intersector.get());
|
||||
@@ -377,12 +376,12 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
|
||||
terrainGeode->setStateSet( stateset );
|
||||
|
||||
|
||||
|
||||
{
|
||||
unsigned int numColumns = 38;
|
||||
unsigned int numRows = 39;
|
||||
unsigned int r, c;
|
||||
|
||||
|
||||
osg::Vec3 origin(0.0f,0.0f,0.0f);
|
||||
osg::Vec3 size(1000.0f,1000.0f,250.0f);
|
||||
|
||||
@@ -435,8 +434,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
|
||||
geometry->setVertexArray(&v);
|
||||
geometry->setTexCoordArray(0, &tc);
|
||||
geometry->setColorArray(&color);
|
||||
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
|
||||
geometry->setColorArray(&color, osg::Array::BIND_OVERALL);
|
||||
|
||||
for(r=0;r<numRows-1;++r)
|
||||
{
|
||||
@@ -449,14 +447,14 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
drawElements[ei++] = (r)*numColumns+c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
osgUtil::SmoothingVisitor smoother;
|
||||
smoother.smooth(*geometry);
|
||||
|
||||
|
||||
terrainGeode->addDrawable(geometry);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// create sphere segment
|
||||
@@ -467,7 +465,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
|
||||
switch(testCase)
|
||||
{
|
||||
case(0):
|
||||
case(0):
|
||||
ss = new osgSim::SphereSegment(
|
||||
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
||||
510.0f, // radius
|
||||
@@ -478,7 +476,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
60);
|
||||
root->addChild(ss.get());
|
||||
break;
|
||||
case(1):
|
||||
case(1):
|
||||
ss = new osgSim::SphereSegment(
|
||||
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
||||
510.0f, // radius
|
||||
@@ -489,7 +487,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
60);
|
||||
root->addChild(ss.get());
|
||||
break;
|
||||
case(2):
|
||||
case(2):
|
||||
ss = new osgSim::SphereSegment(
|
||||
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
||||
510.0f, // radius
|
||||
@@ -500,7 +498,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
60);
|
||||
root->addChild(ss.get());
|
||||
break;
|
||||
case(3):
|
||||
case(3):
|
||||
ss = new osgSim::SphereSegment(
|
||||
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
||||
510.0f, // radius
|
||||
@@ -511,7 +509,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
60);
|
||||
root->addChild(ss.get());
|
||||
break;
|
||||
case(4):
|
||||
case(4):
|
||||
{
|
||||
ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0),
|
||||
700.0f, // radius
|
||||
@@ -520,21 +518,21 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
osg::DegreesToRadians(-60.0f),
|
||||
osg::DegreesToRadians(-40.0f),
|
||||
60);
|
||||
|
||||
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
||||
|
||||
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());
|
||||
|
||||
|
||||
terrainToSS.invert(mt->getMatrix());
|
||||
|
||||
|
||||
root->addChild(mt.get());
|
||||
break;
|
||||
}
|
||||
case(5):
|
||||
case(5):
|
||||
{
|
||||
ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0),
|
||||
700.0f, // radius
|
||||
@@ -543,21 +541,21 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
osg::DegreesToRadians(-60.0f),
|
||||
osg::DegreesToRadians(-40.0f),
|
||||
60);
|
||||
|
||||
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
||||
|
||||
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());
|
||||
|
||||
|
||||
terrainToSS.invert(mt->getMatrix());
|
||||
|
||||
|
||||
root->addChild(mt.get());
|
||||
break;
|
||||
}
|
||||
case(6):
|
||||
case(6):
|
||||
{
|
||||
ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0),
|
||||
700.0f, // radius
|
||||
@@ -566,21 +564,21 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
osg::DegreesToRadians(-60.0f),
|
||||
osg::DegreesToRadians(-40.0f),
|
||||
60);
|
||||
|
||||
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
||||
|
||||
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());
|
||||
|
||||
|
||||
terrainToSS.invert(mt->getMatrix());
|
||||
|
||||
|
||||
root->addChild(mt.get());
|
||||
break;
|
||||
}
|
||||
case(7):
|
||||
case(7):
|
||||
{
|
||||
ss = new osgSim::SphereSegment(
|
||||
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
|
||||
@@ -595,7 +593,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (ss.valid())
|
||||
{
|
||||
ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,0.5f));
|
||||
@@ -605,10 +603,10 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
{
|
||||
ss->getParent(0)->addChild(ss->computeIntersectionSubgraph(terrainToSS, terrainGeode.get()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (useOverlay)
|
||||
{
|
||||
@@ -629,9 +627,9 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
{
|
||||
root->addChild(terrainGeode.get());
|
||||
}
|
||||
|
||||
|
||||
// create particle effects
|
||||
{
|
||||
{
|
||||
osg::Vec3 position = computeTerrainIntersection(terrainGeode.get(),100.0f,100.0f);
|
||||
|
||||
osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect(position, 10.0f);
|
||||
@@ -642,9 +640,9 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
root->addChild(smoke);
|
||||
root->addChild(fire);
|
||||
}
|
||||
|
||||
|
||||
// create particle effects
|
||||
{
|
||||
{
|
||||
osg::Vec3 position = computeTerrainIntersection(terrainGeode.get(),200.0f,100.0f);
|
||||
|
||||
osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect(position, 1.0f);
|
||||
@@ -655,10 +653,10 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi
|
||||
root->addChild(smoke);
|
||||
root->addChild(fire);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool createMovingRadar = true;
|
||||
|
||||
|
||||
// create the moving models.
|
||||
{
|
||||
root->addChild(createMovingModel(osg::Vec3(500.0f,500.0f,500.0f),100.0f, terrainGeode.get(), root, createMovingRadar));
|
||||
@@ -675,12 +673,12 @@ 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 use of particle systems.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
|
||||
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
@@ -694,7 +692,7 @@ int main(int argc, char **argv)
|
||||
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; }
|
||||
|
||||
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
@@ -712,12 +710,12 @@ int main(int argc, char **argv)
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
osg::Group *root = new osg::Group;
|
||||
build_world(root, testCase, useOverlay, technique);
|
||||
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData(root);
|
||||
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user