|
我想让osgText::Text文本根据一个数组里的数据进行更新,可是文本不显示。估计是回调函数不起作用。请帮忙看看回调函数的写法及调用是否正确,谢谢。主要代码如下:
class Updatetext:public osg::NodeCallback
{
public:
Updatetext(int* _height,osgText::Text* _updateText):index(0) //_height为数组首地址,index为下标
{
height = _height;
updateText = _updateText;
}
virtual void operator()(osg::Node* node,osg::NodeVisitor* nv)
{
osg::MatrixTransform* geode = dynamic_cast<osg::MatrixTransform*>(node);
std::string gdlist = "";
std:stringstream os;
os<<height[index];
gdlist += os.str();
updateText->setText(gdlist);
index += 1;
traverse(node,nv);
}
protected:
int index;
int* height;
osgText::Text* updateText;
};
osg::Camera* createPointHUD(int* data)
{
......
osg::ref_ptr<osg::Group> model = new osg::Group;
std::string timesFont("fonts/arial.ttf");
osg::Vec3 position(450.0,740.0,0.0);
osg::Geode* geode = new osg::Geode;
osg::StateSet* stateset = geode->getOrCreateStateSet();
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
osgText::Text* updateText = new osgText::Text;
geode->addDrawable(updateText);
updateText->setCharacterSize(10.0f);
updateText->setFont(timesFont);
updateText->setColor(osg::Vec4(0.0f,255.0f,0.0f,1.0f));
updateText->setText("");
updateText->setPosition(position);
updateText->setDataVariance(osg::Object:YNAMIC);
osg::MatrixTransform* mat = new osg::MatrixTransform;
mat->addChild(geode);
mat->setDataVariance(osg::Object::DYNAMIC);
mat->setUpdateCallback(new Updatetext(data,updateText));
model->addChild(mat);
camera->addChild(model);
return camera;
} |
|