Selection of custom DzNode-derived objects

shoei321shoei321 Posts: 113

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

  • dtammdtamm Posts: 126
    edited December 1969

    interaction in the viewport requires your own custom viewtool. So something like

    
    class MyViewTool : public DzViewTool {
     Q_OBJECT
    public:
     MyViewTool ();
     ~MyViewTool ();
    
     virtual void activate();
     virtual void deactivate();
     virtual void draw( const DzDrawStyle &style;, Dz3DViewport *view ) const;
     virtual bool mousePress( Dz3DViewport *view, QMouseEvent *e, DzViewportMgr::ViewMouseModifier modifier );
     virtual void mouseMove( Dz3DViewport *view, QMouseEvent *e, DzViewportMgr::ViewMouseModifier modifier );
     virtual void mouseRelease( Dz3DViewport *view, QMouseEvent *e, DzViewportMgr::ViewMouseModifier modifier );
     virtual void mouseOver( Dz3DViewport *view, QMouseEvent *e, DzViewportMgr::ViewMouseModifier modifier );
     virtual void mouseLeave( Dz3DViewport *view, QEvent *e, DzViewportMgr::ViewMouseModifier modifier );
     virtual QWidget* getPane( QWidget *parent ) const;
    
    }
    
    class MyViewToolAction : public DzViewToolAction {
     Q_OBJECT
    public:
     MyViewToolAction () : DzViewToolAction("MyViewTool") {}
    
    };
    
    DZ_PLUGIN_CLASS_GUID for MyViewTool
    DZ_PLUGIN_CLASS_GUID for MyViewToolAction
    
  • dtammdtamm Posts: 126
    edited December 1969

    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:

    
    
     if( style.shadeStyle() == DzDrawStyle::Picking && style.pickMode() == DzDrawStyle::PickNodes && isSelectable()){
      int    index = dzScene->findNodeIndex( this ) + 1;
      unsigned char code[3] = { 0, 0, 0 };
    
      if( index > 0 ){
       code[0] = (unsigned char)( index & 0x000000ff );
       code[1] = (unsigned char)( ( index >> 8 ) & 0x0000007f );
       glColor3ubv( code );
      }
     }
    
    

    then draw your node's representation. Make sure you do not change the color after calling glColor3ubv when you are picking.

  • shoei321shoei321 Posts: 113
    edited December 1969

    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 :

    bool DzViewTool::mousePress(Dz3DViewport *view, QMouseEvent *e, DzViewportMgr::ViewMouseModifier modifier) {}

    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

  • dtammdtamm Posts: 126
    edited December 1969

    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.

  • shoei321shoei321 Posts: 113
    edited December 1969

    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

  • dtammdtamm Posts: 126
    edited December 2012

    shoei321 said:
    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.

    Post edited by dtamm on
Sign In or Register to comment.