Digital Art Zone

 
     
Selection of custom DzNode-derived objects
Posted: 25 November 2012 08:33 AM   [ Ignore ]
Member
Rank
Total Posts:  54
Joined  2010-09-22

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

Profile
 
 
Posted: 26 November 2012 10:04 AM   [ Ignore ]   [ # 1 ]
Member
Rank
Total Posts:  106
Joined  2010-12-31

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 mousePressDz3DViewport *viewQMouseEvent *eDzViewportMgr::ViewMouseModifier modifier );
 
virtual void mouseMoveDz3DViewport *viewQMouseEvent *eDzViewportMgr::ViewMouseModifier modifier );
 
virtual void mouseReleaseDz3DViewport *viewQMouseEvent *eDzViewportMgr::ViewMouseModifier modifier );
 
virtual void mouseOverDz3DViewport *viewQMouseEvent *eDzViewportMgr::ViewMouseModifier modifier );
 
virtual void mouseLeaveDz3DViewport *viewQEvent *eDzViewportMgr::ViewMouseModifier modifier );
 
virtual QWidgetgetPaneQWidget *parent ) const;

}

class MyViewToolAction : public DzViewToolAction {
 Q_OBJECT
public:
 
MyViewToolAction () : DzViewToolAction("MyViewTool"{}

}
;

DZ_PLUGIN_CLASS_GUID for MyViewTool
DZ_PLUGIN_CLASS_GUID 
for MyViewToolAction 
Profile
 
 
Posted: 26 November 2012 02:37 PM   [ Ignore ]   [ # 2 ]
Member
Rank
Total Posts:  106
Joined  2010-12-31

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->findNodeIndexthis ) + 1;
  
unsigned char code[3] { 000 };

  if( 
index ){
   code[0] 
= (unsigned char)( index 0x000000ff );
   
code[1] = (unsigned char)( ( index >> ) & 0x0000007f );
   
glColor3ubvcode );
  
}
 } 

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

 

Profile
 
 
Posted: 06 December 2012 03:37 PM   [ Ignore ]   [ # 3 ]
Member
Rank
Total Posts:  54
Joined  2010-09-22

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 *viewQMouseEvent *eDzViewportMgr::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

 

Profile
 
 
Posted: 06 December 2012 05:27 PM   [ Ignore ]   [ # 4 ]
Member
Rank
Total Posts:  106
Joined  2010-12-31

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.

Profile
 
 
Posted: 06 December 2012 06:18 PM   [ Ignore ]   [ # 5 ]
Member
Rank
Total Posts:  54
Joined  2010-09-22

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

Profile
 
 
Posted: 06 December 2012 06:24 PM   [ Ignore ]   [ # 6 ]
Member
Rank
Total Posts:  106
Joined  2010-12-31
shoei321 - 06 December 2012 06:18 PM

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.

Profile