Re: [osg-users] cast ray into scene
Hi Ben, In my engine, I got a method that takes a View and an optional NodePath. Notes: - I created an invisible plane so that I can test against that plane. - pointerX and pointerY are class members (you may refactor so that it suits your needs). - Here my method assumes there is at most one intersection (see the ASSERT()). - setPickPosition() is a method that stores the result (= the intersection/pick position). void computePickPos(osgViewer::View view, osg::NodePath * pPickNodePath = NULL) { if (pPickNodePath pPickNodePath-empty()) return; osgUtil::LineSegmentIntersector::Intersections intersections; bool intersected; if (pPickNodePath) intersected = view.computeIntersections(pointerX, pointerY, *pPickNodePath, intersections); else intersected = view.computeIntersections(pointerX, pointerY, intersections); if (intersected) { ASSERT(intersections.size() = 1); if (intersections.size()0) setPickPosition(intersections.begin()-getWorldIntersectPoint()); } } Hope it helps. Sukender PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/ Le Mon, 09 Mar 2009 20:31:55 +0100, Ben Axelrod baxel...@coroware.com a écrit: 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] cast ray into scene
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
Re: [osg-users] cast ray into scene
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