Hi, 

I think there might be a small bug in osg::OcclusionQueryNode, that I've yet to 
find.

Here is a small example with a line triangle, that shows the problem.
I added no face geometry so the lines should basically always be visible when 
in view.
Each line is under an OcclusionQueryNode, but under some camera poses using the 
trackball manipulator, line 3 isn't visible, although it should be.
When I put all the lines in a osg::Group, they are visible.

Does anybody have an idea where the problem might be?


Code:

#include <osg/Group> 
#include <osgViewer/Viewer> 
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osg/OcclusionQueryNode>
#include <vector>

 int main( int argc, char** argv ) 
 { 
        int width = 640;
        int height = 480;

        osgViewer::Viewer viewer;
        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
        camera->setClearColor(osg::Vec4(1.0, 1.0, 1.0, 0.0)); 
    camera->setViewport( new osg::Viewport(0, 0, width, height) );
    camera->setProjectionMatrixAsPerspective(30.0f, 
static_cast<double>(width)/static_cast<double>(height), 1.0f, 10000.0f );
        viewer.setCamera(camera);

        osg::Group* rootnode = new osg::Group;
    viewer.setSceneData(rootnode);
        viewer.addEventHandler(new osgViewer::StatsHandler);
        viewer.setUpViewInWindow(200, 200, width, height);
        viewer.setCameraManipulator( new osgGA::TrackballManipulator );

        std::vector<osg::Vec3> lines;
        
        //Line 1
        lines.push_back(osg::Vec3(-1,0,0));
        lines.push_back(osg::Vec3(0,1,0));

        //Line 2
        lines.push_back(osg::Vec3(0,1,0));
        lines.push_back(osg::Vec3(1,0,0));

        //Line 3
        lines.push_back(osg::Vec3(1,0,0));
        lines.push_back( osg::Vec3(-1,0,0));
        
        for(int i = 0; i < 3; i++){
        
                //osg::ref_ptr<osg::Group> parent = new osg::Group;
                osg::ref_ptr<osg::OcclusionQueryNode> parent = new 
osg::OcclusionQueryNode;
                parent->setVisibilityThreshold(1);
                parent->setQueriesEnabled(true);
                
                osg::Geometry* linesGeom = new osg::Geometry();
        osg::Vec3Array* vertices = new osg::Vec3Array;
                vertices->push_back(lines.at(i+i));
                vertices->push_back(lines.at(i+i+1));
                osg::Vec4Array* color = new osg::Vec4Array;
                color->push_back(osg::Vec4(1,0,0,1));
                linesGeom->setColorArray(color);
                linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
                linesGeom->setVertexArray(vertices);
                linesGeom->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINES,0,2));
                osg::Geode* geode = new osg::Geode();
                geode->addDrawable(linesGeom);
                parent->addChild(geode);
                rootnode->addChild(parent);
        }
    return viewer.run();        
 }




Cheers,
Dakota

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51621#51621





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to