查看: 1936|回复: 5

osg autotransform设置setAutoScaleToScreen失效

[复制链接]

该用户从未签到

发表于 2011-10-25 11:19:13 | 显示全部楼层 |阅读模式
我想将OSG默认的3轴拖拽器修改为拖拽轴相对于屏幕缩放尺寸都不变,可是设置了setAutoScaleToScreen之后拖拽轴就会消失,不知道是哪里的原因,麻烦帮忙看下。
  1. osg::ref_ptr<osg::AutoTransform> at = new osg::AutoTransform;
  2. //at->setAutoScaleToScreen(true);//加上这句拖拽轴就会消失
  3. osg::Geode* lineGeode = new osg::Geode;
  4. {
  5. osg::Geometry* geometry = new osg::Geometry();

  6. osg::Vec3Array* vertices = new osg::Vec3Array(2);
  7. (*vertices)[0] = osg::Vec3(0.0f,0.0f,0.0f);
  8. (*vertices)[1] = osg::Vec3(0.0f,0.0f,1.0f);

  9. geometry->setVertexArray(vertices);
  10. geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,2));

  11. lineGeode->addDrawable(geometry);
  12. }
  13. // Turn of lighting for line and set line width.
  14. {
  15. osg::LineWidth* linewidth = new osg::LineWidth();
  16. linewidth->setWidth(3.0f);
  17. lineGeode->getOrCreateStateSet()->setAttributeAndModes(linewidth, osg::StateAttribute::ON);
  18. lineGeode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
  19. }

  20. at->addChild(lineGeode);
  21. _xDragger->addChild(at);
  22. _yDragger->addChild(at);
  23. _zDragger->addChild(at);

  24. osg::Geode* geode = new osg::Geode;

  25. // Create a cone.
  26. {
  27. osg::Cone* cone = new osg::Cone (osg::Vec3(0.0f, 0.0f, 1.0f), 0.025f, 0.10f);
  28. geode->addDrawable(new osg::ShapeDrawable(cone));
  29. }

  30. // Create an invisible cylinder for picking the line.
  31. {
  32. osg::Cylinder* cylinder = new osg::Cylinder (osg::Vec3(0.0f,0.0f,0.5f), 0.015f, 1.0f);
  33. osg::Drawable* geometry = new osg::ShapeDrawable(cylinder);
  34. setDrawableToAlwaysCull(*geometry);
  35. geode->addDrawable(geometry);
  36. }

  37. // 添加箭头拖拽按钮到线拖拽器
  38. osg::ref_ptr<osg::AutoTransform> at1 = new osg::AutoTransform;
  39. //at1->setAutoScaleToScreen(true);
  40. at1->addChild(geode);
  41. _xDragger->addChild(at1);
  42. _yDragger->addChild(at1);
  43. _zDragger->addChild(at1);

复制代码
之后的代码应该和这个没有关系了,这些是关键代码。

该用户从未签到

发表于 2011-10-26 09:43:15 | 显示全部楼层
osgmanipulator例子里面我提供了一种做法,不用修改Dragger的内部实现,您不妨参看一下

该用户从未签到

发表于 2011-10-26 11:09:59 | 显示全部楼层
例子里有么,我看戏啊~

该用户从未签到

 楼主| 发表于 2011-10-26 11:29:54 | 显示全部楼层
osgmanipulator的例子我看过了,只有TrackballDragger可以直接通过设置参数实现,而且我看了下TrackballDragger内部代码,实现方法也是通过setAutoScaleToScreen来实现的,您说的提供的方法是TrackballDragger中的方法吗?还是说我遗漏了什么关键代码?还请指教.

该用户从未签到

发表于 2011-10-26 16:25:12 | 显示全部楼层
我指得是DraggerContainer,如果您没有找到这个类,说明您的没有check out足够新的版本

该用户从未签到

 楼主| 发表于 2011-10-27 10:28:07 | 显示全部楼层
谢谢array,更新版本后找到了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表