1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
position = hitr->getWorldIntersectPoint();
osg::Vec3 norm = hitr->getWorldIntersectNormal();
osg::Vec3 normLocal = hitr->getLocalIntersectNormal();
osg::Geode * geode = new osg::Geode();
osg::Vec3 pointInsert = osg::Vec3(position.x(), position.y(),position.z());
osg::Sphere* unitSphere = new osg::Sphere( pointInsert, 500.0f);
osg::ShapeDrawable* unitCubeDrawable = new osg::ShapeDrawable(unitSphere);
unitCubeDrawable->setColor(osg::Vec4(1.0f,0.0f,0.0f,1.0f));
geode->addDrawable(unitCubeDrawable);
geode->setName( pElementToAdd->getName().toStdString());
osg::ref_ptr<osgManipulator::Selection> selection = new osgManipulator::Selection;
selection->addChild( geode );
float scale = geode->getBound().radius() * 2;
osg::ref_ptr<osgManipulator::TranslateAxisDragger> dragger = new osgManipulator::TranslateAxisDragger;
dragger->setupDefaultGeometry();
dragger->setMatrix( osg::Matrix::scale(scale, scale, scale) *
osg::Matrix::translate(geode->getBound().center()) );
osg::ref_ptr<osgManipulator::CommandManager> manager = new osgManipulator::CommandManager;
manager->connect( *dragger, *selection );
// Cacher le dragger
dragger->setNodeMask(0x0);
// Enregistrer le pointeur du draggers
pElementToAdd->setOsgDragger(dragger);
pElementToAdd->setNode(geode);
scene->asGroup()->getChild(0)->asGroup()->addChild(dragger.get());
scene->asGroup()->getChild(0)->asGroup()->addChild(selection); |
Partager