I'm working on a plugin that uses mouse hover actions to toggle visibility on objects. The goal was to have this done by today, and apply it to a character rig so animators don't have to deal with cluttered controls. I'm attemping this through taking the bounding box of the object and projecting it onto the screen and checking if the mouse lies within that 2d bounding box. However that box doesn't stay where the object is located in the scene. The camera has to placed at a certain position and angle to the object in order for it's bounding box and the 2d box to align. Otherwise the box movies above or below the object and it becomes unselectable. I can't figure out what the problem is here and how to fix it. Is the bounding box of the object not sending a straight line from it's points to the screen, or is the 2d box that's not being aligned properly? This is the part of the code in question:
bool mouseEvent::visiblePath()
{
M3dView view = M3dView::active3dView();
MDagPath nodePath = getParentPath();
if(nodePath.isValid()){
MFnTransform dagNode(nodePath);
short posX,minX,maxX;//pivX;
short posY,minY,maxY;//pivY;
getMousePos(posX,posY);
MPoint ptMin,ptMax,ptMouse;//ptPiv;
MVector vecMin,vecMax,vecMouse;//vecPiv;
MBoundingBox box = bbox();
MPoint minimum = box.min();
MPoint maximum = box.max();
view.worldToView(minimum,minX,minY);
view.worldToView(maximum,maxX,maxY);
view.viewToWorld(minX,minY,ptMin,vecMin);
view.viewToWorld(maxX,maxY,ptMax,vecMax);
view.viewToWorld(posX,posY,ptMouse,vecMouse);
MBoundingBox mbox;
mbox.expand(ptMin);
mbox.expand(ptMax);
if(mbox.contains(ptMouse)){
return true;
}else{
MSelectionList list;
MGlobal::getActiveSelectionList(list);
MDagPath dpath;
dagNode.getPath(dpath);
if(list.hasItem(dpath)){
return true;
}else{
return false;
}
}
}else{
MGlobal::displayInfo("no valid dag path");
return false;
}
return mouseEvent::visiblePath();
}