[osg-users] Mouse position to object space

Hakan Gedek hgedek at gmail.com
Thu Nov 23 06:29:34 PST 2017


Hi Flogo,

Thanks so much !  It solved my problem !

Regards,


Flogo wrote:
> Hi Hakan,
> 
> If you want to simply drag (or do other transformation to) an object you can use the Dragger from the osgManipulator pluggin:
> 
> 
> Code:
> 
> osgManipulator::TranslateAxisDragger
> 
> 
> 
> 
> Otherwise you need to project the mouse to the world space.
> If I recall correctly:
> 
> 
> 
> Code:
> 
>     osgViewer::View *view = dynamic_cast<osgViewer::View *>(&actionAdapter);
>     const osg::Camera *camera = view->getCamera();
> 
>     const osg::Matrixd viewMatrix = camera->getViewMatrix();
>     const osg::Matrix projectionMatrix = camera->getProjectionMatrix();
>     osg::Matrix inverseCameraMatrix;
>     inverseCameraMatrix.invert(viewMatrix * projectionMatrix);
>     osg::Vec3 worldPosition = osg::Vec3(ea.getXnormalized(), ea.getYnormalized(), 0.0f) *
>                     inverseCameraMatrix;
> 
> 
> 
> 
> The z value of the Vec3 is the Near Plane, set it to 1.0 to have the Far Plane projection.
> 
> Best,
> Florian


------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72441#72441







More information about the osg-users mailing list