本文整理汇总了C++中osg::NodeRefPtr::addAttachment方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeRefPtr::addAttachment方法的具体用法?C++ NodeRefPtr::addAttachment怎么用?C++ NodeRefPtr::addAttachment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::NodeRefPtr
的用法示例。
在下文中一共展示了NodeRefPtr::addAttachment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doMain
int doMain(int argc, char **argv)
{
//
// This might be necessary depending on the
// used platform to ensure that the corresponding
// libraries get loaded.
//
OSG::preloadSharedObject("OSGFileIO");
OSG::preloadSharedObject("OSGImageFileIO");
OSG::preloadSharedObject("OSGContribPLY");
OSG::osgInit(argc,argv);
// GLUT init
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL | GLUT_DOUBLE);
glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
OSG::PassiveWindowRefPtr pwin=OSG::PassiveWindow::create();
pwin->init();
// create the SimpleSceneManager helper
mgr = new OSG::SimpleSceneManager;
// create the window and initial camera/viewport
mgr->setWindow(pwin);
//
// for storing clipplane beacon we use a container
// collection attachment which we attach to the scene
// node. Otherwise the scene could not be saved correctly,
// as the beacons would be lost.
//
container = OSG::ContainerCollection::create();
//
// Implementation details:
// For each clip plane we provide a ClipPlaneChunk, the plane geometry,
// the plane transform core and at least a plane color conveniently in
// a vector of type VecClipPlaneDetailsT. The next function call
// initializes this data structure.
//
createClipPlaneDetails();
//
// The scene
//
scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addAttachment(container);
//
// A place for accessing the box and torus.
//
vecGeometries.push_back(NULL);
vecGeometries.push_back(NULL);
//
// Build concrete clipping planes and update the clip plane details.
//
ClipPlaneData data1;
ClipPlaneData data2;
data1._equation = OSG::Vec4f(0,0,1,0);
data1._enabled = true;
data2._equation = OSG::Vec4f(1,0,0,0);
data2._enabled = false;
vecClipPlaneData.push_back(data1);
vecClipPlaneData.push_back(data2);
updateClipPlanes(vecClipPlaneData);
keyboard('3',-1,-1);
keyboard('4',-1,-1);
// tell the manager what to manage
mgr->setRoot(scene);
// show the whole scene
mgr->showAll();
mgr->redraw();
pwin->dumpExtensions();
return 0;
}
示例2: main
OSG_END_NAMESPACE
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// load the scene
OSG::NodeRefPtr scene;
if(argc < 2)
{
FWARNING(("No file given!\n"));
scene = OSG::makeTorus(.5, 2, 16, 16);
}
else
{
scene = OSG::SceneFileHandler::the()->read(argv[1]);
}
/*
An Attachment is a special field container that can be attached to
many of the internal classes like Nodes, NodeCores and many others.
There can be multiple Attachments attached to an object.
Attachments can be attached to all FieldContainers that are derived from
AttachmentContainer. This includes most higher-level classes in the
system, like Nodes, NodeCores, Windows, Viewports etc. See the
inheritance graph for details.
One predefined kind of Attachment is the Name, which can
keep the name of an object. Some of loaders (e.g. the WRL loader)
create these kinds of Attachments for named nodes.
*/
/*
An Attachment is a FieldContainer and as such needs to be created using
::create().
*/
OSG::NameRefPtr name = OSG::Name::create();
/*
The NameAttachment only has a single field, there's no need to use the
mask here.
*/
name->editFieldPtr()->setValue("Scene");
/*
Attach the name to the scene node.
*/
scene->addAttachment(name);
/*
Check if the scene has a Name attachment
Attachments are categorized by the GroupID of their class. Every
AttachmentContainer generally keeps only one attachment of a specific
kind.
*/
OSG::AttachmentRefPtr a;
a = scene->findAttachment(OSG::Name::getClassType());
if(a != NULL)
{
OSG::NameRefPtr n = OSG::dynamic_pointer_cast<OSG::Name>(a);
SLOG << "Node name: " << n->getField().getValue() << OSG::endLog;
}
else
{
SLOG << "Node has no name!" << OSG::endLog;
}
/*
As names are used quite often there are two convenience functions
that wrap the code given above: setName and getName. They are declared
in OSGSimpleAttachments.h.
*/
if(getName(scene))
{
SLOG << "Node is named: " << getName(scene) << OSG::endLog;
}
else
{
//.........这里部分代码省略.........