Hi Rhaul/Sumit?

You should avoid doing CPU based frame buffer reads if you can as it's
en extremely slow way of getting this info.  You are far better off
use using ray based testing as per the osgpick example, or if you need
to try and do the op on the GPU, such as by doing a render to texture.
 Finally if you really really have to read the depth buffer write a
camera post draw callback and do your own glReadPixels.

Robert.


On Mon, Jun 23, 2008 at 7:57 PM, Rahul Jain <[EMAIL PROTECTED]> wrote:
> Hi,
> I want to find point of intersection with the scene at the location
> pointed by mouse using depth buffer. I have attached an image to the
> camera for  getting the depth buffer values per frame using code
> mentioned below and i  am to read the information of the depth buffer
> properly
> =========================================================
> image = new osg::Image();
> camera = viewer->getCamera();
> camera->attach(osg::Camera::DEPTH_BUFFER,image);
> image->allocateImage(1280, 1024, 1, GL_LUMINANCE, GL_FLOAT);
> =========================================================
>
> I have created my custom GUIEventHandler for this purpose. In the handle
> function i am getting the mouse coordinates using ea.getX() and
> ea.getY().  After getting the mouse coordinates this is what i am  doing
>
> // Get all the matrix required for inverse transformation
> osg::Matrixd projMatrix    = camera->getProjectionMatrix();
> osg::Matrixd viewMatrix   = camera->getViewMatrix();
> osg::Matrixd  windowMatrix = camera->getViewport()->computeWindowMatrix();
>
> // Get depth value from the image
> float  depth =(float )  (* image->data(ea.getX(), ea.getY()));
>
> // Create a point
> osg::Vec3 point(x,y,depth);
>
> // Apply inverse transformation to get the local coordinates of the
> intersected point
> point = point*osg::Matrixd::inverse(windowMatrix);
> point = point*osg::Matrixd::inverse(projMatrix);
> point = point*osg::Matrixd::inverse(viewMatrix);
>
> To verify the point  am drawing an quad at the location using
>
> osg::ref_ptr<osg::Vec3Array> vert (new osg::Vec3Array);
>   vert->push_back(osg::Vec3(point.x()-0.1,point.y(),point.z()-0.1));
>   vert->push_back(osg::Vec3(point.x()-0.1,point.y(),point.z()+0.1));
>   vert->push_back(osg::Vec3(point.x()+0.1,point.y(),point.z()+0.1));
>   vert->push_back(osg::Vec3(point.x()+0.1,point.y(),point.z()-0.1));
>   geometry->setVertexArray(vert.get());
>
> The quad is drawn at proper location in x,z but in y(OSG y direction)
> direction it is getting translated. I am not able to understand what i
> am doing wrong cam somebody tell me what is the problem in my approach ?
>
> Thanks in advance
> Cheers
> Sumit
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to