Re: [osg-users] Polytope from view frustum
Also check out osgShadow::ConvexPolyhedron if you want to extract the corner verts or make geometry from it. Glenn Waldron On Wed, Nov 2, 2016 at 9:47 AM, Jeff Biggswrote: > > try this... > > osg::Polytope GetViewPolytope( > const osg::Matrix , > const osg::Matrix , > const osg::Matrix ) > { > osg::Polytope clipspace; > clipspace.setToUnitFrustum(true, true); > > // composite matrix > osg::Matrixd mvp = m * v * p; > > // transform from clip space to local coords > osg::Polytope local; > local.setAndTransformProvidingInverse(clipspace, mvp); > > return local; > } > > // --- Sample use case --- > > osg::Camera *cam; > osg::Matrixd entityBodyMatrix; > > osg::Polytope viewPolytope = GetViewPolytope( > cam->getProjectionMatrix(), cam->getViewMatrix(), entityBodyMatrix); > > const osg::BoundingSphere boundSphere; > > if (viewPolytope.contains(boundSphere) { > // sphere is inside of view > } > > jeff > > > > On 11/2/16 3:43 AM, Robert Osfield wrote: > >> On 1 November 2016 at 21:45, Trajce Nikolov NICK >> wrote: >> >>> Hi Community, >>> >>> anyone knowing how to achieve this and with will to share? >>> >>> Thanks a bunch as always !! >>> >> Have a look at the API's... >> >> First one to look at is osg::Polytope, create one of these with a unit >> frustum. This will be in clip space. >> >> Next step transform this Polytope by the projection matrix using the >> transformProvidingInverse() method (to transform a plane you multiple >> it by the inverse of that matrix), so in our case the projection >> matrix transform from eye space into clip space which is the inverse >> of the transform we intend, but thanks to the way that planes are >> transformed we can just use the projection matrix directly as long as >> we use the transformProvidingInverse(). See the src/osg/CullStack.cpp >> to see this in action. >> >> Then transform into object coordinates using the same method by >> providing the view and model matrices. >> >> Robert. >> ___ >> osg-users mailing list >> osg-users@lists.openscenegraph.org >> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >> >> >> > > -- > Jeff Biggs > > ___ > 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] Polytope from view frustum
try this... osg::Polytope GetViewPolytope( const osg::Matrix , const osg::Matrix , const osg::Matrix ) { osg::Polytope clipspace; clipspace.setToUnitFrustum(true, true); // composite matrix osg::Matrixd mvp = m * v * p; // transform from clip space to local coords osg::Polytope local; local.setAndTransformProvidingInverse(clipspace, mvp); return local; } // --- Sample use case --- osg::Camera *cam; osg::Matrixd entityBodyMatrix; osg::Polytope viewPolytope = GetViewPolytope( cam->getProjectionMatrix(), cam->getViewMatrix(), entityBodyMatrix); const osg::BoundingSphere boundSphere; if (viewPolytope.contains(boundSphere) { // sphere is inside of view } jeff On 11/2/16 3:43 AM, Robert Osfield wrote: On 1 November 2016 at 21:45, Trajce Nikolov NICKwrote: Hi Community, anyone knowing how to achieve this and with will to share? Thanks a bunch as always !! Have a look at the API's... First one to look at is osg::Polytope, create one of these with a unit frustum. This will be in clip space. Next step transform this Polytope by the projection matrix using the transformProvidingInverse() method (to transform a plane you multiple it by the inverse of that matrix), so in our case the projection matrix transform from eye space into clip space which is the inverse of the transform we intend, but thanks to the way that planes are transformed we can just use the projection matrix directly as long as we use the transformProvidingInverse(). See the src/osg/CullStack.cpp to see this in action. Then transform into object coordinates using the same method by providing the view and model matrices. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Jeff Biggs ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Polytope from view frustum
Thanks Robert On Wed, Nov 2, 2016 at 9:43 AM, Robert Osfieldwrote: > On 1 November 2016 at 21:45, Trajce Nikolov NICK > wrote: > > Hi Community, > > > > anyone knowing how to achieve this and with will to share? > > > > Thanks a bunch as always !! > > Have a look at the API's... > > First one to look at is osg::Polytope, create one of these with a unit > frustum. This will be in clip space. > > Next step transform this Polytope by the projection matrix using the > transformProvidingInverse() method (to transform a plane you multiple > it by the inverse of that matrix), so in our case the projection > matrix transform from eye space into clip space which is the inverse > of the transform we intend, but thanks to the way that planes are > transformed we can just use the projection matrix directly as long as > we use the transformProvidingInverse(). See the src/osg/CullStack.cpp > to see this in action. > > Then transform into object coordinates using the same method by > providing the view and model matrices. > > Robert. > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > -- trajce nikolov nick ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Polytope from view frustum
On 1 November 2016 at 21:45, Trajce Nikolov NICKwrote: > Hi Community, > > anyone knowing how to achieve this and with will to share? > > Thanks a bunch as always !! Have a look at the API's... First one to look at is osg::Polytope, create one of these with a unit frustum. This will be in clip space. Next step transform this Polytope by the projection matrix using the transformProvidingInverse() method (to transform a plane you multiple it by the inverse of that matrix), so in our case the projection matrix transform from eye space into clip space which is the inverse of the transform we intend, but thanks to the way that planes are transformed we can just use the projection matrix directly as long as we use the transformProvidingInverse(). See the src/osg/CullStack.cpp to see this in action. Then transform into object coordinates using the same method by providing the view and model matrices. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Polytope from view frustum
Hi Community, anyone knowing how to achieve this and with will to share? Thanks a bunch as always !! Cheers, Nick -- trajce nikolov nick ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Polytope - Intersections sorted by distance of localIntersectionPoint and the reference plane
Hi again, After thinking about it here is what I think the answer is. Let's say our polytope intersects two circles (or rectangles) A and B, each at two points A1, A2 and B1, B2 The center point of A1 and A2 is computed, denote by centerA12 The center point of B1 and B2 is computed, denote by centerB12 Then the distance is measured from centerA12, and centerB12 to the reference plane. By default the reference plane is the last plane in teh polytope - meaning, if the polytope is made out of 5 half-planes, the last one is the default reference plane (the last one, as the last one in the data structure the half-planes are stored). The polytope intersector then stores the nodes sorted by the distance as described above. Still need to understand what happens if one of the circles is completely inside the polytope, what is the order of such an object in the sorting scheme. Also, another question I was asking myself, was about duplicate reporting. Let's say I have a parent and a child node both at the same location. When the polytope intersector intersects both, are they reported as 2 different intersections (each having their own path, which is the same except of one node)? (I would say yes) Cheers, Ron -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50330#50330 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Polytope - Intersections sorted by distance of localIntersectionPoint and the reference plane
Hi, I am trying to understand what are (1) distance of the localIntersectionPoint, (2) the reference plane in a polytope intersector, and (3) last plane of the polytope, which are used to sort the intersections of a Polytope intersector. I know that a volume is created with half-planes in a polygon shape for the intersection volume, then the scene nodes are tested to see if they are inside or intersect the polytope (or outside). During this process, a list of intersections is created sorted by the distance of the localIntersectionPoint and the reference plane. also The default for the reference plane is the last plane of the polytope Can someone give an explanation about these? (or explain through an example of, let's say, 2 lines intersecting a polytope, how will they be sorted?) Cheers, Ron -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50314#50314 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Polytope
Hi, I just started to use the polytope and polytopeintersect and have some results I did not expect. In the code there are 3 cases that creates an osg::Box which is the cube I want to intersect with the plane. The 3 cases have each a different solution, where I expect them all to have the same solution which is 4 intersections. There is a comment next to each osg::Box being created.. can someone explain to me why I don't get 4 intersections in all cases? the only difference in each case is that I create the box in a different location. here is the code: Code: #include stdafx.h #include osg/group #include osg/geometry #include osgViewer/Viewer #include osg/Polytope #include osg/ShapeDrawable #include osgUtil/PolytopeIntersector #include osg/shape #include iostream osg::Group* createScene() { osg::Group* root = new osg::Group; // create group for objects we want to collide against osg::Group* pGroup = new osg::Group; root-addChild( pGroup ); osg::Geometry* pTest = osg::createTexturedQuadGeometry( osg::Vec3(-2.0f,-2.0f,0.0), osg::Vec3(4.0f,0.0f,0.0), osg::Vec3(0.0f,4.0f,0.0f) ); osg::Geode* pGeodeTest = new osg::Geode; pGeodeTest-addDrawable( pTest ); pGroup-addChild( pGeodeTest ); // create a cube osg::Geode* pGeode = new osg::Geode; //osg::ShapeDrawable* pShape = new osg::ShapeDrawable( new osg::Box(osg::Vec3(0.0f,0.0f,0.0f),0.2f) ); // 4 intersections, but 2 of them in the same place (not expected) //osg::ShapeDrawable* pShape = new osg::ShapeDrawable( new osg::Box(osg::Vec3(0.2f,0.0f,0.0f),0.2f) ); // only two intersections (not expected) osg::ShapeDrawable* pShape = new osg::ShapeDrawable( new osg::Box(osg::Vec3(0.5f,0.0f,0.0f),0.2f) ); // 4 intersections (expected) pShape-setColor( osg::Vec4( 0,1,0,1 ) ); pGeode-addDrawable( pShape ); root-addChild( pGeode ); osg::Polytope* p = new osg::Polytope; p-setToBoundingBox( pGeode-getBoundingBox() ); osgUtil::PolytopeIntersector* intersector = new osgUtil::PolytopeIntersector( osgUtil::Intersector::MODEL, *p ); osgUtil::IntersectionVisitor* iv = new osgUtil::IntersectionVisitor; iv-setIntersector( intersector ); pGroup-accept( *iv ); if ( iv-getIntersector()-containsIntersections() ) { std::cout COUNT: intersector-getIntersections().size() std::endl; std::cout FIRST COUNT: intersector-getFirstIntersection().numIntersectionPoints std::endl; osgUtil::PolytopeIntersector::Intersection firstIntersection = intersector-getFirstIntersection(); for ( unsigned int i=0; ifirstIntersection.numIntersectionPoints; i++ ) { osg::Vec3 pos = firstIntersection.intersectionPoints[i]; std::cout POS i : pos.x() , pos.y() , pos.z() std::endl; std::cout max dist firstIntersection.maxDistance std::endl; std::cout distance firstIntersection.distance std::endl; osg::Geode* pGeode = new osg::Geode; osg::ShapeDrawable* pTestSphere = new osg::ShapeDrawable( new osg::Sphere(pos,0.02f) ); pTestSphere-setColor( osg::Vec4(1,0,0,1) ); pGeode-addDrawable( pTestSphere ); root-addChild( pGeode ); } } return root; } int _tmain(int argc, _TCHAR* argv[]) { // construct the viewer osg::ref_ptrosgViewer::Viewer rViewer = new osgViewer::Viewer; rViewer-setUpViewInWindow( 32, 32, 800, 600 ); rViewer-setSceneData( createScene() ); return rViewer-run(); } Thank you! Cheers, Peter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=43093#43093 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Polytope intersector
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 From: Paul Martz [EMAIL PROTECTED] Subject: Re: Mouse Picking (again...) Newsgroups: gmane.comp.graphics.openscenegraph.user Date: 2007-12-13 20:44:13 GMT (5 days, 19 hours and 28 minutes ago) Here I am, then, asking anyone that can answer me, why it didn't work even though I used a box rendered vertex by vertex? There is a known bug with the Polytope intersection class: at least one vertex must be in the polytope in order for it to return a hit. If you mouse-click in the middle of a quad and no vertices are within the Polytope, no pick is returned. You can test to see if this is the problem by clicking on a corner of your box. That should return a pick. (If it doesn't, then you have some other bug.) Is still true? I notice recent work on the PolytopeIntersector, as well as code that seems to specifically address the problem you mention. Note that I'm too lazy to check myself :) Tim -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFHaUQYeDhWHdXrDRURAiE5AKCSOA3+dDy+06ReKZQs1zJ7vBxSGwCeOZTQ 9Nk9NpIu0iVc2sKFZc7pqRs= =Qp3r -END PGP SIGNATURE- ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org