|
如下代码中,只有clipNode2可见,clipNode1被裁减掉了,但是clipNode1应该子被裁减掉一半,是不是osg中osg::ClipNode只对最后一个起作用,前面的osg::ClipNode也受最后一个osg::ClipNode的影响。是否有方法使得osg::ClipNode只对自身起作用,而不影响其他的osg::ClipNode?希望各位看一下,谢谢!
#include "stdafx.h"
#include <osg/ClipNode>
#include <osg/MatrixTransform>
#include <osg/ComputeBoundsVisitor>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer>
int main(int, char**)
{
// construct the viewer
osgViewer::Viewer viewer;
osg::Node* node = osgDB::readNodeFile("F:/osgModel/cow.osg");
osg::ComputeBoundsVisitor cbv;
node->accept( cbv );
const osg::BoundingBox& bb = cbv.getBoundingBox();
osg::BoundingBox bb1 = bb;
bb1.xMin() += (bb.xMax() - bb.xMin()) * 0.5f;
osg::BoundingBox bb2 = bb;
bb2.xMax() -= (bb.xMax() - bb.xMin()) * 0.5f;
osg::ClipNode* clipNode1 = new osg::ClipNode;
clipNode1->addChild(node);
clipNode1->createClipBox(bb1);
clipNode1->setCullingActive(false);
osg::ClipNode* clipNode2 = new osg::ClipNode;
clipNode2->addChild(node);
clipNode2->createClipBox(bb2);
clipNode2->setCullingActive(false);
osg::MatrixTransform* mt1 = new osg::MatrixTransform;
mt1->setMatrix(osg::Matrix::translate(bb._max - bb._min));
mt1->addChild(clipNode1);
//mt1->setNodeMask(0);
osg::MatrixTransform* mt2 = new osg::MatrixTransform;
//mt2->setMatrix(osg::Matrix::translate(bb._max - bb._min));
mt2->addChild(clipNode2);
//mt2->setNodeMask(0);
osg::Group* root = new osg::Group;
root->addChild(mt1);
root->addChild(mt2);
// set the scene to render
viewer.setSceneData(root);
// run the viewers frame loop
return viewer.run();
}
|
|