Selection of custom DzNode-derived objects
I've subclassed DzNode and have changed the viewport representation of this object from the standard Null representation by overriding the ::draw( const DzDrawStyle &style; ) method on DzNode (similar to the BlackHole API sample). Now I can't figure out how to change the mouseover/mouseclick behavior to highlight/select the node when I try to interact with the new representation.
With a standard DzNode viewport representation (the intersecting red/green/blue x/y/z line segments indicating the object's position), mousing over any of the line segments causes a bounding box to be drawn, and clicking on any of the line segments selects the node. I'm trying to reproduce this behavior, but on my own viewport representation.
I looked at DzSelectionMap but this appears to only work with geometry in DzShapes, and I need to interact with the OpenGL-drawn representation in the viewport.
Thanks
Ivan
Comments
interaction in the viewport requires your own custom viewtool. So something like
I think I have misunderstood your questions. Is your node not getting picked right when selected?
In that, case you need to handle the draw when drawing the pick image. Something like the following in your draw:
then draw your node's representation. Make sure you do not change the color after calling glColor3ubv when you are picking.
Thanks for the help, I'm a step further now. I've created my own DzViewTool, subclassing DzTranslateTool. I'm still stuck on the same issue though :
I've got a DzNode-derived object in the scene which doesn't have any geometry associated with it. I don't want to use the standard DzNode viewport representation of this object (e.g. the red/green/blue axis lines that show up for a Null object), so I've overridden it's draw method to draw something else in the viewport using OpenGL calls (similar to the Blackhole WSmodifier API example). I now want to have the node be selected when I click on this custom representation of the object in the viewport.
I'm assuming I need to do something in my DzViewTool here :
to detect clicks on this object type. The Dz3DViewport::pickOnNode method appears to do exactly what I need, but I'm not able to figure out how this method identifies what node was clicked on.
Thanks
as long as each node does code similiar to above, then the scene can draw the scene in pick mode and then look at the color under at the position passed in and the color in the pick image to determine which node is there.
Ok now it clicks, I didn't see that you were embedding the node index in the red/green color values. I now have this working as intended, thank you.
One last question -- the pick image color is now of course black. Is there any way to embed the node index in the color AND retain a usable range of visible colors for the pick image? My bitwise arithmetic is a bit rusty...
Thanks
Only draw that special color with the node encoding when the style is in draw is in picking mode. That was the purpose of the if
if( style.shadeStyle() == DzDrawStyle::Picking && style.pickMode() == DzDrawStyle::PickNodes && isSelectable())
.. special picking color
else
glColor3f(1, 0, 0) for red or what you would normally do.