[osg-users] Backface culling for a group containing a plane of linestrips.

Chris Denham c.m.denham at gmail.com
Thu Oct 25 10:10:45 PDT 2007

I'm looking for the best way to make a collection of linestrips (which
lie on plane) disappear when the plane is facing away from the screen.
i.e. exactly like the way back face culling works for polygonal faces.
My first attempt was to create a special kind of group that has a
normal, then when the CullVistor visits the node, determine whether to
accept the node based on the modelviewmatrix transformation of the
normal vector.
Here's my implementation (which doesn't seem to work properly). Can
anyone help me fix it, or suggest a better method?

class NormalGroup : public osg::Group
    virtual void accept(osg::NodeVisitor& nv);
    void setNormal(const osg::Vec3 & position, const osg::Vec3 & direction)
        _position = position;
        _direction = direction;

     osg::Vec3 _position;
     osg::Vec3 _direction;

void NormalGroup::accept(osg::NodeVisitor& nv)
    if (nv.validNodeMask(*this))
        if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
            osgUtil::CullVisitor * cv =
            if (cv)
                osg::Matrix * matrix = cv->getModelViewMatrix();
                osg::Vec3 p1 = *matrix * _position;
                osg::Vec3 p2 = *matrix * (_position + _direction);
                osg::Vec3 d = p2 - p1;
                if (d.y() > 0) Group::accept(nv);
        } else {

More information about the osg-users mailing list