[osg-users] Mouse position to object space
Florian GOLESTIN
florian.golestin at gmail.com
Thu Nov 23 05:20:58 PST 2017
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=72440#72440
More information about the osg-users
mailing list