Subclassing DzViewTool and opengl picking

Hello. After subclassing DzViewTool and creating a derived one, I need now to perform opengl picking, i.e. raycasting mouse coordinates and getting the 3D point in space that is hit (or not) when I click in the viewport. I can't find a way to actually get the 2D mouse position, and also the currently selected camera matrix. Any chance you can help? Thanks.

Post edited by Alessandro Mastronardi on

Comments

  • OmnifluxOmniflux Posts: 373
    edited August 2023

    Are you sure you don't want to be subclassing DzPickTool instead? Then you can use DzPickTool::mousePress(...) which gives you a QMouseEvent you can get the coordinates from by calling pos().

     

    If not, you could do something like

    QPoint qp = dzApp->getInterface()->getViewportMgr()->getActiveViewport()->get3DViewport()->mapFromGlobal(QCursor::pos());

    or, look at the documentation for Dz3DViewport::pickOnNode...

     

    I'm not sure about the camera matrix; would it be the same as the camera world space rotation?

    dzApp->getInterface()->getViewportMgr()->getActiveViewport()->get3DViewport()->getCamera()->getWSRot().getValue(...);

     

    Post edited by Omniflux on
  • @Omniflux thanks a lot, really appreciate your hints, I'll try those. I have to say however that this SDK would need a MAJOR overhaul, it's lacking everything from documentation to some good samples.

  • OmnifluxOmniflux Posts: 373

    Not sure what I was thinking when I suggested world space rotation, I meant world space transform. getWSTransform() instead of getWSRot().

  • Omniflux said:

    Not sure what I was thinking when I suggested world space rotation, I meant world space transform. getWSTransform() instead of getWSRot().

    No worries, thanks for the help!

Sign In or Register to comment.