|
发表于 2016-1-18 22:16:27
|
显示全部楼层
bool pick( const double x, const double y,
osgViewer::Viewer* viewer )
{
if (!viewer->getSceneData())
// Nothing to pick.
return false;
double w( .05 ), h( .05 );
osgUtil:olytopeIntersector* picker =
new osgUtil::PolytopeIntersector(
osgUtil::Intersector::PROJECTION,
x-w, y-h, x+w, y+h );
osgUtil::IntersectionVisitor iv( picker );
viewer->getCamera()->accept( iv );
if (picker->containsIntersections())
{
const osg::NodePath& nodePath =
picker->getFirstIntersection().nodePath;
unsigned int idx = nodePath.size();
while (idx--)
{
// Find the LAST MatrixTransform in the node
// path; this will be the MatrixTransform
// to attach our callback to.
osg::MatrixTransform* mt =
dynamic_cast<osg::MatrixTransform*>(
nodePath[ idx ] );
if (mt == NULL)
continue;
// If we get here, we just found a
// MatrixTransform in the nodePath.
if (_selectedNode.valid())
// Clear the previous selected node's
// callback to make it stop spinning.
_selectedNode->setUpdateCallback( NULL );
_selectedNode = mt;
_selectedNode->setUpdateCallback( new RotateCB );
break;
}
if (!_selectedNode.valid())
osg::notify() << "ick failed." << std::endl;
}
else if (_selectedNode.valid())
{
_selectedNode->setUpdateCallback( NULL );
_selectedNode = NULL;
}
return _selectedNode.valid();
}
参考一下这段代码!! |
|