查看: 1117|回复: 2

关于ScalarBar的旋转问题,90°不显示,89°就正常

[复制链接]

该用户从未签到

发表于 2013-7-11 11:41:45 | 显示全部楼层 |阅读模式
本帖最后由 luckydog 于 2013-7-11 11:42 编辑

osg::Node* createScalarBar()
{osg::ref_ptr<osgSim::ColorRange> cr = new osgSim::ColorRange(0.0f,12.0f);
osgSim::ScalarBar * geode = new osgSim::ScalarBar;
std::vector<osg::Vec4> cs;
cs.push_back(osg::Vec4(0.0f,0.0f,1.0f,1.0f));   // B 蓝
cs.push_back(osg::Vec4(0.0f,1.0f,1.0f,1.0f));   // R
cs.push_back(osg::Vec4(0.0f,1.0f,0.0f,1.0f));   // G 绿
cs.push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));   // G 黄
cs.push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f));   // R 红

cr->setColors(cs);

osgSim::ScalarBar::TextProperties tp;
tp._fontFile = "fonts/times.ttf";
geode->setTextProperties(tp);
geode->setNumColors(30);
geode->setNumLabels(7);
geode->setScalarsToColors(cr);


geode->setTitle("wind(m/s)"); //scalarbar
geode->setWidth(1.0f);
geode->setAspectRatio(0.03f);
//geode->setOrientation(osgSim::ScalarBar::VERTICAL);

osg::StateSet * stateset = geode->getOrCreateStateSet();
stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);

//stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
stateset->setRenderBinDetails(6, "RenderBin");

osg::MatrixTransform * modelview = new osg::MatrixTransform;
modelview->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
osg::Matrixd matrix(osg::Matrixd::scale(500,500,500) * osg::Matrixd::translate(20,50,-10)); // I've played with these values a lot and it seems to work, but I have no idea why

modelview->setMatrix(matrix);
modelview->addChild(geode);

osg:: Projection * projection = new osg:: Projection;
projection->setMatrix( osg:: Matrixd:: ortho2D(0,600,0,600) * osg::Matrixd::rotate(osg:: DegreesToRadians(89.75),osg::Vec3(0.0,0.0,1.0))); // or whatever the OSG window res is
projection->addChild(modelview);

return projection;
}

int main( int argc, char **argv )
{
        osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;

        osg::ref_ptr<osg::Group> root = new osg::Group;

        root->addChild(createScalarBar());

        viewer->setSceneData(root.get());

        viewer->setUpViewInWindow(200,200,800,500);
        viewer->realize();
        viewer->run();
        return 0;
}

如上面红色部分,使用89.就正常,但是不是完全竖直,使用90.0就不显示了

该用户从未签到

发表于 2013-7-16 09:57:03 | 显示全部楼层
您给Projection节点设置这个SR矩阵的目的是?要知道透视投影并不能用空间变换来表达的,所以您这么做本身就欠考虑,如果需要有旋转的要求,请对projection的子节点做操作

该用户从未签到

发表于 2013-11-15 12:25:46 | 显示全部楼层
应该是osg:: Matrixd:: ortho2D(0,600,0,600)位置设置不对
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

联系我们

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