[osg-users] Depth partition doesn't work with intersectors
Hi all, I think I've got a problem while testing the new osgdepthpartition example. I added a PickHandler to test if the IntersectionVisitor could work under such huge environment. It failed to intersect with anything unless I moved very near to the earth geode. The command I used is: # osgdepthpartition --depth-partition 1 2 2 With the attached example code, when the intersector works, you should see a line on the terminal when pressing left button on the earth. But at most time there are no outputs. I guess if the problem is related to the camera projection matrix. As far as I know, the calculated projection matrix will be applied to the main camera in the CullVisitor. Maybe we could dig and make some changes to make the mechanism work with depth-partition? A quick test of previous osgdepthpartition example (with the DepthPartition node) seemed to fail with intersections, too. Cheers, Wang Rui #include osg/io_utils #include osg/ShapeDrawable #include osg/PositionAttitudeTransform #include osg/Texture2D #include osgDB/FileUtils #include osgDB/ReadFile #include osgGA/TrackballManipulator #include osgGA/StateSetManipulator #include osgUtil/LineSegmentIntersector #include osgViewer/ViewerEventHandlers #include osgViewer/Viewer #include iostream const double r_earth = 6378.137; const double r_sun = 695990.0; const double AU = 149697900.0; osg::Node* createScene() { // Create the Earth, in blue osg::ShapeDrawable *earth_sd = new osg::ShapeDrawable; osg::Sphere* earth_sphere = new osg::Sphere; earth_sphere-setName(EarthSphere); earth_sphere-setRadius(r_earth); earth_sd-setShape(earth_sphere); earth_sd-setColor(osg::Vec4(0, 0, 1.0, 1.0)); osg::Geode* earth_geode = new osg::Geode; earth_geode-setName(EarthGeode); earth_geode-addDrawable(earth_sd); // Create the Sun, in yellow osg::ShapeDrawable *sun_sd = new osg::ShapeDrawable; osg::Sphere* sun_sphere = new osg::Sphere; sun_sphere-setName(SunSphere); sun_sphere-setRadius(r_sun); sun_sd-setShape(sun_sphere); sun_sd-setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0)); osg::Geode* sun_geode = new osg::Geode; sun_geode-setName(SunGeode); sun_geode-addDrawable(sun_sd); // Move the sun behind the earth osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform; pat-setPosition(osg::Vec3d(0.0, AU, 0.0)); pat-addChild(sun_geode); osg::Geometry * unitCircle = new osg::Geometry(); { osg::Vec4Array * colours = new osg::Vec4Array(1); (*colours)[0] = osg::Vec4d(1.0,1.0,1.0,1.0); unitCircle-setColorArray(colours); unitCircle-setColorBinding(osg::Geometry::BIND_OVERALL); const unsigned int n_points = 1024; osg::Vec3Array * coords = new osg::Vec3Array(n_points); const double dx = 2.0*osg::PI/n_points; double s,c; for (unsigned int j=0; jn_points; ++j) { s = sin(dx*j); c = cos(dx*j); (*coords)[j].set(osg::Vec3d(c,s,0.0)); } unitCircle-setVertexArray(coords); unitCircle-getOrCreateStateSet()-setMode(GL_LIGHTING,osg::StateAttribute::OFF); unitCircle-addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,n_points)); } osg::Geometry *axes = new osg::Geometry; { osg::Vec4Array *colours = new osg::Vec4Array(1); (*colours)[0] = osg::Vec4d(1.0,0.0,0.0,1.0); axes-setColorArray(colours); axes-setColorBinding(osg::Geometry::BIND_OVERALL); osg::Vec3Array *coords = new osg::Vec3Array(6); (*coords)[0].set(osg::Vec3d(0.0, 0.0, 0.0)); (*coords)[1].set(osg::Vec3d(0.5, 0.0, 0.0)); (*coords)[2].set(osg::Vec3d(0.0, 0.0, 0.0)); (*coords)[3].set(osg::Vec3d(0.0, 0.5, 0.0)); (*coords)[4].set(osg::Vec3d(0.0, 0.0, 0.0)); (*coords)[5].set(osg::Vec3d(0.0, 0.0, 0.5)); axes-setVertexArray(coords); axes-getOrCreateStateSet()-setMode(GL_LIGHTING,osg::StateAttribute::OFF); axes-addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6)); } // Earth orbit osg::Geode * earthOrbitGeode = new osg::Geode; earthOrbitGeode-addDrawable(unitCircle); earthOrbitGeode-addDrawable(axes); earthOrbitGeode-setName(EarthOrbitGeode); osg::PositionAttitudeTransform * earthOrbitPAT = new osg::PositionAttitudeTransform; earthOrbitPAT-setScale(osg::Vec3d(AU,AU,AU)); earthOrbitPAT-setPosition(osg::Vec3d(0.0, AU, 0.0)); earthOrbitPAT-addChild(earthOrbitGeode); earthOrbitPAT-setName(EarthOrbitPAT); osg::Group* scene = new osg::Group; scene-setName(SceneGroup); scene-addChild(earth_geode); scene-addChild(pat); scene-addChild(earthOrbitPAT); return scene; } class PickHandler : public osgGA::GUIEventHandler { public: virtual bool handle( const osgGA::GUIEventAdapter ea, osgGA::GUIActionAdapter aa ) { if ( ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
Re: [osg-users] Depth partition doesn't work with intersectors
Hi Rui, I haven't test the modified app but did do a quick code review. My guess is that the intersection traversal is creating a line segment in window coordinates bound, tranforming to the eye coordinates using the viewer's master Camera's projection matrix and then transforming this into world coordinates - this normally works fine if the master camera's near and far planes are updated to be consistent with the depth range in the scene, but in this case it's the slave camera's that are being set up to encompass the scene extents, while the master camera's near/far settings will be ingnored completely and not adjusted to the scene. The solution is probably to create an infinite ray or one based on the extents of the model rather than the extents of the master camera's projection matrix. Whether this needs a speicific facility in osgUtil::IntersectionVisitor/Intersector to make it easier to manage this type of case I can't say right now, will need to mull it over. Robert. On Thu, Jun 9, 2011 at 7:14 AM, Wang Rui wangra...@gmail.com wrote: Hi all, I think I've got a problem while testing the new osgdepthpartition example. I added a PickHandler to test if the IntersectionVisitor could work under such huge environment. It failed to intersect with anything unless I moved very near to the earth geode. The command I used is: # osgdepthpartition --depth-partition 1 2 2 With the attached example code, when the intersector works, you should see a line on the terminal when pressing left button on the earth. But at most time there are no outputs. I guess if the problem is related to the camera projection matrix. As far as I know, the calculated projection matrix will be applied to the main camera in the CullVisitor. Maybe we could dig and make some changes to make the mechanism work with depth-partition? A quick test of previous osgdepthpartition example (with the DepthPartition node) seemed to fail with intersections, too. Cheers, Wang Rui ___ 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
Re: [osg-users] Depth partition doesn't work with intersectors
Hi Robert, 2011/6/9 Robert Osfield robert.osfi...@gmail.com: Whether this needs a speicific facility in osgUtil::IntersectionVisitor/Intersector to make it easier to manage this type of case I can't say right now, will need to mull it over. Yes, I believe it is reasonable. The only question before I could try out a solution is: should we add an option in the LineSegmentIntersector to use extension line in line-triangle computation, or just add a new intersector type for this situation? Wang Rui ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Depth partition doesn't work with intersectors
Hi Rui, On Thu, Jun 9, 2011 at 2:04 PM, Wang Rui wangra...@gmail.com wrote: 2011/6/9 Robert Osfield robert.osfi...@gmail.com: Whether this needs a speicific facility in osgUtil::IntersectionVisitor/Intersector to make it easier to manage this type of case I can't say right now, will need to mull it over. Yes, I believe it is reasonable. The only question before I could try out a solution is: should we add an option in the LineSegmentIntersector to use extension line in line-triangle computation, or just add a new intersector type for this situation? An InfiniteLineIntersector/LineIntersector might be appropriate. However, it would be tempting to just add a inifinite line flag into LineSegmentIntersector, as this would certainly be the least amount of work, and would lead to the least amount of new code that has to be tested, documented and and maintained. So... I'd go for the infinite line flag as a first implementation, if it looks ugly then we can go back to a creating an Intesector class just for inifinite lines. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Depth partition doesn't work with intersectors
Hi Robert, Fine. I'll have a try as soon as possible. By the way, do you remember the line-triangle intersecting algorithm used in LineSegmentIntersector? I'm not sure about the origin of the algorithm and can hardly extend it before I could fully understand it. :-) Wang Rui 2011/6/9 Robert Osfield robert.osfi...@gmail.com: An InfiniteLineIntersector/LineIntersector might be appropriate. However, it would be tempting to just add a inifinite line flag into LineSegmentIntersector, as this would certainly be the least amount of work, and would lead to the least amount of new code that has to be tested, documented and and maintained. So... I'd go for the infinite line flag as a first implementation, if it looks ugly then we can go back to a creating an Intesector class just for inifinite lines. Robert. ___ 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
Re: [osg-users] depth partition
HI David? (Please sign with the name you wish to be addressed with so we know who to address) I'm not very familiar with the osgdepthpartiion example but I do understand the general concept. My expectation is that for a specific type of application you could probably come up with your own mechanism for management of the mid depth that divides the two regions, you may even be able to use a fixed range, this way would you could avoid the need to traversing the scene for the purposes of depth partitioning. Robert. On Fri, Dec 19, 2008 at 7:37 AM, ZHMW david@gmail.com wrote: Hi everyone! In my application, there is many terrain object, each terrain object is a tree organized by paged lod, just like the structure generated by virtual planet builder. The problem is I cannot integrate many terrain object in one scene. It seems to be the depth problem, And I have tried the osgdepthpartation example. but the visitor in that example cannot process lod nodes. so, I 'm over writting the apply method for PagedLOD. I want to know, what I'm doing is in the right way, And is there any other better solutions? Thanks! Best Wishes. ___ 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
[osg-users] depth partition
Hi everyone! In my application, there is many terrain object, each terrain object is a tree organized by paged lod, just like the structure generated by virtual planet builder. The problem is I cannot integrate many terrain object in one scene. It seems to be the depth problem, And I have tried the osgdepthpartation example. but the visitor in that example cannot process lod nodes. so, I 'm over writting the apply method for PagedLOD. I want to know, what I'm doing is in the right way, And is there any other better solutions? Thanks! Best Wishes. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org