|
现在想做一个裁剪平面与拖拽器结合起来使用的功能,拖拽裁剪平面的时候,模型不动,只显示未被裁剪的部分。该如何实现?
尝试了
osg::ArgumentParser arguments(&argc, argv);
osg::Node* model = osgDB::readNodeFiles(arguments);
if (!model)
model = osgDB::readNodeFile("cow.osg");
//osg::StateSet * stateset = new osg::StateSet;
//osg::ClipNode * clipnode = new osg::ClipNode;
//创建一个裁剪平面
osg::ref_ptr<osg::ClipPlane> cp1 = new osg::ClipPlane();
//设置裁剪平面
cp1->setClipPlane(1, 0, 0, 0.1);
//指定平面索引
cp1->setClipPlaneNum(0);
osg::ref_ptr<osgManipulator::Selection> selection1 = new osgManipulator::Selection;
float scale = model->getBound().radius()*1.6;
osg::ref_ptr<osgManipulator::TranslateAxisDragger>dragger = new osgManipulator::TranslateAxisDragger;
dragger->setupDefaultGeometry();
dragger->setMatrix(osg::Matrix::scale(scale, scale, scale)*osg::Matrix::translate(model->getBound().center()));
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild(dragger.get());
root->addChild(selection1.get());
root->addChild(model);
//root->addChild(osgDB::readNodeFile("axes.osg"));
osg::ref_ptr<osgManipulator::CommandManager> manager = new osgManipulator::CommandManager;
manager->connect(*dragger, *selection1);
//启用裁剪平面
root->getOrCreateStateSet()->setAttributeAndModes(cp1.get(), osg::StateAttribute::ON);
结果很奇怪,有没有其他正常一点的实现方式...新手真的不太会写,就看了看基本的clipplane和dragger的例子,给点思路也好。 |
-
|