|
代码如下:
osg:rawable* mirror = createMirrorSurface(xMin,xMax,yMin,yMax,z);
osg::MatrixTransform* rootNode = new osg::MatrixTransform;
{
osg::Stencil* stencil = new osg::Stencil;
stencil->setFunction(osg::Stencil::ALWAYS,1,~0u);
stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE);
osg::StateSet* statesetBin1 = new osg::StateSet();
statesetBin1->setAttributeAndModes(stencil,osg::StateAttribute::ON);
osg::Geode* geode = new osg::Geode;
geode->addDrawable(mirror); //第一个,添加第一个
geode->setStateSet(statesetBin1);
rootNode->addChild(geode);
}
{
osg::Stencil* stencil = new osg::Stencil;
stencil->setFunction(osg::Stencil::EQUAL,1,~0u);
stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP);
osg::Depth* depth = new osg::Depth;
depth->setFunction(osg::Depth::ALWAYS);
depth->setRange(1.0,1.0);
osg::StateSet* statesetBin3 = new osg::StateSet();
statesetBin3->setAttributeAndModes(stencil,osg::StateAttribute::ON);
statesetBin3->setAttribute(depth);
osg::Geode* geode = new osg::Geode;
geode->addDrawable(mirror); //第二个,添加第二个
geode->setStateSet(statesetBin3);
rootNode->addChild(geode);
}
{
osg::StateSet* dstate = new osg::StateSet();
osg::Stencil* stencil = new osg::Stencil;
stencil->setFunction(osg::Stencil::EQUAL,1,~0u);
stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP);
dstate->setAttributeAndModes(stencil,osg::StateAttribute::ON);
osg::MatrixTransform* reverseMatrix = new osg::MatrixTransform;
reverseMatrix->setStateSet(dstate);
reverseMatrix->preMult(osg::Matrix::translate(0.0f,0.0f,-z)*osg::Matrix::scale(1.0f,1.0f,-1.0f)*osg::Matrix::translate(0.0f,0.0f,z));
reverseMatrix->addChild(model);
rootNode->addChild(reverseMatrix);
} |
|