Hi,
I have a scenegraph consisting of several subgraphs where each of them has a
set of clip planes that are different for each of these subgraphs.
I have attached a simple test program that illustrates what I mean.
I expect to draw a two rectangular quads colored read or blue. Due to the
setting of the clip plane I expect that they do not overlap and only the half
of the quad is painted. But that does not work.
What am I doing wrong?
Greetings
Mathias
#include <osg/ClipNode>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Group>
#include <osgViewer/Viewer>
osg::Node*
createQuad(const osg::Vec4& color, const osg::Vec2& v0, const osg::Vec2& v1, double y = 0)
{
osg::Geode* geode = new osg::Geode;
osg::ref_ptr<osg::Vec3Array> shared_normals = new osg::Vec3Array;
shared_normals->push_back(osg::Vec3(0, -1, 0));
osg::Geometry* polyGeom = new osg::Geometry();
osg::ref_ptr<osg::Vec4Array> shared_colors = new osg::Vec4Array;
shared_colors->push_back(color);
osg::Vec3 myCoords[] = {
osg::Vec3(v0[0], y, v0[1]),
osg::Vec3(v1[0], y, v0[1]),
osg::Vec3(v1[0], y, v1[1]),
osg::Vec3(v0[0], y, v1[1]),
};
int numCoords = sizeof(myCoords)/sizeof(osg::Vec3);
osg::Vec3Array* vertices = new osg::Vec3Array(numCoords, myCoords);
polyGeom->setVertexArray(vertices);
polyGeom->setColorArray(shared_colors.get());
polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
polyGeom->setNormalArray(shared_normals.get());
polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, numCoords));
geode->addDrawable(polyGeom);
return geode;
}
osg::Node* createScene()
{
osg::Group* group = new osg::Group;
osg::ClipNode* clip;
clip = new osg::ClipNode;
group->addChild(clip);
clip->addClipPlane(new osg::ClipPlane(0, 1, 0, 0, 0));
clip->setLocalStateSetModes(osg::StateAttribute::ON);
clip->addChild(createQuad(osg::Vec4(1, 0, 0, 1),
osg::Vec2(-1, -1), osg::Vec2(1, 1)));
clip = new osg::ClipNode;
group->addChild(clip);
clip->addClipPlane(new osg::ClipPlane(0, -1, 0, 0, 0));
clip->setLocalStateSetModes(osg::StateAttribute::ON);
clip->addChild(createQuad(osg::Vec4(0, 0, 1, 1),
osg::Vec2(-1, -1), osg::Vec2(1, 1)));
return group;
}
int main( int argc, char **argv )
{
osgViewer::Viewer viewer;
viewer.setSceneData(createScene());
return viewer.run();
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/