For my application, I use this function to extract the origin and the direction of a 2d point on the screen. My windowing system here is Qt.
I can't say this is the most efficient way to get the answer, but it works. void QOpenSceneGraph::xyVector(const QPoint &screenpoint, osg::Vec3d &origin, osg::Vec3d &direction) { osg::Matrix mat = osg::Matrix::inverse(m_SceneView->getProjectionMatrix()); osg::Matrix cameramatrix = this->getCameraMatrix(); osg::Matrix cameramatrixnotrans = cameramatrix; cameramatrixnotrans.setTrans(0,0,0); osg::Vec4d d = osg::Vec4( ((double)screenpoint.x() / (double)this->width()) * 2.0 - 1.0, -(((double)screenpoint.y() / (double)this->height()) * 2.0 - 1.0), 0.0,1.0); d = d * mat; d = d * cameramatrixnotrans; direction.set(d[0],d[1],d[2]); direction.normalize(); origin = cameramatrix.getTrans(); } On Mon, Mar 9, 2009 at 2:31 PM, Ben Axelrod <baxel...@coroware.com> wrote: > I have been using osgUtil::PickVisitor for a while now to pick objects in > my tree under the mouse. But now I need to cast a ray into the scene under > the mouse and manually intersect it with an imaginary plane. Is there some > helper function to do this mouse ray cast for me? Specifically, something > that would take as input 2 ints for the position of the mouse, and maybe the > camera or projection and view matrices, then output a vector? > > > > Thanks, > > -Ben > > _______________________________________________ > 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