osgManipulator.Translate2DDragger是OpenSceneGraph中的一个Manipulator(处理器)类,具有平移物体的功能。它用于移动二维平面中的对象。
#include <osgManipulator/Translate2DDragger>
#include <osgManipulator/Dragger>
#include <osg/MatrixTransform>
#include <osgViewer/Viewer>
int main()
{
osg::ref_ptr<osgManipulator::Translate2DDragger> dragger =
new osgManipulator::Translate2DDragger;
osg::ref_ptr<osg::MatrixTransform> transform =
new osg::MatrixTransform(osg::Matrix::translate(osg::Vec3(0, 0, 0)));
transform->addChild(dragger);
osg::ref_ptr<osgManipulator::Dragger> axisDragger = dragger->createDragger(0);
osg::ref_ptr<osg::MatrixTransform> axisTransform =
new osg::MatrixTransform(osg::Matrix::translate(osg::Vec3(1, 1, 0)));
axisTransform->addChild(axisDragger);
osg::ref_ptr<osg::Geode> modelGeode = new osg::Geode;
modelGeode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0),1)));
transform->addChild(modelGeode);
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild(transform);
root->addChild(axisTransform);
dragger->setHandleEvents(true);
dragger->setActivationKeyEvent('t');
osgViewer::Viewer viewer;
viewer.setSceneData(root);
viewer.run();
return 0;
}
[1] OpenSceneGraph Reference Documentation. https://www.openscenegraph.org/documentation/osg/index.html.
[2] OpenSceneGraph GitHub Repository. https://github.com/openscenegraph/OpenSceneGraph.
[3] osgManipulator.Translate2DDragger Class Reference. https://www.openscenegraph.org/documentation/osgManipulator/classosgManipulator_1_1Translate2DDragger.html.