本文整理汇总了C++中osg::NodePtr::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ NodePtr::addChild方法的具体用法?C++ NodePtr::addChild怎么用?C++ NodePtr::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::NodePtr
的用法示例。
在下文中一共展示了NodePtr::addChild方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setActive
void testObj::setActive( osg::NodePtr parent, bool active )
{
if ( _isActive && ! active )
{
osg::addRefCP( node );
parent->subChild( node );
}
else if ( ! _isActive && active )
parent->addChild( node );
_isActive = active;
}
示例2: traverseGraph
//.........这里部分代码省略.........
SoNormalBinding* _Binding = ( SoNormalBinding* ) OIVNode;
mCurrentState.NormalBinding = _Binding->value.getValue();
// Return the old OSG node as the current OSG node
return OSGNode;
}
///////////////
// Normal node
///////////////
if( OIVNode->isOfType( SoNormal::getClassTypeId() ) )
{
// Save current normals
mCurrentState.Normals = convertNormals( ( SoNormal* ) OIVNode );
// Return the old OSG node as the current OSG node
return OSGNode;
}
///////////////////////
// Transformation node
///////////////////////
if( OIVNode->isOfType( SoTransform::getClassTypeId() ) )
{
osg::NodePtr _OSGTransform = convertTransformation( OIVNode );
// Add the transformation to the current OSG node
beginEditCP ( OSGNode, Node::ChildrenFieldMask );
{
OSGNode->addChild( _OSGTransform );
}
endEditCP ( OSGNode, Node::ChildrenFieldMask );
// Return the new transform node as the current OSG node
return _OSGTransform;
}
///////////////////////
// MatrixTransformation node
///////////////////////
if( OIVNode->isOfType( SoMatrixTransform::getClassTypeId() ) )
{
osg::NodePtr _OSGTransform = convertMatrixTransformation( OIVNode );
// Add the transformation to the current OSG node
beginEditCP ( OSGNode, Node::ChildrenFieldMask );
{
OSGNode->addChild( _OSGTransform );
}
endEditCP ( OSGNode, Node::ChildrenFieldMask );
// Return the new transform node as the current OSG node
return _OSGTransform;
}
////////////////////
// Indexed face set
////////////////////
if( OIVNode->isOfType( SoIndexedFaceSet::getClassTypeId() ) )
示例3: main
//.........这里部分代码省略.........
reader = vtkXMLImageDataReader::New();
vtkSmartPointer<vtkImageDataGeometryFilter> geoFilter =
vtkSmartPointer<vtkImageDataGeometryFilter>::New();
geoFilter->SetInputConnection(reader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
if (fileExt.find("vtr") != string::npos)
{
reader = vtkXMLRectilinearGridReader::New();
vtkSmartPointer<vtkGeometryFilter> geoFilter =
vtkSmartPointer<vtkGeometryFilter>::New();
geoFilter->SetInputConnection(reader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
else if (fileExt.find("vts") != string::npos)
{
reader = vtkXMLStructuredGridReader::New();
vtkSmartPointer<vtkGeometryFilter> geoFilter =
vtkSmartPointer<vtkGeometryFilter>::New();
geoFilter->SetInputConnection(reader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
else if (fileExt.find("vtp") != string::npos)
{
reader = vtkXMLPolyDataReader::New();
mapper->SetInputConnection(reader->GetOutputPort());
}
else if (fileExt.find("vtu") != string::npos)
{
reader = vtkXMLUnstructuredGridReader::New();
vtkSmartPointer<vtkGeometryFilter> geoFilter =
vtkSmartPointer<vtkGeometryFilter>::New();
geoFilter->SetInputConnection(reader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
else if (fileExt.find("vtk") != string::npos)
{
oldStyleReader = vtkGenericDataObjectReader::New();
oldStyleReader->SetFileName(filename.c_str());
oldStyleReader->Update();
if(oldStyleReader->IsFilePolyData())
mapper->SetInputConnection(oldStyleReader->GetOutputPort());
else
{
vtkSmartPointer<vtkGeometryFilter> geoFilter =
vtkSmartPointer<vtkGeometryFilter>::New();
geoFilter->SetInputConnection(oldStyleReader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
}
else
{
cout << "Not a valid vtk file ending (vti, vtr, vts, vtp, vtu, vtk)" <<
endl;
return 1;
}
if (fileExt.find("vtk") == string::npos)
{
reader->SetFileName(filename.c_str());
reader->Update();
}
vtkActor* actor = vtkActor::New();
actor->SetMapper(mapper);
vtkOsgConverter converter(actor);
converter.SetVerbose(true);
//converter->SetMapper(mapper);
converter.WriteAnActor();
OSG::NodePtr node = converter.GetOsgNode();
replaceExt(filename, "osb");
if (useSwitch)
{
beginEditCP(switchNode);
switchNode->addChild(node);
endEditCP(switchNode);
}
else
OSG::SceneFileHandler::the().write(node, filename.c_str());
if (reader)
reader->Delete();
if (oldStyleReader)
oldStyleReader->Delete();
}
if (useSwitch)
{
string filename(filenames[0]);
replaceExt(filename, "osb");
OSG::SceneFileHandler::the().write(switchNode, filename.c_str());
}
//mapper->Delete(); // TODO crashes
OSG::osgExit();
cout << "File conversion finished" << endl;
return 0;
}
示例4: testRefCount
void testRefCount(void)
{
#if 0
OSG::NodePtr pNode = OSG::Node::create();
OSG::NodePtr pNode1 = OSG::Node::create();
fprintf(stderr, "1\n");
//XX
#if 0
pNode.dump();
pNode1.dump();
#endif
pNode->addChild(pNode1);
fprintf(stderr, "2\n");
//XX
#if 0
pNode.dump();
pNode1.dump();
#endif
fprintf(stderr, "3\n");
//XX
#if 0
pNode.dump();
pNode1.dump();
#endif
applyToAspect(1, false);
applyToAspect(2);
fprintf(stderr, "4\n");
//XX
#if 0
pNode.dump();
pNode1.dump();
#endif
fprintf(stderr, "5\n");
//XX
#if 0
pNode.dump();
pNode1.dump();
#endif
applyToAspect(1, false);
fprintf(stderr, "6\n");
//XX
#if 0
pNode.dump();
pNode1.dump();
#endif
applyToAspect(2);
fprintf(stderr, "7\n");
#endif
}
示例5: main
int main( int argc, char *argv[] )
{
// parse command line options
parsecommandline( argc, argv );
// OSG init
osg::osgLog().setLogLevel(osg::LOG_WARNING);
osg::osgInit(argc, argv);
// disable display lists
osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype();
osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto);
if ( pGeoProto != osg::NullFC )
pGeoProto->setDlistCache(false);
// create the graph
osg::NodePtr node;
// root
root = osg::Node::create();
beginEditCP(root);
root->setCore( osg::Group::create() );
// beacon for camera and light
osg::NodePtr beacon;
beacon = osg::Node::create();
beginEditCP(beacon);
beacon->setCore( osg::Group::create() );
endEditCP(beacon);
// light
light_node = osg::Node::create();
osg::DirectionalLightPtr light = osg::DirectionalLight::create();
beginEditCP( light_node );
light_node->setCore( light );
endEditCP( light_node );
root->addChild( light_node );
beginEditCP(light);
light->setAmbient( .3, .3, .3, 1 );
light->setDiffuse( 1, 1, 1, 1 );
light->setDirection(0,0,1);
light->setBeacon( beacon );
endEditCP(light);
// transformation, parent of beacon
node = osg::Node::create();
cam_trans = osg::Transform::create();
beginEditCP(node);
node->setCore( cam_trans );
node->addChild( beacon );
endEditCP(node);
root->addChild( node );
// finish scene graph
endEditCP(root);
// Camera
osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create();
cam->setBeacon( beacon );
cam->setFov( 50 );
cam->setNear( 0.1 );
cam->setFar( 10000 );
// Background
osg::SolidBackgroundPtr background = osg::SolidBackground::create();
// Viewport
osg::ViewportPtr vp = osg::Viewport::create();
vp->setCamera( cam );
vp->setBackground( background );
vp->setRoot( root );
vp->setSize( 0,0, 1,1 );
if ( with_window )
{
// GLUT init
glutInitWindowSize( 400, 400 ); // before glutInit so user can
glutInitWindowPosition( 100, 100 ); // override with comannd line args
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("Polygon Intersection Check Test");
glutKeyboardFunc(key);
glutVisibilityFunc(vis);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIdleFunc(display);
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
// Window
osg::GLUTWindowPtr gwin;
GLint glvp[4];
glGetIntegerv( GL_VIEWPORT, glvp );
gwin = osg::GLUTWindow::create();
//.........这里部分代码省略.........
示例6: createChildVisualEntity
void SimulationEngine::createChildVisualEntity(osg::NodePtr parentNode,
/*osg::TransformPtr trans,*/ const opal::ShapeData* data, const std::string& name,
const std::string& materialName)
{
// Create an Ogre SceneNode for the Entity.
osg::Matrix m;
opal::Point3r offsetPos = data->offset.getPosition();
//Ogre::Vector3 translationOffset(offsetPos[0], offsetPos[1],
//offsetPos[2]);
opal::Quaternion offsetQuat = data->offset.getQuaternion();
//Ogre::Quaternion rotationOffset;
//rotationOffset.x = offsetQuat.x;
//rotationOffset.y = offsetQuat.y;
//rotationOffset.z = offsetQuat.z;
//rotationOffset.w = offsetQuat.w;
//Ogre::SceneNode* newChildNode = NULL;
//Ogre::Entity* e = NULL;
// OSG covention: we need one new node and transformation
osg::NodePtr newChildNode; //= osg::Node::create();
osg::TransformPtr newTransCore = osg::Transform::create();
osg::beginEditCP(newTransCore);
m.setIdentity();
m.setTranslate(
(osg::Real32)offsetPos[0],
(osg::Real32)offsetPos[1],
(osg::Real32)offsetPos[2]);
m.setRotate(
osg::Quaternion(
osg::Vec3f(
(osg::Real32)offsetQuat[1],
(osg::Real32)offsetQuat[2],
(osg::Real32)offsetQuat[3]),
(osg::Real32)offsetQuat[0]));
newTransCore->setMatrix(m);
osg::endEditCP(newTransCore);
switch(data->getType())
{
case opal::BOX_SHAPE:
{
//newChildNode = parentNode->createChildSceneNode(name,
//translationOffset, rotationOffset);
// Scale the object according to the given dimensions.
opal::Vec3r boxDim = static_cast<const opal::BoxShapeData*>
(data)->dimensions;
//Ogre::Vector3 dimensions(boxDim[0], boxDim[1], boxDim[2]);
//newChildNode->scale(dimensions[0], dimensions[1],
//dimensions[2]);
//create the geometry which we will assign a texture to
newChildNode = osg::makeBox((osg::Real32)boxDim[0],
(osg::Real32)boxDim[1],
(osg::Real32)boxDim[2],1,1,1);
// Create an Ogre Entity using a cube mesh. This mesh must be
// stored as a box with dimensions 1x1x1.
//e = mOgreSceneMgr->createEntity(name, "cube.mesh");
//e->setMaterialName(materialName);
// Keep the normals normalized even after scaling.
//e->setNormaliseNormals(true);
// Attach the Entity to the SceneNode.
//newChildNode->attachObject(e);
//osg::beginEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
osg::beginEditCP(parentNode);
parentNode->setCore(newTransCore);
parentNode->addChild(newChildNode);
osg::endEditCP(parentNode);
//osg::endEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
break;
}
case opal::SPHERE_SHAPE:
{
//newChildNode = parentNode->createChildSceneNode(name,
//translationOffset, rotationOffset);
// Scale the object according to the given dimensions.
//Ogre::Real radius = static_cast<const opal::SphereShapeData*>
//(data)->radius;
//newChildNode->scale(radius, radius, radius);
opal::real radius = static_cast<const opal::SphereShapeData*>
(data)->radius;
newChildNode = osg::makeSphere(3, (osg::Real32)radius);
// Create an Ogre Entity using a sphere mesh. This mesh must be
//.........这里部分代码省略.........
示例7: main
int main( int argc, char *argv[] )
{
// OSG init
osg::osgLog().setLogLevel(osg::LOG_WARNING);
osg::osgInit(argc, argv);
// parse command line options
parsecommandline( argc, argv );
// disable display lists
osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype();
osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto);
if ( pGeoProto != osg::NullFC )
pGeoProto->setDlistCache(false);
// create the graph
osg::NodePtr node;
// root
root = osg::Node::create();
beginEditCP(root);
root->setCore( osg::Group::create() );
// beacon for camera and light
osg::NodePtr beacon;
beacon = osg::Node::create();
beginEditCP(beacon);
beacon->setCore( osg::Group::create() );
endEditCP(beacon);
// light
light_node = osg::Node::create();
osg::DirectionalLightPtr light = osg::DirectionalLight::create();
beginEditCP( light_node );
light_node->setCore( light );
root->addChild( light_node );
beginEditCP(light);
light->setAmbient( .3, .3, .3, 1 );
light->setDiffuse( 1, 1, 1, 1 );
light->setDirection(0,0,1);
light->setBeacon( beacon );
endEditCP(light);
// transformation, parent of beacon
node = osg::Node::create();
cam_trans = osg::Transform::create();
beginEditCP(node);
node->setCore( cam_trans );
node->addChild( beacon );
endEditCP(node);
root->addChild( node );
// Camera
osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create();
cam->setBeacon( beacon );
cam->setFov( 50 );
cam->setNear( 0.1 );
cam->setFar( 10000 );
// Background
osg::SolidBackgroundPtr background = osg::SolidBackground::create();
if ( White_background )
{
beginEditCP( background );
background->setColor(osg::Color3f(1,1,1));
endEditCP( background );
}
// Viewport
osg::ViewportPtr vp = osg::Viewport::create();
vp->setCamera( cam );
vp->setBackground( background );
vp->setRoot( root );
vp->setSize( 0,0, 1,1 );
if ( With_window )
{
// GLUT init
glutInitWindowSize( 400, 400 ); // before glutInit so user can
glutInitWindowPosition( 100, 100 ); // override with comannd line args
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("Collision Benchmark");
glutKeyboardFunc(key);
glutVisibilityFunc(vis);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIdleFunc(display);
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
// Window
osg::GLUTWindowPtr gwin;
//.........这里部分代码省略.........
示例8: createScoreBoards
NodePtr createScoreBoards()
{
GeometryPtr geo;
NodePtr bg;
SimpleMaterialPtr m;
ScoreBoard1 = new TextStuff() ;
ScoreBoard2 = new TextStuff() ;
// First get the global group node
OSG::NodePtr scoreBoardsNodePtr = OSG::Node::create();
scoreBoardsNodePtr->setCore(OSG::Group::create());
// Setup text 1
ScoreBoard1->initialize();
ScoreBoard1->updateFace();
ScoreBoard1->updateScore(0,0);
// Setup text 2
ScoreBoard2->initialize();
ScoreBoard2->updateFace();
ScoreBoard2->updateScore(0,0);
////////// 1 /////////
// make its transform
TransformPtr trans1;
NodePtr trans_node1 = makeCoredNode<Transform>(&trans1);
beginEditCP(trans1);
trans1->getMatrix().setTransform(Vec3f(0,4,-10.5),Quaternion( Vec3f(0,1,0),deg2rad(0)));
endEditCP(trans1);
// make geometry
bg = makePlane(9.3, 1, 8,2);
m= SimpleMaterial::create();
beginEditCP(m);
{
m->setAmbient (Color3f(0,0,0));
m->setDiffuse (Color3f(0.0,0.0,0.0));
}
endEditCP (m);
geo = GeometryPtr::dcast(bg->getCore());
beginEditCP(geo);
geo->setMaterial(m);
beginEditCP(geo);
beginEditCP(bg);
bg->addChild(ScoreBoard1->mRootNode);
endEditCP(bg);
beginEditCP(trans_node1);
trans_node1->addChild(bg);
endEditCP(trans_node1);
////////// 2 /////////
// make its transform
TransformPtr trans2;
NodePtr trans_node2 = makeCoredNode<Transform>(&trans2);
beginEditCP(trans2);
trans2->getMatrix().setTransform(Vec3f(0,4,10.5),Quaternion( Vec3f(0,1,0),deg2rad(180)));
endEditCP(trans2);
// make geometry
bg = makePlane(9.3, 1, 8,2);
m = SimpleMaterial::create();
beginEditCP(m);
{
m->setAmbient (Color3f(0,0,0));
m->setDiffuse (Color3f(0.0,0.0,0.0));
}
endEditCP (m);
geo = GeometryPtr::dcast(bg->getCore());
beginEditCP(geo);
geo->setMaterial(m);
beginEditCP(geo);
beginEditCP(bg);
bg->addChild(ScoreBoard2->mRootNode);
endEditCP(bg);
beginEditCP(trans_node2);
trans_node2->addChild(bg);
endEditCP(trans_node2);
beginEditCP(scoreBoardsNodePtr);
scoreBoardsNodePtr->addChild(trans_node1);
scoreBoardsNodePtr->addChild(trans_node2);
endEditCP(scoreBoardsNodePtr);
return scoreBoardsNodePtr;
}