|
我想将OSG默认的3轴拖拽器修改为拖拽轴相对于屏幕缩放尺寸都不变,可是设置了setAutoScaleToScreen之后拖拽轴就会消失,不知道是哪里的原因,麻烦帮忙看下。
- osg::ref_ptr<osg::AutoTransform> at = new osg::AutoTransform;
- //at->setAutoScaleToScreen(true);//加上这句拖拽轴就会消失
- osg::Geode* lineGeode = new osg::Geode;
- {
- osg::Geometry* geometry = new osg::Geometry();
- osg::Vec3Array* vertices = new osg::Vec3Array(2);
- (*vertices)[0] = osg::Vec3(0.0f,0.0f,0.0f);
- (*vertices)[1] = osg::Vec3(0.0f,0.0f,1.0f);
- geometry->setVertexArray(vertices);
- geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,2));
- lineGeode->addDrawable(geometry);
- }
- // Turn of lighting for line and set line width.
- {
- osg::LineWidth* linewidth = new osg::LineWidth();
- linewidth->setWidth(3.0f);
- lineGeode->getOrCreateStateSet()->setAttributeAndModes(linewidth, osg::StateAttribute::ON);
- lineGeode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
- }
- at->addChild(lineGeode);
- _xDragger->addChild(at);
- _yDragger->addChild(at);
- _zDragger->addChild(at);
- osg::Geode* geode = new osg::Geode;
- // Create a cone.
- {
- osg::Cone* cone = new osg::Cone (osg::Vec3(0.0f, 0.0f, 1.0f), 0.025f, 0.10f);
- geode->addDrawable(new osg::ShapeDrawable(cone));
- }
- // Create an invisible cylinder for picking the line.
- {
- osg::Cylinder* cylinder = new osg::Cylinder (osg::Vec3(0.0f,0.0f,0.5f), 0.015f, 1.0f);
- osg::Drawable* geometry = new osg::ShapeDrawable(cylinder);
- setDrawableToAlwaysCull(*geometry);
- geode->addDrawable(geometry);
- }
- // 添加箭头拖拽按钮到线拖拽器
- osg::ref_ptr<osg::AutoTransform> at1 = new osg::AutoTransform;
- //at1->setAutoScaleToScreen(true);
- at1->addChild(geode);
- _xDragger->addChild(at1);
- _yDragger->addChild(at1);
- _zDragger->addChild(at1);
复制代码 之后的代码应该和这个没有关系了,这些是关键代码。 |
|