Added test cases for SphereSegment intersection code.

This commit is contained in:
Robert Osfield 2005-10-01 19:28:34 +00:00
parent e2f2960704
commit c401e31bd8

View File

@ -224,7 +224,7 @@ osg::Vec3 computeTerrainIntersection(osg::Node* subgraph,float x,float y)
// MAIN SCENE GRAPH BUILDING FUNCTION // MAIN SCENE GRAPH BUILDING FUNCTION
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
void build_world(osg::Group *root) void build_world(osg::Group *root, unsigned int testCase)
{ {
// create terrain // create terrain
@ -328,20 +328,61 @@ void build_world(osg::Group *root)
// create sphere segment // create sphere segment
osg::ref_ptr<osgSim::SphereSegment> ss = 0; osg::ref_ptr<osgSim::SphereSegment> ss = 0;
{ {
ss = new osgSim::SphereSegment(
computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center switch(testCase)
500.0f, // radius {
osg::DegreesToRadians(135.0f), case(0):
osg::DegreesToRadians(245.0f), ss = new osgSim::SphereSegment(
osg::DegreesToRadians(-10.0f), computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center
osg::DegreesToRadians(30.0f), 510.0f, // radius
60); osg::DegreesToRadians(135.0f),
osg::DegreesToRadians(240.0f),
osg::DegreesToRadians(-10.0f),
osg::DegreesToRadians(30.0f),
60);
break;
case(1):
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);
break;
case(2):
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);
break;
case(3):
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);
break;
};
ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,0.5f));
ss->setSideColor(osg::Vec4(0.0f,1.0f,1.0f,0.1f)); ss->setSideColor(osg::Vec4(0.0f,1.0f,1.0f,0.1f));
#if 1
root->addChild(ss.get()); root->addChild(ss.get());
#endif
} }
#if 1
root->addChild(ss->computeIntersectionSubgraph(osg::Matrixd::identity(), terrainGeode.get()));
#else
osgSim::SphereSegment::LineList lines = ss->computeIntersection(osg::Matrixd::identity(), terrainGeode.get()); osgSim::SphereSegment::LineList lines = ss->computeIntersection(osg::Matrixd::identity(), terrainGeode.get());
if (!lines.empty()) if (!lines.empty())
{ {
@ -368,8 +409,9 @@ void build_world(osg::Group *root)
{ {
osg::notify(osg::NOTICE)<<"No intersections found"<<std::endl; osg::notify(osg::NOTICE)<<"No intersections found"<<std::endl;
} }
#endif
#if 1 #if 0
osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode; osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode;
@ -385,9 +427,8 @@ void build_world(osg::Group *root)
root->addChild(overlayNode); root->addChild(overlayNode);
#else #else
root->addChild(terrainGeode); root->addChild(terrainGeode.get());
#endif #endif
@ -449,6 +490,11 @@ int main(int argc, char **argv)
// get details on keyboard and mouse bindings used by the viewer. // get details on keyboard and mouse bindings used by the viewer.
viewer.getUsage(*arguments.getApplicationUsage()); viewer.getUsage(*arguments.getApplicationUsage());
// if user request help write it out to cout.
unsigned int testCase = 0;
if (arguments.read("-t", testCase)) {}
// if user request help write it out to cout. // if user request help write it out to cout.
if (arguments.read("-h") || arguments.read("--help")) if (arguments.read("-h") || arguments.read("--help"))
{ {
@ -467,7 +513,7 @@ int main(int argc, char **argv)
} }
osg::Group *root = new osg::Group; osg::Group *root = new osg::Group;
build_world(root); build_world(root, testCase);
// add a viewport to the viewer and attach the scene graph. // add a viewport to the viewer and attach the scene graph.
viewer.setSceneData(root); viewer.setSceneData(root);