Discussion:
[osg-users] How do you create the osg::Planeof PolytopeIntersector that will give you the right intersection?
mirr...@gmail.com
2021-03-16 12:25:15 UTC
Permalink
win10&osg3.6.4
//
osg::Matrixd proj = osg::Matrixd::identity();
proj.makePerspective(60, frustumAspectWidth/frustumAspectHeight,
frustumNear, frustumFar);
//
const double mynear = proj(3, 2) / (proj(2, 2) - 1.0);
const double myfar = proj(3, 2) / (1.0 + proj(2, 2));
//
const double nLeft = mynear * (proj(2, 0) - 1.0) / proj(0, 0);
const double nRight = mynear * (1.0 + proj(2, 0)) / proj(0, 0);
const double nTop = mynear * (1.0 + proj(2, 1)) / proj(1, 1);
const double nBottom = mynear * (proj(2, 1) - 1.0) / proj(1, 1);
const double fLeft = myfar * (proj(2, 0) - 1.0) / proj(0, 0);
const double fRight = myfar * (1.0 + proj(2, 0)) / proj(0, 0);
const double fTop = myfar * (1.0 + proj(2, 1)) / proj(1, 1);
const double fBottom = myfar * (proj(2, 1) - 1.0) / proj(1, 1);
//
_projectPt[0] = osg::Vec3d(0.0, 0.0, 0.0);
_projectPt[1] = osg::Vec3d(nLeft, nBottom, -mynear);
_projectPt[2] = osg::Vec3d(nRight, nBottom, -mynear);
_projectPt[3] = osg::Vec3d(nRight, nTop, -mynear);
_projectPt[4] = osg::Vec3d(nLeft, nTop, -mynear);
_projectPt[5] = osg::Vec3d(fLeft, fBottom, - myfar);
_projectPt[6] = osg::Vec3d(fRight, fBottom, - myfar);
_projectPt[7] = osg::Vec3d(fRight, fTop, -myfar);
_projectPt[8] = osg::Vec3d(fLeft, fTop, - myfar);
osg::Polytope viewFrstumPoly;
//
osg::Matrixd ViewM = _view->getCamera()->getInverseViewMatrix();
//
osg::Vec3d tempProjectPt[9];
//tempProjectPt[0] = _projectPt[0] * ViewM;
tempProjectPt[1] = _projectPt[1] * ViewM;
tempProjectPt[2] = _projectPt[2] * ViewM;
tempProjectPt[3] = _projectPt[3] * ViewM;
tempProjectPt[4] = _projectPt[4] * ViewM;
tempProjectPt[5] = _projectPt[5] * ViewM;
tempProjectPt[6] = _projectPt[6] * ViewM;
tempProjectPt[7] = _projectPt[7] * ViewM;
tempProjectPt[8] = _projectPt[8] * ViewM;
{
viewFrstumPoly.add(osg::Plane(tempProjectPt[1],tempProjectPt[5],tempProjectPt[8]));
}
{
viewFrstumPoly.add(osg::Plane(tempProjectPt[2],tempProjectPt[7],tempProjectPt[6]));
}

{
viewFrstumPoly.add(osg::Plane(tempProjectPt[3],
tempProjectPt[4],tempProjectPt[8]));
}

{
viewFrstumPoly.add(osg::Plane(tempProjectPt[1],tempProjectPt[2],tempProjectPt[6]));
}
{
viewFrstumPoly.add(osg::Plane(tempProjectPt[5],tempProjectPt[6],tempProjectPt[7]));
}
{
viewFrstumPoly.add(osg::Plane(tempProjectPt[3],tempProjectPt[4],tempProjectPt[1]));
}
osg::ref_ptr<osgUtil::PolytopeIntersector> picker = new
osgUtil::PolytopeIntersector(osgUtil::Intersector::MODEL, poly);
picker->setPrecisionHint(osgUtil::Intersector::USE_DOUBLE_CALCULATIONS);
picker->setPrimitiveMask(osgUtil::PolytopeIntersector::POINT_PRIMITIVES);
picker->setIntersectionLimit(osgUtil::Intersector::NO_LIMIT);
//
osgUtil::IntersectionVisitor iv(picker);
_videoFusionNode->accept(iv);//group of scene
if (picker->containsIntersections())
{
//
}
--
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/32729314-2d08-46c7-973c-812c6d8a2bb0n%40googlegroups.com.
Loading...