|
发表于 2011-9-2 14:12:57
|
显示全部楼层
Ex_min-Sx_min,Ey_min-Sy_min,Ex_max-Sx_max,Ey_max-Sy_max好像都等于0吧,
我想你只要记录点击点,而不是最大最小XY,这样应该就可以了
case osgGA::GUIEventAdapter:USH:
{
osgUtil:ineSegmentIntersector::Intersections intersections;
if(ea.getButtonMask()==osgGA::GUIEventAdapter:EFT_MOUSE_BUTTON)
{
if (!viewer)
{
return false;
}
Sx=ea.getX();//记录鼠标开始点击点
Sy=ea.getY();
);
}
}
case(osgGA::GUIEventAdapter:OUBLECLICK):
{
if(ea.getButton()==osgGA::GUIEventAdapter:EFT_MOUSE_BUTTON)
{
Ex=ea.getX();//结束点
Ey=ea.getY();
pick(viewer);
}
}
///////////////////////////////////
bool pick(osgViewer::Viewer* viewer )
{
if (Sx>Ex)) swap(Sx,Ex);
if (Sy>Ey)) swap(Sy,Ey);
osgUtillytopeIntersector * picker =
new osgUtil:olytopeIntersector(
osgUtil::Intersector:ROJECTION,
Sx,Sy,Ex,Ey);///
osgUtil::IntersectionVisitor iv( picker );
viewer->getCamera()->accept( iv );
if (picker->containsIntersections())
{
std::cout<<"intersect!"<<std::endl;
}else
{
std::cout<<"unintersect!"<<std::endl;
}
} |
|