mtuttle
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 = dagNode.boundingBox();                 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(); }
Reply 0 0
mtuttle
here's a more readable format for the code:

http://www.creativecrash.com/forums/api/topics/mboundingbox-issue--2
Reply 0 0
pshipkov
Funny, not far ago i coded animation controls and workflow system entirely through openGL as a replacement to the "standard" Maya thing. It is much more pleasant to the eye than the "wire" controls and brings a lot of interactivity. Anyway, what i meant with this explanation is that i know very well how tricky can be that stuff. I remember having quite a bit of problems with the projections.

I cannot pinpoint the problem in your code, but we can try step by step:
Can you draw your BBox in 3D to make sure it is in the right place ?
If so, then something is wrong with your 3D-2D projections - and that's probably where the problems are, but it is hard to tell. Let's see if step 1 is ok.

Btw, i know that animators dislike auto-toggling of controls. Things turn into disco or Christmas tree. They prefer switches - objects visible in the viewport. When they click on one of them the switch toggles the visibility of some controls, etc.
Reply 0 0
pshipkov
I am looking at your code again  - cannot remember right now but i don't think there is a onMouseMove event in Maya (you can do it through QT of course, but that's different thing), i mean - it will not update until you click or release. Wonder if that is confusing the matter on your side ?
Reply 0 0
mtuttle
Hey Peter, do you have a demonstration of your OpenGL control/animation system? I've seen Pixar's but I don't have time to create a whole new piece of animation software or learn to use OpenGL as such before my reel is due next week (which upon approval determines whether I graduate or not), but would be great reference for the future.
I am using qt to get the mouse move event because I haven't found (in the API documentaion at least) an onMouseMove function within Maya's SDK.  I borrowed it from this :http://www.highend3d.com/forums/api/topics/maya-api-qt-mouse-hover--2 And applied it as a custom locator that creates a new widget upon it's creation and that widget toggles the visibility for any geometry shapes that the locator shares with it's transform. I thought about a manipulator or context, but that would mean the animator would have to switch to that tool each time to get to the toggling and then switch back to do the animation, and it would be too much trouble to isolate what objects they want the manipulator/context to work on...The bounding box is derived from the sibiling shapes in world space, as is the mouse's position -defaulting from M3dView functions...If I have to figure out something special to do the projection/bounding box generation I haven't figured it out yet....
In regards to the disco thing, if there was auto-toggling, there'd be no need to separate each control by color, would there? 
Reply 0 0
pshipkov
Unfortunately i cannot tell much about the anim system i mentioned before also it would take quite a bit of typing to explain most of the concepts. What i see is that animators really dig it. So i must got something right there :)

First draw in 3D the BBox to make sure it is in place.

Reply 0 0
mtuttle
I drew the box and it is in place. I also drew the mouse position (derived from QT and then converted to world space coordinates from M3dView), and it turns out the y-position is flipped. Merely inverting the y value didn't work, so what can I do?
Reply 0 0
mtuttle
Well, I almost got it working by subtracting the height of the window by  the y-value of the mouse position, but it still isn't successful in all cases(objects)....
Reply 0 0
pshipkov
Ok, it sounds like you are almost there.
Draw one more thing simultaneously: the 3D bounding box and it's 2D projection.
I usually draw the heck out of everything (that's why i have the displayComponents node) otherwise is pretty hard to figure out what is going on by just looking at numbers printed in the console.
Can you show a screenshot ?

Reply 0 0
mtuttle
Here's a basic test with a poly sphere. The larger bounding box is the sphere's and the smaller one is the bounding box constructed by my plugin...I don't know how to do custom OGL drawings outside of Maya's "draw" methods so that it updates in real time, so I had it create joints for everything else (the 2d box & mouse trail).
bbScreenShotLQ.jpg
Reply 0 0
mtuttle
Hm, it appears that generating a bounding box for the locator solved the issue....
Reply 0 0
pshipkov
If you get your rigs going with that system post a video or something. I am interested in this kind of stuff.
Reply 0 0
mtuttle
http://www.youtube.com/watch?v=kBVfibv0AUM
Reply 0 0
pshipkov
Very nice, i am going to forward this to some guys here, they will be interested to see it.
Reply 0 0
Reply