|
我首先定义一个回调函数
template<typename T>
class UpdateCallback: public osg::NodeCallback
{
public:
UpdateCallback(T* node):m_node(node)
{};
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
if (m_node)
{
m_node->update();
}
traverse(node,nv);
}
public:
T* m_node;
};
再在
class Flower:public osg::MatrixTransform
{
osg::Vec4Array* m_colors;
osg::Geode*createFlower(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height);
Flower(float xx,float yy)
{
m_colors = new osg::Vec4Array(4); this->setUpdateCallback( new UpdateCallback<Flower>(this));
}
void update();
}
void Flower::update()
{
osg::Vec4Array& colors=*m_colors;
if (n_aphor<1.0f)
{
n_aphor=n_aphor+0.01;
for (int i=0;i<colors.size();i++)
{
colors[i] = osg::Vec4(1, 1, 1,n_aphor);
}
}
}
再在创建图元里面吧颜色传出来
osg::Vec4Array* colors = new osg::Vec4Array(4);
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 0));
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 0));
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 0));
colors->push_back(osg::Vec4(0.0f, 0.0f, 0.0f, 0));
//aphor=m_aphor;
colors=m_colors;
怎么改变不了Alpha值
其他步骤没错 |
|