|
本帖最后由 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就不显示了 |
|