Hi, everyone:
In my opinion, the clip effect of a clipnode only affects its child nodes,
and a new clipnode only uses its own clipplanes. But the fact seems different
from this. In the following project, a clipnode with a cow is added to two
parents, but only one cow is shown. How can I get two clipped cows in result in
the following code?
osg::Node* decorate_with_clip_node(osg::Node* node)
{
osg::Group* rootnode = new osg::Group;
osg::ClipNode* clipped_subgraph = new osg::ClipNode;
osg::BoundingSphere bs = node->getBound();
bs.radius()*= 0.4f;
osg::BoundingBox bb;
bb.expandBy(bs);
clipped_subgraph->createClipBox(bb);
clipped_subgraph->addChild(node);
osg::MatrixTransform *mt1 = new osg::MatrixTransform;
mt1->addChild(clipped_subgraph);
osg::MatrixTransform *mt2 = new osg::MatrixTransform;
osg::Matrixd mat;
mat.makeTranslate(bs.radius()*2, bs.radius()*2, bs.radius()*2);
mt2->setMatrix(mat);
mt2->addChild(clipped_subgraph);
rootnode->addChild(mt1);
rootnode->addChild(mt2);
return rootnode;
}
int main( int argc, char **argv )
{
// use an ArgumentParser object to manage the program arguments.
// load the nodes from the commandline arguments.
osg::Node* loadedModel = osgDB::readNodeFile("cow.osgt");
if (!loadedModel)
{
osg::notify(osg::NOTICE)<<"Please specifiy a filename and the command
line"<<std::endl;
return 1;
}
// decorate the scenegraph with a clip node.
osg::Node* rootnode = decorate_with_clip_node(loadedModel);
// run optimization over the scene graph
osgUtil::Optimizer optimzer;
optimzer.optimize(rootnode);
osgViewer::Viewer viewer;
// set the scene to render
viewer.setSceneData(rootnode);
return viewer.run();
}
------------------
Failure is the mother of success.
Wu Zhicheng
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org