Hi Roland, A couple of points. First up if the CompositeViewer is being run multi-theaded then the draw traversal may not be complete, and the values not copied yet to the osg::Image by the time your frame loop reaches your image data output line. In this context it probably will just mean getting values a bit out of step with the current frame, but it is a potential cause for threading issues that you should be careful about.
W.r.t distance values, are you expecting them to be in eye coords? If so you'll need to transform using the near/far distances of the current projection matrix. I can't recall the equation off the top of my head but it's something you should be able to derive from docs on OpenGL. Robert. On Mon, Jun 15, 2009 at 8:28 AM, Roland Leitner<[email protected]> wrote: > Hi folks, > > I am using the z-Buffer in osg 2.4 and have problems getting reasonable > values. When the camera is about two meters away from any flat object > surface, I'll get the value 0.995, and when the camera is about eight meters > away i'll get 0.997 from the z buffer. I have also tried to transform the z > value into a distance value, but the distance value makes no sense! Below is > my code! > > Cheers, Roland > > osgViewer::View* view = new osgViewer::View; > viewer.addView(view); > > view->setSceneData(root); > > view->getCamera()->setProjectionMatrixAsPerspective(V_FoV_deg,V_FoV_deg/H_FoV_deg,1,100); > view->getCamera()->setViewport(new osg::Viewport(traits->width/2,0, 64, 48 )); > view->getCamera()->setGraphicsContext(gc.get()); > > osg::Image* image = new osg::Image(); > view->getCamera()->attach(osg::Camera::DEPTH_BUFFER,image); > > image->allocateImage(64,48,1,GL_DEPTH_COMPONENT,GL_FLOAT); > > float z; > > while( !viewer.done() ) > { > viewer.frame(); > > z = ((float*)pmdimage->data())[1]; > std::cout << "z value : " << z << std::endl; > } > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=13976#13976 > > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

